Class: When::TM::Clock

Inherits:
ReferenceSystem show all
Extended by:
Parts::Resource::Pool
Includes:
Spatial::Normalize, Temporal, Coordinates
Defined in:
lib/when_exe/tmreference.rb

Overview

時計

see gml schema

Direct Known Subclasses

CalendarTypes::UTC

Constant Summary

Constants included from Coordinates

Coordinates::Bahai, Coordinates::CommonResidue, Coordinates::DefaultDateIndices, Coordinates::DefaultDayIndex, Coordinates::DefaultTimeIndices, Coordinates::IndianCities, Coordinates::Javanese, Coordinates::MATCH, Coordinates::Mayan, Coordinates::PERIOD, Coordinates::PERIOD_NAME, Coordinates::PRECISION, Coordinates::PRECISION_NAME, Coordinates::Tibetan, Coordinates::VALUE, Coordinates::Yi

Constants included from Parts::Resource

Parts::Resource::LabelProperty

Instance Attribute Summary collapse

Attributes inherited from ReferenceSystem

#domain_of_validity, #position

Attributes inherited from BasicTypes::Object

#label

Attributes included from Parts::Resource

#_pool, #child, #keys, #locale, #namespace

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Parts::Resource::Pool

[], []=, _pool, _setup_, pool_keys

Methods included from Parts::Resource::Synchronize

#synchronize

Methods included from Coordinates

to_deg, to_dms

Methods inherited from ReferenceSystem

#domain, #name

Methods included from Parts::Resource

#[], _decode, _encode, _extract_prefix, _instance, _parse, _path_with_prefix, _replace_tags, #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

Instance Attribute Details

#date_basisArray<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



462
463
464
# File 'lib/when_exe/tmreference.rb', line 462

def date_basis
  @date_basis
end

#reference_eventString (readonly) Also known as: referenceEvent

Note:

new の options 引数に :reference_event があれば設定される。 ライブラリとしては本変数を参照していない。下記の振る舞いを String で説明するため用いてもよい。

Note:

日付の境界が午前0時でない場合、When::Coordinates::Temporal.border により、境界が指定される。 border, behavior メソッドをオーバーライドすることで、日の出、日の入りなど event 時刻が一定 しない場合にも対応する。

この時法の基点となる事象

Event used as the datum for this clock

Returns:



434
435
436
# File 'lib/when_exe/tmreference.rb', line 434

def reference_event
  @reference_event
end

#reference_timeWhen::TM::ClockTime (readonly) Also known as: referenceTime

この時法による参照事象の時刻

Time of the reference event for this clock

Returns:



443
444
445
# File 'lib/when_exe/tmreference.rb', line 443

def reference_time
  @reference_time
end

#secondNumeric (readonly)

universal_timeとこの時法の最小単位との比 - additional attribute

Returns:



486
487
488
# File 'lib/when_exe/tmreference.rb', line 486

def second
  @second
end

#time_standardWhen::TimeStandard (readonly)

時刻制 - additional attribute

Returns:



469
470
471
# File 'lib/when_exe/tmreference.rb', line 469

def time_standard
  @time_standard
end

#tz_propWhen::V::TimezoneProperty Also known as: tzProp

Note:

