Class: When::TM::Clock

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

Overview

When::TM::Clock への追加

Direct Known Subclasses

CalendarTypes::UTC

Constant Summary

Constants included from Coordinates

Coordinates::Bahai, Coordinates::Chinese, Coordinates::Common, Coordinates::DefaultDateIndices, Coordinates::DefaultDayIndex, Coordinates::DefaultTimeIndices, Coordinates::Indian, Coordinates::Iranian, Coordinates::Javanese, Coordinates::LocationTable, Coordinates::MATCH, Coordinates::Mayan, Coordinates::PERIOD, Coordinates::PERIOD_NAME, Coordinates::PRECISION, Coordinates::PRECISION_NAME, Coordinates::Russian, Coordinates::Tibetan, Coordinates::VALUE, Coordinates::Yi

Constants included from Namespace

Namespace::DC, Namespace::DCQ, Namespace::DCT, Namespace::FOAF, Namespace::OWL, Namespace::RDF, Namespace::RDFC, Namespace::RDFS, Namespace::RSS, Namespace::XSD

Instance Attribute Summary collapse

Attributes inherited from ReferenceSystem

#domain_of_validity, #position

Attributes inherited from BasicTypes::Object

#label

Attributes included from Parts::Resource

#child, #keys, #locale, #namespace

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Parts::Resource::Pool

[], []=, _setup_

Methods included from Parts::Timezone::Base

#^

Methods included from Coordinates

to_deg, to_deg_225, to_dms

Methods inherited from ReferenceSystem

#domain, #name

Methods included from Parts::Resource

#[], #^, _instance, base_uri, #each, #enum_for, #hierarchy, #include?, #included?, #iri, #leaf?, #m17n, #map, #parent, #registered?, root_dir

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



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

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:



472
473
474
# File 'lib/when_exe/tmreference.rb', line 472

def reference_event
  @reference_event
end

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

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

Time of the reference event for this clock

Returns:



481
482
483
# File 'lib/when_exe/tmreference.rb', line 481

def reference_time
  @reference_time
end

#secondNumeric (readonly)

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

Returns:



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

def second
  @second
end

#time_standardWhen::TimeStandard (readonly)

時刻制 - additional attribute

Returns:



507
508
509
# File 'lib/when_exe/tmreference.rb', line 507

def time_standard
  @time_standard
end

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

Note:

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

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



517
518
519
# File 'lib/when_exe/tmreference.rb', line 517

def tz_prop
  @tz_prop
end

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

UTCによる参照事象の時刻

UTC time of the reference event

Returns:



490
491
492
# File 'lib/when_exe/tmreference.rb', line 490

def utc_reference
  @utc_reference
end

#zoneString (readonly) Also known as: to_extended

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

Returns:



530
531
532
# File 'lib/when_exe/tmreference.rb', line 530

def zone
  @zone
end

Class Method Details

._local_timeObject

共通処理



397
398
399
400
401
402
403
404
405
406
# File 'lib/when_exe/tmreference.rb', line 397

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:



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

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

._setup_infoHash

設定情報を取得する

Returns:

  • (Hash)

    設定情報



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

def _setup_info
  {:local => _local_time}
end

.is_local_time_set?true, false

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

Returns:

  • (true, false)


392
393
394
# File 'lib/when_exe/tmreference.rb', line 392

def is_local_time_set?
  _local_time[0]
end

.local_timeWhen::Parts::Timezone::Base

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



384
385
386
# File 'lib/when_exe/tmreference.rb', line 384

def local_time
  _local_time[1]
end

.local_time=(local) ⇒ When::Parts::Timezone::Base, String

Note:

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

地方時

Parameters:

Returns:



372
373
374
375
376
377
378
# File 'lib/when_exe/tmreference.rb', line 372

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

Instance Method Details

#_coordinates_to_number(clk_time) ⇒ Numeric

時刻をNumeric(serial time)に変換する

Parameters:

Returns:



610
611
612
613
614
615
616
617
618
# File 'lib/when_exe/tmreference.rb', line 610

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

#_number_to_coordinates(serial_time) ⇒ Numeric

Numeric(serial time)を時刻に変換する

Parameters:

Returns:



626
627
628
629
630
631
632
633
634
# File 'lib/when_exe/tmreference.rb', line 626

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

#clk_trans(clk_time) ⇒ When::TM::ClockTime Also known as: clkTrans

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

Parameters:

Returns:



572
573
574
# File 'lib/when_exe/tmreference.rb', line 572

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

#daylightWhen::TM::Clock

夏時間帯の時計

Returns:



724
725
726
# File 'lib/when_exe/tmreference.rb', line 724

def daylight
  _tz_prop ? _tz_prop.daylight : self
end

#locationWhen::Coordinates::Spatial

時間帯を代表する空間位置



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

def location
  @location ||= @tz_prop.kind_of?(When::Parts::Timezone) ? @tz_prop.location :
                                  When::Coordinates::Spatial.default_location
end

#rate_of_clockNumeric

時間の歩度

Returns:



537
538
539
# File 'lib/when_exe/tmreference.rb', line 537

def rate_of_clock
  @time_standard.rate_of_clock
end

#standardWhen::TM::Clock

標準時間帯の時計

Returns:



718
719
720
# File 'lib/when_exe/tmreference.rb', line 718

def standard
  _tz_prop ? _tz_prop.standard : self
end

#to_basicString

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

Returns:



651
652
653
654
# File 'lib/when_exe/tmreference.rb', line 651

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

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

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

Parameters:

Returns:



595
596
597
598
599
600
601
602
# File 'lib/when_exe/tmreference.rb', line 595

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, sdn = nil) ⇒ Numeric Also known as: to_local_time

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

Parameters:

  • clk_time (Array<Numeric>)
  • sdn (Integer) (defaults to: nil)

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

Returns:



584
585
586
# File 'lib/when_exe/tmreference.rb', line 584

def to_universal_time(clk_time, sdn=nil)
  return _coordinates_to_number(_decode(clk_time)) / @second
end

#tz_differenceWhen::TM:IntervalLength

夏時間帯と標準時間帯の時間差

Returns:

  • (When::TM:IntervalLength)


730
731
732
# File 'lib/when_exe/tmreference.rb', line 730

def tz_difference
  _tz_prop ? _tz_prop.tz_difference : 0
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:



695
696
697
698
699
700
701
702
703
704
705
706
707
# File 'lib/when_exe/tmreference.rb', line 695

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秒



551
552
553
# File 'lib/when_exe/tmreference.rb', line 551

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:



561
562
563
# File 'lib/when_exe/tmreference.rb', line 561

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