Class: When::TM::DateAndTime

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

Overview

時刻を伴った日付

see gml schema

Constant Summary

Constants inherited from CalDate

CalDate::SearchOption

Constants inherited from TemporalPosition

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

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 When

CENTURY, DAY, DECADE, DurationP1D, DurationP1M, DurationP1W, DurationP1Y, EUCJP, HOUR, MINUTE, MONTH, SECOND, STRING, SYSTEM, SourceURI, When::TimeValue, UTF8, VERSION, W31J, WEEK, YEAR

Constants included from Parts::Resource

Parts::Resource::LabelProperty, Parts::Resource::Prefix, Parts::Resource::PrefixIndex, Parts::Resource::PrefixKeys, Parts::Resource::PrefixValues

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 CalDate

#cal_date, #calendar_era, #calendar_era_name

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 CalDate

#%, #_date_to_s, #_event_form, #_to_hash, #calendar_name, #cwday, #cweek, #cwyear, #day, #leaf?, #least_significant_coordinate, #length, #mday, #month, #most_significant_coordinate, #mweek, #reference_label, #to_i, #to_residue, #wday, #yday, #year, #ymon, #yweek

Methods inherited from TemporalPosition

#+, #+@, #-, #<=>, #[], #^, _instance, #_notes, _options, _setup_, #_to_hash, #_to_s, #calendar_name, #clock_name, #copy, #dynamical_time, #has_next?, #has_time?, #include?, #is?, #month_included, #note?, #notes, #period, #prev, #rate_of_clock, #reference_label, #scan, #strftime, #succ, #term, #time_standard, #to_clock_time, #to_date, #to_date_time, #to_date_uri, #to_f, #to_i, #to_residue, #to_time, #to_uri, #week_included, #year_included

Methods included from Coordinates

to_deg, to_dms

Methods included from When

Calendar, CalendarEra, CalendarNote, Clock, Duration, M17n, MonthName, Pair, Residue, Resource, TemporalPosition, _free_conv, _parse, _setup_, at, client, config, era, free_conv, m17n, now, server, today, utc, when?

Methods included from TemporalPosition::Conversion

#julian_date, #tm_position

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?

Methods included from Parts::Resource::Pool

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

Methods included from Parts::Resource::Synchronize

#synchronize

Constructor Details

#initialize(date, time, options = {}) ⇒ DateAndTime

オブジェクトの生成

Parameters:

Options Hash (options):



1860
1861
1862
1863
# File 'lib/when_exe/tmposition.rb', line 1860

