Class: When::TM::ClockTime

Inherits:
TemporalPosition show all
Defined in:
lib/when_exe/tmposition.rb,
lib/when_exe/inspect.rb

Overview

時刻

see gml schema

Constant Summary

Constants inherited from TemporalPosition

TemporalPosition::AMPM, TemporalPosition::DateTimeInstanceMethods, TemporalPosition::Format, TemporalPosition::HashProperty

Constants included from Coordinates

Coordinates::Bahai, Coordinates::Common, Coordinates::DefaultDateIndices, Coordinates::DefaultDayIndex, Coordinates::DefaultTimeIndices, Coordinates::Indian, Coordinates::Iranian, 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 When

CENTURY, DAY, DECADE, EUCJP, HOUR, MINUTE, MONTH, MinusInfinity, Month, P1D, P1M, P1W, P1Y, PT1H, PT1M, PT1S, PlusInfinity, RootDir, SECOND, STRING, SYSTEM, SourceURI, When::TimeValue, UTF8, VERSION, W31J, WEEK, Week, YEAR

Constants included from Parts::Resource

Parts::Resource::ConstList, Parts::Resource::ConstTypes, Parts::Resource::IRIHeader, Parts::Resource::LabelProperty

Constants included from IndeterminateValue

IndeterminateValue::After, IndeterminateValue::Before, IndeterminateValue::I, IndeterminateValue::Max, IndeterminateValue::Min, IndeterminateValue::Now, IndeterminateValue::S, IndeterminateValue::Unknown

Instance Attribute Summary collapse

Attributes inherited from TemporalPosition

#events, #frame, #indeterminated_position, #location, #options, #precision, #query, #trans

Attributes included from Parts::Resource

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

Instance Method Summary collapse

Methods inherited from TemporalPosition

#+, #+@, #-, #<=>, #==, #[], #^, #_attr, _instance, #_notes, _options, _setup_, _setup_info, _temporal_position, #_term, #_to_h, #_to_s, _verify, #calendar_name, #caret_frame, #clock_name, #copy, #dynamical_time, #floor, format, #has_next?, #has_time?, #include?, #inspect, #is?, #month_included, #note?, #notes, #period, #prev, #rate_of_clock, #reference_label, #scan, #strftime, #succ, #time_standard, #to_clock_time, #to_date, #to_datetime, #to_f, #to_i, #to_residue, #to_time, #week_included, #year_included

Methods included from Coordinates

to_deg, to_deg_225, to_dms

Methods included from When

Border, Calendar, CalendarEra, CalendarNote, Clock, Duration, Index, Location, M17n, MonthName, Pair, Residue, Resource, TemporalPosition, Wikipedia, _const_missing, _define_common_calendar_types, _setup_, _setup_info, at, client, column, config, const_missing, era, free_conv, m17n, now, server, today, when?

Methods included from TemporalPosition::Conversion

#julian_date, #tm_pos

Methods included from Parts::Resource

#[], #^, _abbreviation_to_iri, _decode, _encode, _extract_prefix, _instance, _instantiate, _parse, _path_with_prefix, _replace_tags, _setup_, _setup_info, _simplify_path, base_uri, #each, #enum_for, #hierarchy, #include?, #included?, #iri, #leaf?, #m17n, #map, #next, #parent, #prev, #registered?, root_dir

Methods included from Parts::Resource::Pool

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

Methods included from Parts::Resource::Synchronize

#synchronize

Constructor Details

#initialize(time, options = {}) ⇒ ClockTime

オブジェクトの生成

Parameters:

  • time (String)

    ISO8601形式の時刻表現

  • time (Array<Numeric>)

    (日, 時, 分, 秒)

  • options (Hash) (defaults to: {})

    以下の通り

Options Hash (options):



1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
# File 'lib/when_exe/tmposition.rb', line 1533