When::TM::TemporalPosition に対して加減算を行うと、時間帯が変わる可能性がある。 本変数により、時間帯決定ルール(When::V::TimezoneProperty#rrule)を参照する。

この時法を生成した時間帯プロパティ - additional attribute



479
480
481
# File 'lib/when_exe/tmreference.rb', line 479

def tz_prop
  @tz_prop
end

#utc_referenceWhen::TM::ClockTime (readonly) Also known as: utcReference

UTCによる参照事象の時刻

UTC time of the reference event

Returns:



452
453
454
# File 'lib/when_exe/tmreference.rb', line 452

def utc_reference
  @utc_reference
end

#zoneString (readonly) Also known as: to_extended

この時法のUTCとの差(ISO 8601 extended format) - additional attribute

Returns:



492
493
494
# File 'lib/when_exe/tmreference.rb', line 492

def zone
  @zone
end

Class Method Details

._local_timeObject

共通処理



362
363
364
365
366
367
368
369
370
371
# File 'lib/when_exe/tmreference.rb', line 362

def _local_time
  case @local_time
  when Array  ; @local_time
  when nil    ; @local_time = [false, When.utc]
  when String ; @local_time = [true,  When::Parts::Timezone[@local_time] ||
                                      When::V::Timezone[@local_time]     ||
                                      When.Clock(@local_time)]
  else        ; @local_time = [true,  @local_time]
  end
end

._setup_(local = nil) ⇒ void

Note:

本メソッドでマルチスレッド対応の管理変数の初期化を行っている。 このため、本メソッド自体はスレッドセーフでない。

This method returns an undefined value.

When::TM::Clock Class のグローバルな設定を行う

Parameters:



321
322
323
324
325
# File 'lib/when_exe/tmreference.rb', line 321

def _setup_(local=nil)
  @_lock_ = Mutex.new if When.multi_thread
  @_pool  = {}
  @local_time = local
end

.get_clock(options) ⇒ Object



375
376
377
# File 'lib/when_exe/tmreference.rb', line 375

def get_clock(options)
  get_clock_option(options) || local_time
end

.get_clock_option(options) ⇒ Object



380
381
382
383
384
# File 'lib/when_exe/tmreference.rb', line 380

def get_clock_option(options)
  clock = options.delete(:clock)
  tz    = options.delete(:tz)
  tz ? (When::V::Timezone[tz] || When::Parts::Timezone[tz]) : clock
end

.is_local_time_set?true, false

When::TM::Clock のローカルタイムが設定されているか?

Returns:

  • (true, false)


357
358
359
# File 'lib/when_exe/tmreference.rb', line 357

def is_local_time_set?
  _local_time[0]
end

.local_timeWhen::TM::Clock, ...

When::TM::Clock のローカルタイムを読みだす



349
350
351
# File 'lib/when_exe/tmreference.rb', line 349

def local_time
  _local_time[1]
end

.local_time=(local) ⇒ When::TM::Clock, ...

Note:

@local_timeは、原則、ライブラリ立ち上げ時に setup で初期化する。 以降、@local_timeに代入を行っても、すでに生成した When::TM::TemporalPosition 等には反映されない。

地方時



337
338
339
340
341
342
343
# File 'lib/when_exe/tmreference.rb', line 337

def local_time=(local)
  if @_pool
    @local_time = local
  else
    _setup_(local)
  end
end

.to_hms(hms, extended = true) ⇒ Object



387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
# File 'lib/when_exe/tmreference.rb', line 387

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 の時間帯を変更して複製する



603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
# File 'lib/when_exe/tmreference.rb', line 603

def ^(date, options={})
  date = Position.any_other(date, options)
  my_options = (date.options||{}).merge(options)
  frac       = self.universal_time(date.to_i)
  sdn, time  = (date.universal_time - frac).divmod(Duration::DAY)
  my_options[:frame] ||= date.frame if date.kind_of?(CalDate)
  my_options[:clock]   = self
  case date
  when DateAndTime
    time += frac unless self.kind_of?(When::CalendarTypes::LocalTime)
    DateAndTime.new(my_options[:frame].to_cal_date(sdn + JulianDate::JD19700101), time, my_options)
  when CalDate
    CalDate.new(my_options[:frame].to_cal_date(date.to_i), my_options)
  when JulianDate
    my_options[:frame] = my_options.delete(:clock)
    JulianDate.universal_time(sdn * Duration::DAY, my_options)
  else
    raise TypeError, "Irregal (Temporal)Position"
  end
end

#_arrange_length(period) ⇒ Object

期間オブジェクトの桁数合わせ



701
702
703
704
705
706
# File 'lib/when_exe/tmreference.rb', line 701

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)に変換する

Parameters:

Returns:



570
571
572
573
574
575
576
577
578
# File 'lib/when_exe/tmreference.rb', line 570

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(time) ⇒ Object

夏時間



679
680
681
682
683
684
685
686
687
# File 'lib/when_exe/tmreference.rb', line 679

def _daylight(time)
  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(time)