def initialize(date, time, options={})
  options[:time] = time
  super(date, 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_timeWhen::TM::ClockTime (readonly) Also known as: clkTime

時刻要素

Returns:



1700
1701
1702
# File 'lib/when_exe/tmposition.rb', line 1700

def clk_time
  @clk_time
end

Instance Method Details

#&(other) ⇒ When::TM::DateAndTime

ユリウス日または通年が指定の剰余となる日

Parameters:

Returns:

Raises:

  • (TypeError)


1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
# File 'lib/when_exe/tmposition.rb', line 1743

def &(other)
  raise TypeError,"The right operand should be When::Coordinates::Residue" unless other.kind_of?(Residue)
  case other.event
  when 'day'
    # 指定の剰余となる日
    other -= @frame.indices[-1].shift unless @frame.indices[-1].shift == 0
    return self.dup._copy({:events=>nil, :query=>@query, :validate=>:done,
                           :date=>_date_with_era(@frame.to_cal_date(other & to_i)),
                           :time=>@clk_time.clk_time.dup})

  when 'year'
    # 指定の剰余となる年
    date = @cal_date.dup
    date[0] = (other & (most_significant_coordinate + @frame._diff_to_CE)) - @frame._diff_to_CE
    return self.dup._copy({:events=>nil, :query=>@query,
                           :date=>_date_with_era(date),
                           :time=>@clk_time.clk_time.dup})

  else
    raise ArgumentError,"The right operand should have a unit 'day' or 'year'"
  end
end

#_attrObject

属性の Hash



1825
1826
1827
# File 'lib/when_exe/tmposition.rb', line 1825

def _attr
  super.merge({:clock=>clock})
end

#_copy(options = {}) ⇒ Object

属性のコピー



1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
# File 'lib/when_exe/tmposition.rb', line 1831

def _copy(options={})
  # 夏時間の調整
  case options[:time]
  when Array
    if clock._need_validate
      new_clock = clock._daylight { |c| self.class.new(options[:date], options[:time], {:frame=>@frame, :clock=>c}) } || clock
      options[:time] = options[:time].map {|t| t * 1}
    else
      new_clock = clock
    end
    options[:time] = @clk_time.dup._copy(options.merge({:clock=>new_clock}))
  when nil
    options[:time] = @clk_time.dup._copy(options)
  end

  return super(options)
end

#ceil(digit = DAY, precision = digit) ⇒ When::TM::DateAndTime

下位桁の切り上げ

digit     : Integer

Parameters:

  • digit (Integer) (defaults to: DAY)

    切り上げずに残す、最下位の桁

  • precision (Integer) (defaults to: digit)

    切り上げ結果の分解能

Returns:



1800
1801
1802
1803
1804
1805
1806
1807
# File 'lib/when_exe/tmposition.rb', line 1800

def ceil(digit=DAY, precision=digit)
  length  = clock.indices.length
  count   = digit - length
  period  = PeriodDuration.new((count<=0) ? 1 : 0.1**count, digit, (-@frame.indices.length)..length)
  result  = floor(digit, precision) + period
  result += clock._tz_difference if (result.universal_time <= self.universal_time)
  return result
end

#clockWhen::TM::Clock

時法の取得

Returns:



1707
1708
1709
# File 'lib/when_exe/tmposition.rb', line 1707

def clock
  @clk_time.frame
end

#floor(digit = DAY, precision = digit) ⇒ When::TM::DateAndTime

下位桁の切り捨て

Parameters:

  • digit (Integer) (defaults to: DAY)

    切り捨てずに残す、最下位の桁

  • precision (Integer) (defaults to: digit)

    切り捨て結果の分解能

Returns:



1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
# File 'lib/when_exe/tmposition.rb', line 1774

def floor(digit=DAY, precision=digit)
  count = digit - clock.indices.length
  date  = (digit>=DAY) ? @cal_date.dup : @frame._validate(@cal_date[0..(digit-1)])
  time  = clock._validate(@clk_time.clk_time[0..((digit<=DAY) ? 0 : ((count>=0) ? -1 : digit))])

  if (count >= 0)
    factor = 10**count
    time[-1] = (time[-1] * factor).floor.to_f / factor
  end

  # オブジェクトの生成
  options = {:date=>date, :validate=>:done, :events=>nil, :query=>nil,
             :time=>(digit<=DAY) ? time : @clk_time.dup._copy({:time=>time})}
  options[:precision] = precision if precision
  return self.dup._copy(options)
end

#hour(d = 0) ⇒ Numeric

Parameters:

  • d (Integer) (defaults to: 0)

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

Returns:



1210
1211
1212
# File 'lib/when_exe/inspect.rb', line 1210

def hour(d=0)
  @clk_time.hour(d)
end

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

Parameters:

  • d (Integer) (defaults to: 0)

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

Returns:



1220
1221
1222
# File 'lib/when_exe/inspect.rb', line 1220

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:



1179
1180
1181
1182
# File 'lib/when_exe/inspect.rb', line 1179

def name(index, format=nil)
  digit = _digit(index)
  (digit <= DAY) ? super : @clk_time.name(digit, format)
end

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

Parameters:

  • d (Integer) (defaults to: 0)

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

Returns:



1231
1232
1233
# File 'lib/when_exe/inspect.rb', line 1231

def second(d=0)
  @clk_time.second(d)
end

#to_cal_dateWhen::TM::CalDate Also known as: to_CalDate

時刻情報のない When::TM::CalDate を返す

Returns:



1813
1814
1815
1816
1817
1818
# File 'lib/when_exe/tmposition.rb', line 1813

def to_cal_date
  options = _attr
  options.delete(:clock)
  options[:precision] = [When::DAY, options[:precision]].min
  CalDate.new(@cal_date, options)
end

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

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

Parameters:

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

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

Returns:



1190
1191
1192
# File 'lib/when_exe/inspect.rb', line 1190

def to_m17n(precision=@precision)
  super + @clk_time.to_m17n(precision)
end

#to_s(precision = @precision) ⇒ String

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

Parameters:

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

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

Returns:



1200
1201
1202
# File 'lib/when_exe/inspect.rb', line 1200

def to_s(precision=@precision)
  super + @clk_time.to_s(precision)
end

#universal_timeNumeric

内部時間

Returns:

  • (Numeric)

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

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

Raises:

  • (NameError)


1719
1720
1721
1722
1723
1724
# File 'lib/when_exe/tmposition.rb', line 1719

def universal_time
  return super if [Now, Max, Min].include?(@indeterminated_position)
  raise NameError, "Temporal Reference System is not defined" unless (@frame && clock)
  @universal_time ||= (to_i - +@clk_time.clk_time[0] - JulianDate::JD19700101) * Duration::DAY +
                               @clk_time.universal_time
end

#value(index) ⇒ Numeric

要素の参照

Parameters:

  • index (Integer)

    参照する要素の指定

Returns:



1732
1733
1734
1735
# File 'lib/when_exe/tmposition.rb', line 1732

def value(index)
  digit = _digit(index)
  return (digit <= DAY) ? @cal_date[digit-1] : @clk_time.clk_time[digit]
end