def initialize(time, options={})
  # 参照系の取得
  @frame = options[:frame] || Clock.local_time
  @frame = When.Clock(@frame) if (@frame.kind_of?(String))
  options.delete(:frame)

  # 時刻表現の解読 ( Time Zone の解釈 )
  if (time.kind_of?(String))
    case time
    when /\A([-+])?(\d{2,}?):?(\d{2})?:?(\d{2}(\.\d+)?)?\z/
      sign, hh, mm, ss = $~[1..4]
      time = @frame._validate([0,0,0,0],
             [0,
              -(sign.to_s + "0" + hh.to_s).to_i,
              -(sign.to_s + "0" + mm.to_s).to_i,
              Pair._en_number(-(sign.to_s + "0" + ss.to_s).to_f)])
      time[0] = Pair.new(0, time[0].to_i) if (time[0] != 0)
    when /\AZ\z/
      time = [0,0,0,0]
    else
      raise ArgumentError, "Invalid Time Format"
    end
  end
  @clk_time = time

  # 分解能
  @precision = @frame._precision(time, options.delete(:precision))

  super(options)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class When::TM::TemporalPosition

Instance Attribute Details

#clk_timeArray<Numeric> (readonly) Also known as: clkTime

Note:

ISO19108 では sequence<Integer> だが、閏時・閏秒などが表現可能なよう Numeric としている。

時刻要素

Returns:



1449
1450
1451
# File 'lib/when_exe/tmposition.rb', line 1449

def clk_time
  @clk_time
end

Instance Method Details

#_copy(options = {}) ⇒ Object

protected 属性のコピー



1513
1514
1515
1516
1517
1518
1519
1520
1521
# File 'lib/when_exe/tmposition.rb', line 1513

def _copy(options={})
  @clk_time = options[:time]  if (options.key?(:time))
  @frame    = options[:clock] if (options.key?(:clock))
  if (options.key?(:tz_prop))
    @frame  = @frame.dup
    @frame.tz_prop = options[:tz_prop]
  end
  return super
end

#_time_to_s(precision = @precision) ⇒ String

protected

時間帯以外の部分の文字列化

Parameters:

  • precision (Integer) (defaults to: @precision)

    どの桁まで多言語対応文字列化するか、分解能で指定する

Returns:



950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
# File 'lib/when_exe/inspect.rb', line 950

def _time_to_s(precision=@precision)
  terms   = []
  format  = ''
  format += Pair::DL2[@clk_time[0] * 0] || ':' if @frame.pair[0] || @clk_time[0].kind_of?(Pair)

  # 時分
  digits = [@clk_time.length-2, precision].min
  if digits > 0
    terms  += @clk_time[1..-1]
    format += "%02d:" * digits
    format  = format[0..-2] if precision == digits
  end

  # 秒
  digits  = [precision - @clk_time.length + 1, STRING-SECOND].min
  if digits == 0
    format += "%02d"
  elsif digits > 0
    factor  = 10**digits
    terms[-1] = ((@clk_time[-1] + 1E-6) * factor).floor.to_f / factor  # 切り捨て(10で割る丸めガードあり)
    format += "%02.#{digits}f"
  end

  # 結果
  time = Pair._format([format] + terms)
  time.sub(/([^\d])(\d)\./, '\10\2.')
end

#_to_hash_value(options = {}) ⇒ Object

to_h のための要素生成



981
982
983
# File 'lib/when_exe/inspect.rb', line 981

def _to_hash_value(options={})
  clk_time.map {|e| _m17n_form(e, options) }
end

#carryNumeric

繰り上がり

Returns:

  • (Numeric)

    日付の境界が午前0時でない場合、clk_time の最上位桁に 0 以外が入ることがある



1496
1497
1498
# File 'lib/when_exe/tmposition.rb', line 1496

def carry
  return @clk_time[0]
end

#hour(d = 0) ⇒ Numeric

Parameters:

  • d (Integer) (defaults to: 0)

    時刻が‘時分秒’でない表現のための桁位置変更指示(小さいほうに位置をずらす)

Returns:



913
914
915
# File 'lib/when_exe/inspect.rb', line 913

def hour(d=0)
  @clk_time[HOUR+d]
end

#local_time(sdn = nil) ⇒ Numeric

内部時間(ローカル)

Parameters:

  • sdn (Integer) (defaults to: nil)

    参照事象の通し番号

Returns:

  • (Numeric)

    T00:00:00(ローカル) からの Universal Coordinated Time の経過時間 / 128秒

    時法によっては、異なる意味を持つことがある