end

#_need_validateObject

夏時間の有無



669
670
671
672
673
674
675
# File 'lib/when_exe/tmreference.rb', line 669

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)を時刻に変換する

Parameters:

Returns:



586
587
588
589
590
591
592
593
594
# File 'lib/when_exe/tmreference.rb', line 586

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

時刻配列の分解能



710
711
712
713
714
# File 'lib/when_exe/tmreference.rb', line 710

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

#_round_value(precision) ⇒ Object

丸め量 / When::TM::Duration::SYSTEM



718
719
720
721
722
723
724
# File 'lib/when_exe/tmreference.rb', line 718

def _round_value(precision)
  offset = When::TM::Duration::DAY / 2
  precision.times do |i|
    offset /= @unit[i+1] ? @unit[i+1] : 10
  end
  offset
end

#_to_hash_value(options = {}) ⇒ Object

_m17n_form のための要素生成



654
655
656
# File 'lib/when_exe/tmreference.rb', line 654

def _to_hash_value(options={})
  tzname(:hash)[0]
end

#_tz_differenceObject

この時法の夏時間-標準時間変化量



691
692
693
694
695
696
697
# File 'lib/when_exe/tmreference.rb', line 691

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時刻をこの時法の時刻に変換する

Parameters:

Returns:



534
535
536
# File 'lib/when_exe/tmreference.rb', line 534

def clk_trans(clk_time)
  return self.to_clk_time(When.utc.to_universal_time(u_time.clk_time))
end

#rate_of_clockNumeric

時間の歩度

Returns:



499
500
501
# File 'lib/when_exe/tmreference.rb', line 499

def rate_of_clock
  @time_standard.rate_of_clock
end

#to_basicString

この時法のUTCとの差(ISO 8601 basic format)

Returns:



662
663
664
665
# File 'lib/when_exe/tmreference.rb', line 662

def to_basic
  return '' unless @zone
  @zone.gsub(/:/, '')
end

#to_clk_time(fod, options = {}) ⇒ When::TM::ClockTime

128秒単位の実数をこの時法の時刻に変換する

Parameters:

Returns:



555
556
557
558
559
560
561
562
# File 'lib/when_exe/tmreference.rb', line 555

def to_clk_time(fod, options={})
  options[: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)), options)
  return clk_time if (second||0) == 0
  clk_time.clk_time[-1] += second
  return clk_time
end

#to_universal_time(clk_time) ⇒ Numeric

この時法の時刻を128秒単位の実数に変換する

Parameters:

Returns:



545
546
547
# File 'lib/when_exe/tmreference.rb', line 545

def to_universal_time(clk_time)
  return _coordinates_to_number(_decode(clk_time)) / @second
end

#tzname(format = :extended) ⇒ Array<String>

Note:

:extended または :basicが指定され、上記は時間帯名が定義されていない場合は、ISO 8601形式で返す

この時法の時間帯名

Parameters:

  • format (Symbol) (defaults to: :extended)
    • :extended ISO 8601 extended format (default)

    • :basic ISO 8601 basic format

    • :hash 時間帯名の後ろにISO 8601 extended format を付加する

Returns:



636
637
638
639
640
641
642
643
644
645
646
647
648
# File 'lib/when_exe/tmreference.rb', line 636

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(sdn = nil) ⇒ Numeric

128秒単位の実数による参照事象の時刻

Fraction time of the reference event

Parameters:

  • sdn (Integer) (defaults to: nil)

    参照事象の通し番号(ダミー)

Returns:

  • (Numeric)

    T00:00:00Z からの参照事象の経過時間 / 128秒



513
514
515
# File 'lib/when_exe/tmreference.rb', line 513

def universal_time(sdn=nil)
  return @utc_reference.universal_time
end

#utc_trans(u_time) ⇒ When::TM::ClockTime Also known as: utcTrans

この時法の時刻をUTC時刻に変換する

Parameters:

Returns:



523
524
525
# File 'lib/when_exe/tmreference.rb', line 523

def utc_trans(u_time)
  return When.utc.to_clk_time(self.to_universal_time(u_time.clk_time))
end