Class: When::TM::Clock
- Inherits:
-
ReferenceSystem
- Object
- BasicTypes::Object
- Object
- ReferenceSystem
- When::TM::Clock
- Extended by:
- Parts::Resource::Pool
- Includes:
- Temporal, Coordinates
- Defined in:
- lib/when_exe/tmreference.rb
Overview
時計
see gml schema
Direct Known Subclasses
Constant Summary
Constants included from Coordinates
Coordinates::Bahai, Coordinates::CommonResidue, Coordinates::DefaultDateIndex, Coordinates::DefaultTimeIndex, Coordinates::IndianCities, Coordinates::Javanese, Coordinates::MATCH, Coordinates::Mayan, Coordinates::PERIOD, Coordinates::PERIOD_NAME, Coordinates::PRECISION, Coordinates::PRECISION_NAME, Coordinates::VALUE, Coordinates::Yi
Constants included from Parts::Resource
Parts::Resource::LabelProperty, Parts::Resource::Prefix, Parts::Resource::PrefixIndex, Parts::Resource::PrefixKeys, Parts::Resource::PrefixValues
Class Attribute Summary collapse
Instance Attribute Summary collapse
-
#date_basis ⇒ Array<When::TM::Calendar>
(also: #dateBasis)
readonly
一暦日の中の時間位置を定めるために、この時計とともに使用する暦 (relation - Resolution).
-
#reference_event ⇒ String
(also: #referenceEvent)
readonly
この時法の基点となる事象.
-
#reference_time ⇒ When::TM::ClockTime
(also: #referenceTime)
readonly
この時法による参照事象の時刻.
-
#second ⇒ Numeric
readonly
universal_timeとこの時法の最小単位との比 - additional attribute.
-
#time_standard ⇒ When::TimeStandard
readonly
時刻制 - additional attribute.
-
#tz_prop ⇒ When::V::TimezoneProperty
(also: #tzProp)
この時法を生成した時間帯プロパティ - additional attribute.
-
#utc_reference ⇒ When::TM::ClockTime
(also: #utcReference)
readonly
UTCによる参照事象の時刻.
-
#zone ⇒ String
(also: #to_extended)
readonly
この時法のUTCとの差(ISO 8601 extended format) - additional attribute.
Attributes inherited from ReferenceSystem
#domain, #domain_of_validity, #position
Attributes inherited from BasicTypes::Object
Attributes included from Parts::Resource
#_pool, #child, #keys, #locale, #namespace
Class Method Summary collapse
-
._setup_(local = nil) ⇒ void
When::TM::Clock Class のグローバルな設定を行う.
- .get_clock(options) ⇒ Object
- .get_clock_option(options) ⇒ Object
- .to_hms(hms, extended = true) ⇒ Object
Instance Method Summary collapse
-
#^(date, options = {}) ⇒ When::TM::DateAndTime, When::TM::JulianDate
When::TM::TemporalPosition の時間帯を変更して複製する.
-
#_arrange_length(period) ⇒ Object
期間オブジェクトの桁数合わせ.
-
#_coordinates_to_number(clk_time) ⇒ Numeric
時刻をNumeric(serial time)に変換する.
-
#_daylight(zdate = nil, &block) ⇒ Object
夏時間.
-
#_need_validate ⇒ Object
夏時間の有無.
-
#_number_to_coordinates(serial_time) ⇒ Numeric
Numeric(serial time)を時刻に変換する.
-
#_precision(time, default = nil) ⇒ Object
時刻配列の分解能.
-
#_to_hash_value(options = {}) ⇒ Object
_m17n_form のための要素生成.
-
#_tz_difference ⇒ Object
この時法の夏時間-標準時間変化量.
-
#clk_trans(clk_time) ⇒ When::TM::ClockTime
(also: #clkTrans)
UTC時刻をこの時法の時刻に変換する.
-
#rate_of_clock ⇒ Numeric
時間の歩度.
-
#to_basic ⇒ String
この時法のUTCとの差(ISO 8601 basic format).
-
#to_clk_time(fod, options = {}) ⇒ When::TM::ClockTime
日の小数をこの時法の時刻に変換する.
-
#to_universal_time(clk_time) ⇒ Numeric
この時法の時刻を日の小数に変換する.
-
#tzname(format = :extended) ⇒ Array<String>
この時法の時間帯名.
-
#universal_time ⇒ Numeric
日の小数による参照事象の時刻.
-
#utc_trans(u_time) ⇒ When::TM::ClockTime
(also: #utcTrans)
この時法の時刻をUTC時刻に変換する.
Methods included from Parts::Resource::Pool
[], []=, _pool, _setup_, pool_keys
Methods included from Parts::Resource::Synchronize
Methods included from Coordinates
Methods inherited from ReferenceSystem
Methods inherited from BasicTypes::Object
Methods included from Parts::Resource
#[], _extract_prefix, _instance, _parse, _path_with_prefix, #each, #enum_for, #hierarchy, #include?, #included?, #iri, #leaf?, #m17n, #map, #next, #parent, #prev, #registered?
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class When::Parts::Resource
Class Attribute Details
.local_time ⇒ When::TM::Clock, ...
本変数の write access はテスト用である。 本変数は、原則、ライブラリ立ち上げ時に setup で初期化する。 以降、本変数に代入を行っても、すでに生成した When::TM::TemporalPosition には反映されない。
マルチスレッド動作時 CalendarEra の生成で Calendar の本属性が更新される 参照・更新処理は Clock.synchronize { … } の … の部分に書く必要がある
地方時
287 288 289 |
# File 'lib/when_exe/tmreference.rb', line 287 def local_time @local_time end |
Instance Attribute Details
#date_basis ⇒ Array<When::TM::Calendar> (readonly) Also known as: dateBasis
一暦日の中の時間位置を定めるために、この時計とともに使用する暦 (relation - Resolution)
The calendar that is used with this clock to define temporal position within a calendar day
391 392 393 |
# File 'lib/when_exe/tmreference.rb', line 391 def date_basis @date_basis end |
#reference_event ⇒ String (readonly) Also known as: referenceEvent
new の options 引数に :reference_event があれば設定される。 ライブラリとしては本変数を参照していない。下記の振る舞いを String で説明するため用いてもよい。
日付の境界が午前0時でない場合、When::Coordinates::Temporal.border により、境界が指定される。 border, behavior メソッドをオーバーライドすることで、日の出、日の入りなど event 時刻が一定 しない場合にも対応する。
この時法の基点となる事象
Event used as the datum for this clock
363 364 365 |
# File 'lib/when_exe/tmreference.rb', line 363 def reference_event @reference_event end |
#reference_time ⇒ When::TM::ClockTime (readonly) Also known as: referenceTime
この時法による参照事象の時刻
Time of the reference event for this clock
372 373 374 |
# File 'lib/when_exe/tmreference.rb', line 372 def reference_time @reference_time end |
#second ⇒ Numeric (readonly)
universal_timeとこの時法の最小単位との比 - additional attribute
415 416 417 |
# File 'lib/when_exe/tmreference.rb', line 415 def second @second end |
#time_standard ⇒ When::TimeStandard (readonly)
時刻制 - additional attribute
398 399 400 |
# File 'lib/when_exe/tmreference.rb', line 398 def time_standard @time_standard end |
#tz_prop ⇒ When::V::TimezoneProperty Also known as: tzProp
When::TM::TemporalPosition に対して加減算を行うと、時間帯が変わる可能性がある。 本変数により、時間帯決定ルール(When::V::TimezoneProperty#rrule)を参照する。
この時法を生成した時間帯プロパティ - additional attribute
408 409 410 |
# File 'lib/when_exe/tmreference.rb', line 408 def tz_prop @tz_prop end |
#utc_reference ⇒ When::TM::ClockTime (readonly) Also known as: utcReference
UTCによる参照事象の時刻
UTC time of the reference event
381 382 383 |
# File 'lib/when_exe/tmreference.rb', line 381 def utc_reference @utc_reference end |
#zone ⇒ String (readonly) Also known as: to_extended
この時法のUTCとの差(ISO 8601 extended format) - additional attribute
421 422 423 |
# File 'lib/when_exe/tmreference.rb', line 421 def zone @zone end |
Class Method Details
._setup_(local = nil) ⇒ void
This method returns an undefined value.
When::TM::Clock Class のグローバルな設定を行う
295 296 297 298 299 300 301 |
# File 'lib/when_exe/tmreference.rb', line 295 def _setup_(local=nil) @_lock_ = Mutex.new if When.multi_thread @_lock_.lock if @_lock_ @_pool = {} @local_time = local @_lock_.unlock if @_lock_ end |
.get_clock(options) ⇒ Object
304 305 306 |
# File 'lib/when_exe/tmreference.rb', line 304 def get_clock() get_clock_option() || @local_time || When.utc end |
.get_clock_option(options) ⇒ Object
309 310 311 312 313 |
# File 'lib/when_exe/tmreference.rb', line 309 def get_clock_option() clock = .delete(:clock) tz = .delete(:tz) tz ? (When::V::Timezone[tz] || When::Parts::Timezone[tz]) : clock end |
.to_hms(hms, extended = true) ⇒ Object
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 |
# File 'lib/when_exe/tmreference.rb', line 316 def to_hms(hms, extended=true) case hms when Numeric sgn = (hms >= 0) ? '+' : '-' hh, mm = hms.abs.divmod(3600) mm, ss = mm.divmod(60) ss, ff = ss.divmod(1) ff = (ff == 0 || When::STRING <= When::SECOND) ? '' : ("%.#{When::STRING - When::SECOND}f" % ff)[1..-1] ss = (ss == 0 && ff == '') ? '' : ("%02d" % ss) mm = "%02d" % mm hh = "%02d" % hh when /^([-+])(\d{2})([:=*])?(\d{2})?([:=*])?(\d{2})?(\.\d+)?$/ sgn, hh, d1, mm, d2, ss, ff = $~[1..7] ff ||= '' ss ||= '' mm ||= '' else return nil end if (extended) d1 ||= (mm=='') ? '' : ':' d2 ||= (ss=='') ? '' : ':' else d1 = '' d2 = '' end sgn + hh + d1 + mm + d2 + ss + ff end |
Instance Method Details
#^(date, options = {}) ⇒ When::TM::DateAndTime, When::TM::JulianDate
When::TM::TemporalPosition の時間帯を変更して複製する
530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 |
# File 'lib/when_exe/tmreference.rb', line 530 def ^(date, ={}) date = Position.any_other(date, ) = (date.||{}).merge() frac = self.universal_time sdn, time = (date.universal_time - frac).divmod(Duration::DAY) [:frame] ||= date.frame if date.kind_of?(CalDate) [:clock] = self case date when DateAndTime return DateAndTime.new([:frame].to_cal_date(sdn + JulianDate::JD19700101), time+frac, ) when CalDate return CalDate.new([:frame].to_cal_date(date.to_i), ) when JulianDate [:frame] = .delete(:clock) return JulianDate.universal_time(sdn * Duration::DAY, ) else raise TypeError, "Irregal (Temporal)Position" end end |
#_arrange_length(period) ⇒ Object
期間オブジェクトの桁数合わせ
627 628 629 630 631 632 |
# File 'lib/when_exe/tmreference.rb', line 627 def _arrange_length(period) return period unless period.kind_of?(Array) diff = @indices.length - period.length + 1 return period if (diff == 0) return (diff > 0) ? period + Array.new(diff, 0) : period[0...diff] end |
#_coordinates_to_number(clk_time) ⇒ Numeric
時刻をNumeric(serial time)に変換する
497 498 499 500 501 502 503 504 505 |
# File 'lib/when_exe/tmreference.rb', line 497 def _coordinates_to_number(clk_time) u = 1 s = 0 (@base.length-1).downto(1) do |i| s += u * (+clk_time[i] - @base[i]) if (clk_time[i]) u *= @unit[i] end return s + u * (+clk_time[0]) + @origin_of_LSC end |
#_daylight(zdate = nil, &block) ⇒ Object
夏時間
605 606 607 608 609 610 611 612 613 |
# File 'lib/when_exe/tmreference.rb', line 605 def _daylight(zdate=nil, &block) case @tz_prop when nil ; return self when When::V::TimezoneProperty ; timezone = @tz_prop._pool['..'] else ; timezone = @tz_prop end return self unless timezone return timezone._daylight(zdate, &block) end |
#_need_validate ⇒ Object
夏時間の有無
595 596 597 598 599 600 601 |
# File 'lib/when_exe/tmreference.rb', line 595 def _need_validate case @tz_prop when nil ; false when When::V::TimezoneProperty ; @tz_prop._pool['..']._need_validate else ; @tz_prop._need_validate end end |
#_number_to_coordinates(serial_time) ⇒ Numeric
Numeric(serial time)を時刻に変換する
513 514 515 516 517 518 519 520 521 |
# File 'lib/when_exe/tmreference.rb', line 513 def _number_to_coordinates(serial_time) time = [serial_time-@origin_of_LSC] (@base.length-1).downto(1) do |i| carry, time[0] = (+time[0]).divmod(@unit[i]) time[0] += @base[i] time.unshift(carry) end return time end |
#_precision(time, default = nil) ⇒ Object
時刻配列の分解能
636 637 638 639 640 |
# File 'lib/when_exe/tmreference.rb', line 636 def _precision(time, default=nil) nil_index = time.index(nil) || time.length precision = nil_index - 1 if (nil_index < @base.length || time[-1].kind_of?(Integer)) When::Coordinates::Index.precision(default || precision) end |
#_to_hash_value(options = {}) ⇒ Object
_m17n_form のための要素生成
580 581 582 |
# File 'lib/when_exe/tmreference.rb', line 580 def _to_hash_value(={}) tzname(:hash)[0] end |
#_tz_difference ⇒ Object
この時法の夏時間-標準時間変化量
617 618 619 620 621 622 623 |
# File 'lib/when_exe/tmreference.rb', line 617 def _tz_difference case @tz_prop when nil ; 0 when When::V::TimezoneProperty ; @tz_prop._pool['..'].difference else ; @tz_prop.difference end end |
#clk_trans(clk_time) ⇒ When::TM::ClockTime Also known as: clkTrans
UTC時刻をこの時法の時刻に変換する
461 462 463 |
# File 'lib/when_exe/tmreference.rb', line 461 def clk_trans(clk_time) return self.to_clk_time(When.utc.to_universal_time(u_time.clk_time)) end |
#rate_of_clock ⇒ Numeric
時間の歩度
428 429 430 |
# File 'lib/when_exe/tmreference.rb', line 428 def rate_of_clock @time_standard.rate_of_clock end |
#to_basic ⇒ String
この時法のUTCとの差(ISO 8601 basic format)
588 589 590 591 |
# File 'lib/when_exe/tmreference.rb', line 588 def to_basic return '' unless @zone @zone.gsub(/:/, '') end |
#to_clk_time(fod, options = {}) ⇒ When::TM::ClockTime
日の小数をこの時法の時刻に変換する
482 483 484 485 486 487 488 489 |
# File 'lib/when_exe/tmreference.rb', line 482 def to_clk_time(fod, ={}) [:frame] = self fod, second = fod.trunk, fod.branch / fod.second if fod.kind_of?(When::Coordinates::LeapSeconds) clk_time = ClockTime.new(_encode(_number_to_coordinates(fod * @second)), ) return clk_time if (second||0) == 0 clk_time.clk_time[-1] += second return clk_time end |
#to_universal_time(clk_time) ⇒ Numeric
この時法の時刻を日の小数に変換する
472 473 474 |
# File 'lib/when_exe/tmreference.rb', line 472 def to_universal_time(clk_time) return _coordinates_to_number(_decode(clk_time)) / @second end |
#tzname(format = :extended) ⇒ Array<String>
:extended または :basicが指定され、上記は時間帯名が定義されていない場合は、ISO 8601形式で返す
この時法の時間帯名
562 563 564 565 566 567 568 569 570 571 572 573 574 |
# File 'lib/when_exe/tmreference.rb', line 562 def tzname(format=:extended) name = @tz_prop.tzname if @tz_prop.kind_of?(When::V::TimezoneProperty) && format != :hash name ||= format == :basic ? to_basic : @zone name = Array(name) return name unless format == :hash tzid = case @tz_prop when When::V::TimezoneProperty ; @tz_prop['..'].property['tzid'].object when When::Parts::Timezone ; @tz_prop.timezone.name else ; '' end name[0] = tzid + name[0] name end |
#universal_time ⇒ Numeric
日の小数による参照事象の時刻
Fraction time of the reference event
440 441 442 |
# File 'lib/when_exe/tmreference.rb', line 440 def universal_time return @utc_reference.universal_time end |
#utc_trans(u_time) ⇒ When::TM::ClockTime Also known as: utcTrans
この時法の時刻をUTC時刻に変換する
450 451 452 |
# File 'lib/when_exe/tmreference.rb', line 450 def utc_trans(u_time) return When.utc.to_clk_time(self.to_universal_time(u_time.clk_time)) end |