Raises:

  • (NameError)


1485
1486
1487
1488
# File 'lib/when_exe/tmposition.rb', line 1485

def local_time(sdn=nil)
  raise NameError, "Temporal Reference System is not defined" unless @frame
  @local_time ||= @frame.to_local_time(@clk_time, sdn)
end

#minute(d = 0) ⇒ Numeric Also known as: min

Parameters:

  • d (Integer) (defaults to: 0)

    時刻が‘時分秒’でない表現のための桁位置変更指示(小さいほうに位置をずらす)

Returns:



924
925
926
# File 'lib/when_exe/inspect.rb', line 924

def minute(d=0)
  @clk_time[MINUTE+d]
end

#name(index, format = nil) ⇒ When::BasicTypes::M17n

要素の多言語対応文字列化

Parameters:

  • index (Integer)

    多言語対応文字列化する要素の指定

  • format (When::BasicTypes::M17n) (defaults to: nil)

    多言語対応文字列化の書式

Returns:



862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
# File 'lib/when_exe/inspect.rb', line 862

def name(index, format=nil)
  digit      = _digit(index) {|digit| digit > DAY}
  coordinate = @clk_time[digit]
  return m17n(format % coordinate) if format

  indices  = @frame.indices[digit-1]
  if indices
    trunk  = indices.trunk
    branch = indices.branch
  end
  format = branch ? m17n("%02d:") : "%02d"
  return m17n(format % coordinate) unless trunk
  trunk  = trunk[coordinate * 1]
  return m17n(trunk) unless branch
  return trunk.prefix(branch[coordinate * 0])
end

#second(d = 0) ⇒ Numeric Also known as: sec

Parameters:

  • d (Integer) (defaults to: 0)

    時刻が‘時分秒’でない表現のための桁位置変更指示(小さいほうに位置をずらす)

Returns:



936
937
938
# File 'lib/when_exe/inspect.rb', line 936

def second(d=0)
  @clk_time[SECOND+d]
end

#to_m17n(precision = @precision) ⇒ When::BasicTypes::M17n

多言語対応文字列化 - When.exe Standard Representation により多言語対応文字列化する

Parameters:

  • precision (Integer) (defaults to: @precision)

    どの桁まで多言語対応文字列化するか、分解能で指定する

Returns:



885
886
887
888
889
890
891
# File 'lib/when_exe/inspect.rb', line 885

def to_m17n(precision=@precision)
  time  = m17n('T' + _time_to_s(precision))
  if @frame
    time += @frame.zone unless Clock.is_local_time_set? && @frame.equal?(Clock.local_time)
  end
  return time
end

#to_s(precision = @precision) ⇒ String

文字列化 - When.exe Standard Representation により文字列化する

Parameters:

  • precision (Integer) (defaults to: @precision)

    どの桁まで多言語対応文字列化するか、分解能で指定する

Returns:



899
900
901
902
903
904
905
# File 'lib/when_exe/inspect.rb', line 899

def to_s(precision=@precision)
  time  = 'T' + _time_to_s(precision)
  if @frame
    time += @frame.zone unless Clock.is_local_time_set? && @frame.equal?(Clock.local_time)
  end
  return time
end

#universal_time(sdn = nil) ⇒ Numeric

内部時間

Parameters:

  • sdn (Integer) (defaults to: nil)

    参照事象の通し番号

Returns:

  • (Numeric)

    T00:00:00Z からの Universal Coordinated Time の経過時間 / 128秒

    時法によっては、異なる意味を持つことがある

Raises:

  • (NameError)


1470
1471
1472
1473
# File 'lib/when_exe/tmposition.rb', line 1470

def universal_time(sdn=nil)
  raise NameError, "Temporal Reference System is not defined" unless @frame
  @universal_time ||= @frame.to_universal_time(@clk_time, sdn)
end

#value(index) ⇒ Numeric

要素の参照

Parameters:

  • index (Integer, String)

    参照する要素の指定

Returns:



1506
1507
1508
# File 'lib/when_exe/tmposition.rb', line 1506

def value(index)
  @clk_time[_digit(index) {|digit| digit >= DAY}]
end