Class: When::TM::DateAndTime

Inherits:
CalDate show all
Defined in:
lib/when_exe/tmptypes.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::DateTimeInstanceMethods, TemporalPosition::Format, TemporalPosition::HashProperty

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 When

AUTHOR, CENTURY, COPYRIGHT, 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, YEARS

Constants included from Parts::Resource

Parts::Resource::ConstList, Parts::Resource::ConstTypes, Parts::Resource::IRIDecode, Parts::Resource::IRIDecodeTable, Parts::Resource::IRIEncode, Parts::Resource::IRIEncodeTable, Parts::Resource::IRIHeader, Parts::Resource::LabelProperty

Constants included from Namespace

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

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_props

Attributes inherited from TemporalPosition

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

Attributes included from Parts::Resource

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

Instance Method Summary collapse

Methods inherited from CalDate

#%, #_event_form, #_to_h, #calendar_era_epoch, #calendar_era_go_back, #calendar_era_name, #calendar_era_reverse, #calendar_name, #coordinate, #cwday, #cweek, #cwyear, #day, #leaf?, #least_significant_coordinate, #length, #mday, #member, #month, #most_significant_coordinate, #mweek, #prev, #rdf_graph, #reference_label, #register_graph, #succ, #to_i, #to_jsonld_hash, #to_linked_data, #to_residue, #to_uri_linkeddata, #wday, #without_era, #yday, #year, #ymon, #yweek

Methods inherited from TemporalPosition

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

Methods included from Coordinates

to_deg, to_deg_225, to_dms, utf_gets

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, date_or_era, era, free_conv, m17n, now, server, strptime, today, when?, where?

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, #parent, #registered?, root_dir

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):



1178
1179
1180
1181
# File 'lib/when_exe/tmptypes.rb', line 1178

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:



971
972
973
# File 'lib/when_exe/tmptypes.rb', line 971

def clk_time
  @clk_time
end

Instance Method Details

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

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

Parameters:

Returns:

Raises:

  • (TypeError)


1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
# File 'lib/when_exe/tmptypes.rb', line 1027

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

  when 'year'
    # 指定の剰余となる年
    date     = @frame.send(:_decode, _date_without_era)
    date[0]  = (other & (date[0] + @frame.diff_to_CE)) - @frame.diff_to_CE
    options  = {:date=>_date_with_era(@frame.send(:_encode, date)), :time=>@clk_time.clk_time.dup,
                :events=>nil, :query=>@query}
    options[:precision] = When::YEAR if precision < When::YEAR
    return self.dup._copy(options)

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

#_attrObject

属性の Hash



1137
1138
1139
# File 'lib/when_exe/tmptypes.rb', line 1137

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

#_copy(options = {}) ⇒ Object

属性のコピー



1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
# File 'lib/when_exe/tmptypes.rb', line 1143

def _copy(options={})
  # 夏時間の調整
  case options[:time]
  when Array
    if clock._need_validate
      if @calendar_era_props
        date     = options[:date].dup
        date[0] += calendar_era_epoch
      else
        date     = options[:date]
      end
      new_clock = clock._daylight([@frame, date, options[:time]])
      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

下位桁の切り上げ

Parameters:

  • digit (Integer) (defaults to: DAY)

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

  • precision (Integer) (defaults to: digit)

    切り上げ結果の分解能

Returns:



1100
1101
1102
1103
1104
1105
1106
1107
# File 'lib/when_exe/tmptypes.rb', line 1100

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:



978
979
980
# File 'lib/when_exe/tmptypes.rb', line 978

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:



1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
# File 'lib/when_exe/tmptypes.rb', line 1061

def floor(digit=DAY, precision=digit)
  count    = digit - clock.indices.length

  if digit>=DAY
    date     = @cal_date.dup
  elsif @calendar_era_props
    date     = @cal_date.dup
    date[0] += calendar_era_epoch
    date     = @frame._validate(date[0..(digit-1)])
    date[0] -= calendar_era_epoch
  else
    date     = @frame._validate(@cal_date[0..(digit-1)])
  end

  time     = @clk_time.clk_time[0..((digit<=DAY) ? 0 : ((count>=0) ? -1 : digit))]
  time[0] += to_i
  time     = clock._validate(time)
  time[0] -= to_i

  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:



1475
1476
1477
# File 'lib/when_exe/inspect.rb', line 1475

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

#local_timeNumeric

内部時間(ローカル)

Returns:

  • (Numeric)

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

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

Raises:

  • (NameError)


1004
1005
1006
1007
1008
# File 'lib/when_exe/tmptypes.rb', line 1004

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

#locationWhen::Coordinates::Spatial

位置情報



1113
1114
1115
# File 'lib/when_exe/tmptypes.rb', line 1113

def location
  @location ||= @clk_time.frame.location
end

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

Parameters:

  • d (Integer) (defaults to: 0)

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

Returns:



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

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:



1431
1432
1433
1434
# File 'lib/when_exe/inspect.rb', line 1431

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:



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

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

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

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

Returns:



1121
1122
1123
1124
1125
1126
# File 'lib/when_exe/tmptypes.rb', line 1121

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, round = false) ⇒ When::BasicTypes::M17n

Note:

丸めるのは precision が When::DAY よりも高精度の場合のみである

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

Parameters:

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

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

  • round (true, false) (defaults to: false)

    指定の桁までで丸める(true)か, 切り捨てる(false)か

Returns:



1444
1445
1446
# File 'lib/when_exe/inspect.rb', line 1444

def to_m17n(precision=@precision, round=false)
  super + _clk_time_for_inspect(round ? precision : nil).to_m17n(precision)
end

#to_s(precision = @precision, round = false) ⇒ String

Note:

丸めるのは precision が When::DAY よりも高精度の場合のみである

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

Parameters:

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

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

  • round (true, false) (defaults to: false)

    指定の桁までで丸める(true)か, 切り捨てる(false)か

Returns:



1456
1457
1458
# File 'lib/when_exe/inspect.rb', line 1456

def to_s(precision=@precision, round=false)
  super + _clk_time_for_inspect(round ? precision : nil).to_s(precision)
end

#universal_timeNumeric

内部時間

Returns:

  • (Numeric)

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

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

Raises:

  • (NameError)


990
991
992
993
994
# File 'lib/when_exe/tmptypes.rb', line 990

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 - JulianDate::JD19700101) * Duration::DAY + @clk_time.universal_time(to_i)
end

#value(index) ⇒ Numeric

要素の参照

Parameters:

  • index (Integer)

    参照する要素の指定

Returns:



1016
1017
1018
1019
# File 'lib/when_exe/tmptypes.rb', line 1016

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