Class: When::TM::TemporalPosition
- Inherits:
-
Object
- Object
- When::TM::TemporalPosition
- Extended by:
- When, Coordinates
- Includes:
- Comparable, When, Coordinates, Parts::Resource, IndeterminateValue, Conversion
- Defined in:
- lib/when_exe/tmposition.rb,
lib/when_exe/inspect.rb
Overview
「時間位置」の基底クラス
see gml schema
Direct Known Subclasses
Defined Under Namespace
Modules: Conversion
Constant Summary collapse
- HashProperty =
Position::HashProperty
- DateTimeInstanceMethods =
::Object.const_defined?(:Date) && ::Date.method_defined?(:+) ? ::DateTime.instance_methods : []
- AMPM =
['AM', 'PM'].map {|half| When::Parts::Resource._instance('_m:CalendarFormats::' + half)}
- Format =
{ 'a' => ['%s', 'a'], 'A' => ['%s', 'A'], 'b' => ['%s', 'b'], 'B' => ['%s', 'B'], 'c' => When::Parts::Resource._instance('_m:CalendarFormats::DateTime'), 'C' => ['%02d', 'C'], 'd' => ['%02d', 'd'], 'D' => '%m/%d/%y', 'e' => ['%2d', 'd'], 'E' => ['%s', 'E'], 'F' => ['%s', 'F'], 'G' => ['%d', 'G'], 'g' => ['%02d', 'g'], 'h' => '%b', 'H' => ['%02d', 'H'], 'I' => ['%02d', 'I'], 'j' => ['%03d', 'j'], 'k' => ['%2d', 'H'], 'l' => ['%2d', 'I'], 'm' => ['%02d', 'm'], 'M' => ['%02d', 'M'], 'n' => '\n', 'p' => ['%s', 'p'], 'P' => ['%s', 'P'], 'q' => ['%01d', 'd'], 'r' => '%I:%M:%S %p', 'R' => '%H:%M', 's' => ['%d', 's'], 'S' => ['%02d', 'S'], 't' => '\t', 'T' => '%H:%M:%S', 'u' => ['%d', 'u'], 'U' => ['%02d', 'U'], 'V' => ['%02d', 'V'], 'w' => ['%d', 'w'], 'W' => ['%02d', 'W'], 'x' => When::Parts::Resource._instance('_m:CalendarFormats::Date'), 'X' => When::Parts::Resource._instance('_m:CalendarFormats::Time'), 'y' => ['%02d', 'y'], 'Y' => ['%4d', 'Y'], 'z' => ['%s', 'z'], 'Z' => ['%s', 'Z'], '+' => '%a %b %d %T %z %Y' }
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::IRIDecode, Parts::Resource::IRIDecodeTable, Parts::Resource::IRIEncode, Parts::Resource::IRIEncodeTable, 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
-
#events ⇒ Array<When::Parts::Enumerator>
この時間位置と関連付けられたイベント - additional attribute.
-
#frame ⇒ When::TM::ReferenceSystem
この時間位置と関連付けられた時間参照系 (relation - Reference).
-
#indeterminated_position ⇒ When::TM::IndeterminateValue
(also: #indeterminatedPosition)
readonly
この時間位置の意味づけ.
-
#location ⇒ When::Coordinates::Spatial
その他の属性 - additional attribute.
-
#options ⇒ Hash
readonly
その他の属性 - additional attribute.
-
#precision ⇒ Numeric
この時間位置の分解能 - additional attribute.
-
#query ⇒ Hash
その他の属性 - additional attribute.
-
#trans ⇒ Hash
その他の属性 - additional attribute.
Attributes included from Parts::Resource
#_pool, #child, #keys, #locale, #namespace
Class Method Summary collapse
-
._instance(specification, options = {}) ⇒ When::TM::TemporalPosition, ...
Temporal Objetct の生成.
-
._options(options) ⇒ Object
option の正規化.
-
._setup_(format = nil) ⇒ void
When::TM::TemporalPosition Class のグローバルな設定を行う.
-
._setup_info ⇒ Hash
設定情報を取得する.
-
._temporal_position(*args) ⇒ Object
When::TM::TemporalPosition の生成.
-
._verify(source, target) ⇒ Object
比較.
-
.format ⇒ Object
strftime で用いる書式のハッシュ.
Instance Method Summary collapse
-
#+(other) ⇒ When::TM::TemporalPosition
加算.
-
#+@ ⇒ Float
ユリウス日時(実数).
-
#-(other) ⇒ When::TM::TemporalPosition, When::TM::Duration
減算.
-
#<=>(other) ⇒ Integer
大小比較.
-
#==(other) ⇒ Boolean
オブジェクトの同値.
-
#[](index) ⇒ Numeric
要素の参照.
-
#^(other, leaf = true, &block) ⇒ Array of (element^self) for all When::Parts::Resource registered elements, ...
条件を満たすオブジェクトの抽出.
-
#_attr ⇒ Object
属性の Hash.
-
#_notes(options = {}) ⇒ Array<Array<Hash{:note=>note, :value=>value}>>
時間位置オブジェクトの暦注を取得.
-
#_to_h(options = {}) ⇒ Hash
時間位置オブジェクトの内容を Hash 化.
- #_to_s ⇒ Object
-
#calendar_name ⇒ Array<Class>
暦法名.
-
#clock_name(prefix = true) ⇒ Array<String>
時法名.
-
#copy(options = {}) ⇒ When::TM::TemporalPosition
属性を変更したコピーを作る.
-
#dynamical_time ⇒ Numeric
外部時間.
-
#floor(digit = DAY, precision = digit) ⇒ When::TM::TemporalPosition
下位桁の切り捨て.
-
#has_next? ⇒ Boolean
前後の日時を取得可能か?.
-
#has_time? ⇒ Boolean
分解能が時刻を持つか.
-
#include?(date) ⇒ Boolean
指定の日時を含むか?.
-
#inspect ⇒ String
When::TM::TemporalPosition オブジェクトを分かりやすい文字列にして返します.
-
#is?(event = nil, options = {}) ⇒ Boolean
指定の日時が指定イベントに該当するか?.
-
#month_included(ord, wkst, opt, block) ⇒ Range, ...
含まれる月.
-
#note?(options = {}) ⇒ Boolean
暦注の一致 or 不一致.
-
#notes(options = {}) ⇒ Array<Array<Hash{:note=>note, :value=>value}>>
時間位置オブジェクトの暦注を取得し value を暦注の値 (String, When::BasicTypes::M17n or When::Coordinates::Residue)とする Hash で表現.
-
#period ⇒ When::TM::PeriodDuration
分解能に対応する Duration.
-
#prev ⇒ When::TM::TemporalPosition
前の日時.
-
#rate_of_clock ⇒ Numeric
時間の歩度.
-
#reference_label ⇒ When::BasicTypes::M17n
参照ラベル.
-
#scan(other, leaf = false, &block) ⇒ Array of (element^self) for all When::Parts::Resource registered elements, ...
条件を満たすオブジェクトの抽出.
-
#strftime(pattern = @frame.strftime, locale = nil) ⇒ When::BasicTypes::M17n
指定の書式による多言語対応文字列化 - pattern で指定した書式で多言語対応文字列化する.
-
#succ ⇒ When::TM::TemporalPosition
(also: #next)
次の日時.
-
#time_standard ⇒ When::TimeStandard
時刻系.
-
#to_clock_time ⇒ When::TM::ClokTime
When::TM::ClockTime オブジェクトへの変換.
-
#to_date(option = {}, start = _default_start) ⇒ ::Date
(also: #to_date_or_datetime)
標準ライブラリの Date オブジェクトへの変換.
-
#to_datetime(option = {:frame=>When::UTC}, start = _default_start) ⇒ ::DateTime
標準ライブラリの DateTime オブジェクトへの変換.
-
#to_f ⇒ Float
ユリウス日時(実数).
-
#to_i ⇒ Integer
ユリウス日(整数).
-
#to_m17n ⇒ When::BasicTypes::M17n
多言語対応文字列化 - When.exe Standard Representation により多言語対応文字列化する.
-
#to_residue(remainder, divisor) ⇒ When::Coordinates::Residue
剰余類化.
-
#to_s ⇒ String
文字列化 - When.exe Standard Representation により文字列化する.
-
#to_time ⇒ ::Time
組み込みライブラリの Time オブジェクトへの変換.
-
#to_uri ⇒ String
URI要素化 - URI表現の要素として用いる形式に変換.
-
#to_uri_escape ⇒ String
URI要素化 - URI表現の要素として用いる形式に変換(“^”はエスケープ).
-
#universal_time ⇒ Numeric
(also: #local_time)
内部時間.
-
#week_included(ord, wkst, opt, &block) ⇒ Range, Array
含まれる週.
-
#month_included(ord, wkst, opt, block) ⇒ Range, ...
含まれる年.
Methods included from Coordinates
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, at, client, column, config, const_missing, era, free_conv, m17n, now, server, today, when?
Methods included from Conversion
Methods included from Parts::Resource
_abbreviation_to_iri, _decode, _encode, _extract_prefix, _instantiate, _parse, _path_with_prefix, _replace_tags, _simplify_path, base_uri, #each, #enum_for, #hierarchy, #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
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object (private)
When::TM::TemporalPosition で定義されていないメソッドは 処理を @frame(class: When::TM::Calendar or When::TM::Clock) または to_date_or_datetime(class: ::Date or ::DateTime) に委譲する
その他のメソッド
1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 |
# File 'lib/when_exe/tmposition.rb', line 1127 def method_missing(name, *args, &block) return _method_missing(name, *args, &block) if When::Parts::MethodCash::Escape.key?(name) if DateTimeInstanceMethods.include?(name) && ! @frame.respond_to?(name) self.class.module_eval %Q{ def #{name}(*args, &block) self.to_date_or_datetime.send("#{name}", *args, &block) end } unless When::Parts::MethodCash.escape(name) self.to_date_or_datetime.send(name, *args, &block) else self.class.module_eval %Q{ def #{name}(*args, &block) @frame.send("#{name}", self, *args, &block) end } unless When::Parts::MethodCash.escape(name) @frame.send(name, self, *args, &block) end end |
Instance Attribute Details
#events ⇒ Array<When::Parts::Enumerator>
この時間位置と関連付けられたイベント - additional attribute
232 233 234 |
# File 'lib/when_exe/tmposition.rb', line 232 def events @events end |
#frame ⇒ When::TM::ReferenceSystem
この時間位置と関連付けられた時間参照系 (relation - Reference)
The time reference system associated with the temporal position being described
226 227 228 |
# File 'lib/when_exe/tmposition.rb', line 226 def frame @frame end |
#indeterminated_position ⇒ When::TM::IndeterminateValue (readonly) Also known as: indeterminatedPosition
この時間位置の意味づけ
217 218 219 |
# File 'lib/when_exe/tmposition.rb', line 217 def indeterminated_position @indeterminated_position end |
#location ⇒ When::Coordinates::Spatial
その他の属性 - additional attribute
265 266 267 |
# File 'lib/when_exe/tmposition.rb', line 265 def location @location end |
#options ⇒ Hash (readonly)
その他の属性 - additional attribute
247 248 249 |
# File 'lib/when_exe/tmposition.rb', line 247 def @options end |
#precision ⇒ Numeric
precision より resolution の方が分解能の意味にふさわしいが ISO19108 で別の意味に用いられているため resolution とした。
この時間位置の分解能 - additional attribute
241 242 243 |
# File 'lib/when_exe/tmposition.rb', line 241 def precision @precision end |
#query ⇒ Hash
その他の属性 - additional attribute
259 260 261 |
# File 'lib/when_exe/tmposition.rb', line 259 def query @query end |
#trans ⇒ Hash
その他の属性 - additional attribute
253 254 255 |
# File 'lib/when_exe/tmposition.rb', line 253 def trans @trans end |
Class Method Details
._instance(specification, options = {}) ⇒ When::TM::TemporalPosition, ...
options の中身は本メソッドによって更新されることがある。
:tz は ‘Asia/Tokyo’など時間帯を表す文字列をキーにして、登録済みのWhen::V::Timezone, When::Parts::Timezoneを検索して使用する。 :clock はWhen::Parts::Timezone::Baseオブジェクトをそのまま使用するか ‘+09:00’などの文字列をWhen::TM::Clock化して使用する。 :tz の方が :clock よりも優先される。
Temporal Objetct の生成
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 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 417 418 419 420 421 422 423 424 425 426 |
# File 'lib/when_exe/tmposition.rb', line 310 def _instance(specification, ={}) # prefix - RFC 5545 Options iso8601form = When::Parts::Resource::ContentLine.extract_rfc5545_Property(specification, ). gsub(When::Parts::Resource::IRIDecode) {|c| When::Parts::Resource::IRIDecodeTable[c]} # suffix - Frame specification if iso8601form =~ /\A(.*[^\d])\((([-+*&%@!>=<?\dW.]|\{.+?\})+)\)\z/ frame, iso8601form = $~[1..2] frame.sub!(/_+\z/, '') else iso8601form, frame, *rest = iso8601form.split(/\^{1,2}/) return rest.inject(_instance(iso8601form + '^' + frame, )) {|p,c| When.Resource(c, '_c:').jul_trans(p)} unless rest.empty? end # add frame to options = .merge({:frame=>When.Resource(frame, '_c:')}) if frame # indeterminateValue if (iso8601form.sub!(/\/After$|^Before\/|^Now$|^Unknown$|^[-+]Infinity\z/i, '')) [:indeterminated_position] = When::TimeValue::S[$&.sub(/\//,'')] case [:indeterminated_position] when When::TimeValue::Now, When::TimeValue::Unknown, When::TimeValue::Max, When::TimeValue::Min return self.new(self.()) end end # each specification splitted = iso8601form.split(/\//) if (splitted[0] =~ /\AR(\d+)?\z/) repeat = $1 ? $1.to_i : true splitted.shift end case splitted.length when 1 when 2 if (splitted[0] !~ /\A[-+]?P/ && splitted[1] =~ /\A\d/ && splitted[1].length < splitted[0].length) splitted[1] = splitted[0][0..(splitted[0].length-splitted[1].length-1)] + splitted[1] end else raise ArgumentError, "Irregal ISO8601 Format: #{iso8601form}" end = self.() element = splitted.map { |v| _date_time_or_duration(v, .dup) } # total result case repeat when nil case element[1] when nil return element[0] when Duration case element[0] when Duration ; raise TypeError, "Duplicate Duration: #{element[0]} and #{element[1]}" when self ; return When::Parts::GeometricComplex.new(*element) else ; return When::Parts::GeometricComplex.new(element[0].first, element[1]) end when self case element[0] when Duration ; return When::Parts::GeometricComplex.new([[element[1]-element[0],false], [element[1],true ]]) when self ; return When::Parts::GeometricComplex.new(element[0]..element[1]) else ; return When::Parts::GeometricComplex.new(element[0].first..element[1]) end else case element[0] when Duration ; return When::Parts::GeometricComplex.new([[element[1].first-element[0],false], [element[1].last-element[0]-1,true ]]) when self ; return When::Parts::GeometricComplex.new(element[0]...element[1].last) else ; return When::Parts::GeometricComplex.new(element[0].first...element[1].last) end end when 0 ; return [] when Integer ; return [element[0]] * repeat unless element[1] end case element[1] when Duration case element[0] when Duration ; raise TypeError, "Duplicate Duration: #{element[0]} and #{element[1]}" else ; duration = element[1] end when self case element[0] when Duration ; duration = -element[0] when self ; duration = element[1] - element[0] else ; duration = element[1] - element[0].first end else case element[0] when Duration ; duration = -element[0] when self ; duration = element[1].first - element[0] else ; duration = element[1].first - element[0].first end end base = element[0].kind_of?(Duration) ? element[1] : element[0] if repeat.kind_of?(Integer) result = case base when self ; (1..repeat-1).inject([base]) {|a,i| a << (a[-1] + duration) } else ; (1..repeat-1).inject([base]) {|a,i| a << When::Parts::GeometricComplex.new( a[-1].first+duration...a[-1].last+duration)} end result.reverse! if duration.sign < 0 return result else duration = -duration if duration.sign < 0 return case base when self ; When::V::Event.new({'rrule'=>{'FREQ'=>duration}, 'dtstart'=>base}) else ; When::V::Event.new({'rrule'=>{'FREQ'=>duration}, 'dtstart'=>base.first, 'dtend' =>base.last}) end end end |
._options(options) ⇒ Object
option の正規化
501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 |
# File 'lib/when_exe/tmposition.rb', line 501 def () query = .dup main = {} clock = Clock.get_clock_option(query) main[:clock] = clock if clock [:indeterminated_position, :frame, :events, :precision, :era_name, :era, :abbr, :extra_year_digits, :ordinal_date_digits, :wkst, :time_standard, :location].each do |key| main[key] = query.delete(key) if (query.key?(key)) end long = query.delete(:long) lat = query.delete(:lat) alt = query.delete(:alt) main[:location] ||= "_l:long=#{long||0}&lat=#{lat||0}&alt=#{alt||0}" if long && lat trans = query.delete(:trans) || {} [:lower, :upper, :count].each do |key| trans[key] = query.delete(key) if (query.key?(key)) end query = query.merge(query.delete(:query)) if (query.key?(:query)) main[:query] = query if (query.size > 0) main[:trans] = trans if (trans.size > 0) return main end |
._setup_(format = nil) ⇒ void
format の指定がない場合、format は Format(モジュール定数)と解釈する
This method returns an undefined value.
When::TM::TemporalPosition Class のグローバルな設定を行う
310 311 312 |
# File 'lib/when_exe/inspect.rb', line 310 def _setup_(format=nil) @format = format ? Format.merge(format) : Format end |
._setup_info ⇒ Hash
設定情報を取得する
318 319 320 |
# File 'lib/when_exe/inspect.rb', line 318 def _setup_info {:format => format} end |
._temporal_position(*args) ⇒ Object
When::TM::TemporalPosition の生成
432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 |
# File 'lib/when_exe/tmposition.rb', line 432 def _temporal_position(*args) # 引数の解釈 = args[-1].kind_of?(Hash) ? args.pop.dup : {} validate = .delete(:invalid) = TemporalPosition.() [:frame] ||= 'Gregorian' [:frame] = When.Resource([:frame], '_c:') if [:frame].kind_of?(String) case args[0] when String [:era_name] = When::EncodingConversion.to_internal_encoding(args.shift) when Array [:era_name] = args.shift [:era_name][0] = When::EncodingConversion.to_internal_encoding([:era_name][0]) end # 時間位置の生成 res = [] abbrs = Array([:abbr]) date = Array.new([:frame].indices.length-1) { element = args.shift abbr = abbrs.shift res << element.to('year') if element.kind_of?(When::Coordinates::Residue) element.kind_of?(Numeric) ? element : (abbr || 1) } date += Array.new(2) { element = args.shift abbr = abbrs.shift res << element.to('day') if element.kind_of?(When::Coordinates::Residue) case element when Numeric ; element when nil ; abbr else ; nil end } if args.length > 0 [:clock] ||= Clock.local_time [:clock] = When.Clock([:clock]) time = Array.new([:clock].indices.length) {args.shift} position = DateAndTime.new(date, time.unshift(0), ) else position = CalDate.new(date, ) end res.each do |residue| position = position.succ if residue.carry < 0 position &= residue end return position unless [:raise, :check].include?(validate) # 時間位置の存在確認 date[0] = -date[0] if position.calendar_era_props && position.calendar_era_reverse # 紀元前 date.each_index do |i| break unless date[i] next if When::Coordinates::Pair._force_pair(date[i]) == When::Coordinates::Pair._force_pair(position.cal_date[i]) return nil if validate == :check raise ArgumentError, "Specified date not found: #{date}" end return position unless time time.each_index do |i| break unless time[i] next if When::Coordinates::Pair._force_pair(time[i]) == When::Coordinates::Pair._force_pair(position.clk_time.clk_time[i]) return nil if validate == :check raise ArgumentError, "Specified time not found: #{time}" end return position end |
._verify(source, target) ⇒ Object
比較
526 527 528 529 |
# File 'lib/when_exe/tmposition.rb', line 526 def _verify(source, target) return source.universal_time <=> target.universal_time if source.time_standard.equal?(target.time_standard) return source.dynamical_time <=> target.dynamical_time end |
Instance Method Details
#+(other) ⇒ When::TM::TemporalPosition
加算
762 763 764 765 766 767 768 769 770 771 772 773 |
# File 'lib/when_exe/tmposition.rb', line 762 def +(other) case other when Integer ; self + PeriodDuration.new(other, When::DAY) when Numeric ; self + IntervalLength.new(other, 'day') when PeriodDuration ; _plus(other) when Duration ; @frame.kind_of?(Calendar) ? @frame.jul_trans(JulianDate.dynamical_time(dynamical_time + other.duration), self._attr) : JulianDate.dynamical_time(dynamical_time + other.duration, self._attr) else ; raise TypeError, "The right operand should be Numeric or Duration" end rescue RangeError (@frame ^ self) + other end |
#+@ ⇒ Float
ユリウス日時(実数)
689 690 691 |
# File 'lib/when_exe/tmposition.rb', line 689 def +@ JulianDate._t_to_d(dynamical_time) end |
#-(other) ⇒ When::TM::TemporalPosition, When::TM::Duration
減算
782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 |
# File 'lib/when_exe/tmposition.rb', line 782 def -(other) case other when TimeValue ; self.time_standard.rate_of_clock == other.time_standard.rate_of_clock && [@precision, other.precision].min <= When::DAY ? PeriodDuration.new(self.to_i - other.to_i, When::DAY) : IntervalLength.new((self.dynamical_time - other.dynamical_time) / Duration::SECOND, 'second') when Integer ; self - PeriodDuration.new(other, When::DAY) when Numeric ; self - IntervalLength.new(other, 'day') when PeriodDuration ; _plus(-other) when Duration ; @frame.kind_of?(Calendar) ? @frame.jul_trans(JulianDate.dynamical_time(dynamical_time - other.duration), self._attr) : JulianDate.dynamical_time(dynamical_time - other.duration, self._attr) else ; raise TypeError, "The right operand should be Numeric, Duration or TemporalPosition" end rescue RangeError (@frame ^ self) - other end |
#<=>(other) ⇒ Integer
大小比較
903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 |
# File 'lib/when_exe/tmposition.rb', line 903 def <=>(other) other = other.first if other.kind_of?(Range) return universal_time <=> other if other.kind_of?(Numeric) [self.indeterminated_position, other.indeterminated_position].each do |position| prec = SYSTEM if [TimeValue::Min, TimeValue::Max].include?(position) end prec = [self.precision, other.precision].min unless prec case prec when DAY ; return self.to_i <=> other.to_i when SYSTEM ; return TemporalPosition._verify(self, other) end if prec < DAY && respond_to?(:most_significant_coordinate) && other.respond_to?(:most_significant_coordinate) && @frame.equal?(other.frame) self_year = most_significant_coordinate other_year = other.most_significant_coordinate if @cal_date.length + prec == 1 self_year *= 1 other_year *= 1 end result = self_year <=> other_year return result unless result == 0 && @cal_date.length + prec > 1 (@cal_date.length + prec - 2).times do |i| result = @cal_date[i+1] <=> other.cal_date[i+1] return result unless result == 0 end @cal_date[prec - 1] <=> other.cal_date[prec - 1] else source = (prec >= self.precision ) ? self : self.floor(prec) target = (prec >= other.precision) ? other : other.floor(prec) return source.to_i <=> target.to_i if prec <= DAY TemporalPosition._verify(source, target) end end |
#==(other) ⇒ Boolean
オブジェクトの同値
886 887 888 889 890 |
# File 'lib/when_exe/tmposition.rb', line 886 def ==(other) (self <=> other) == 0 rescue false end |
#[](index) ⇒ Numeric
要素の参照
751 752 753 754 |
# File 'lib/when_exe/tmposition.rb', line 751 def [](index) return value(index) if index.kind_of?(String) || !index.respond_to?(:inject) index.inject([]) {|list, i| list << value(i) } end |
#^(other, leaf = true, &block) ⇒ Array of (element^self) for all When::Parts::Resource registered elements, ...
条件を満たすオブジェクトの抽出
1001 1002 1003 |
# File 'lib/when_exe/tmposition.rb', line 1001 def ^(other, leaf=true, &block) scan(other, leaf, &block) end |
#_attr ⇒ Object
属性の Hash
1019 1020 1021 1022 1023 1024 1025 1026 1027 |
# File 'lib/when_exe/tmposition.rb', line 1019 def _attr attributes = {} [:frame, :events, :precision, :options, :trans, :query].each do |key| attributes[key] = instance_variable_get("@#{key}") end attributes[:location] = location attributes[:time_standard] = time_standard return attributes.delete_if {|k,v| !v} end |
#_notes(options = {}) ⇒ Array<Array<Hash{:note=>note, :value=>value}>>
When::TM::TemporalPosition の場合、events に暦注名の入ったその暦注に該当する日付である。 (例) Christian クラス で easter を計算した場合、当該年の復活祭の日付オブジェクトが返る。 暦注サブクラスの場合、要素が増えたり、:note の暦注要素の型が変わったりすることがある。
時間位置オブジェクトの暦注を取得
609 610 611 |
# File 'lib/when_exe/inspect.rb', line 609 def _notes(={}) _calendar_note().notes(self, ) end |
#_to_h(options = {}) ⇒ Hash
時間位置オブジェクトの内容を Hash 化
675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 |
# File 'lib/when_exe/inspect.rb', line 675 def _to_h(={}) hash = super.update({ :sdn => to_i, :calendar => calendar_name, :notes => _notes() }) hash.update({ :clock => clock, :clk_time => to_clock_time, :dynamical => dynamical_time * clock.second, :universal => universal_time * clock.second }) if clock hash end |
#_to_s ⇒ Object
716 |
# File 'lib/when_exe/inspect.rb', line 716 alias :_to_s :to_s |
#calendar_name ⇒ Array<Class>
暦法名
341 342 343 |
# File 'lib/when_exe/inspect.rb', line 341 def calendar_name [self.class] end |
#clock_name(prefix = true) ⇒ Array<String>
時法名
351 352 353 |
# File 'lib/when_exe/inspect.rb', line 351 def clock_name(prefix=true) [clock.iri(prefix)] end |
#copy(options = {}) ⇒ When::TM::TemporalPosition
属性を変更したコピーを作る
1011 1012 1013 1014 1015 |
# File 'lib/when_exe/tmposition.rb', line 1011 def copy(={}) position = self.dup position._copy() position end |
#dynamical_time ⇒ Numeric
外部時間
637 638 639 640 641 642 643 644 645 |
# File 'lib/when_exe/tmposition.rb', line 637 def dynamical_time return @dynamical_time if @dynamical_time && @indeterminated_position != Now @dynamical_time = case @indeterminated_position when Max ; +Float::MAX/4 when Min ; -Float::MAX/4 else ; time_standard.to_dynamical_time(local_time) end end |
#floor(digit = DAY, precision = digit) ⇒ When::TM::TemporalPosition
下位桁の切り捨て
853 854 855 |
# File 'lib/when_exe/tmposition.rb', line 853 def floor(digit=DAY, precision=digit) self end |
#has_next? ⇒ Boolean
前後の日時を取得可能か?
841 842 843 |
# File 'lib/when_exe/tmposition.rb', line 841 def has_next? When::Coordinates::PERIOD_NAME[@precision] != nil end |
#has_time? ⇒ Boolean
分解能が時刻を持つか
861 862 863 |
# File 'lib/when_exe/tmposition.rb', line 861 def has_time? (@precision > 0) end |
#include?(date) ⇒ Boolean
指定の日時を含むか?
873 874 875 876 |
# File 'lib/when_exe/tmposition.rb', line 873 def include?(date) return false if self.precision > date.precision return self == date end |
#inspect ⇒ String
When::TM::TemporalPosition オブジェクトを分かりやすい文字列にして返します
332 333 334 |
# File 'lib/when_exe/inspect.rb', line 332 def inspect When::EncodingConversion.to_external_encoding(to_s) end |
#is?(event = nil, options = {}) ⇒ Boolean
指定の日時が指定イベントに該当するか?
647 648 649 650 651 652 653 654 |
# File 'lib/when_exe/inspect.rb', line 647 def is?(*args) = args.last.kind_of?(Hash) ? args.pop.dup : {} note = _calendar_note() event = args.first || .delete(:event) || note.event return note.note?(self, ) unless .empty? return note.note?(self, event) unless event.to_s =~ /\A([^\d]+)/ && note.respond_to?($1.downcase) return note.include?(self, event) end |
#month_included(ord, wkst, opt, block) ⇒ Range, ...
引数 ord, wkst, opt はそのクラスで位置づけを判断するため、引数の順序は任意(省略も可)
含まれる月
420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 |
# File 'lib/when_exe/inspect.rb', line 420 def month_included(*args, &block) first, length, wkst, opt = _range(args) if wkst (first...(first+length)).map {|i| begun = self.floor(MONTH,DAY) + When::TM::PeriodDuration.new([0,i,0]) ended = begun + P1M ended = ended.prev until begun.cal_date[MONTH-1] == ended.cal_date[MONTH-1] if ended.to_i <= begun.to_i ended = begun loop do succ = ended.succ break unless succ.frame.equal?(begun.frame) ended = succ end end dates = [begun] loop do current = dates[-1].week_included(wkst) if current.last.to_i > ended.to_i dates[-1] = ended break (dates.map {|date| date.week_included(wkst, {:Range=>begun.to_i..ended.to_i}, &block)}). unshift(yield(begun, MONTH)).compact elsif wkst.kind_of?(When::Coordinates::Residue) dates << dates[-1] + wkst.duration else it = wkst.enum_for(dates[-1], :forward) begin date = it.next end while date.to_i == dates[-1].to_i date = date.to_cal_date unless date.instance_of?(TM::CalDate) dates << date end end } else begun = self.floor(MONTH,DAY) + When::TM::PeriodDuration.new([0, first, 0]) ended = begun + When::TM::PeriodDuration.new([0, length, 0]) loop do last = ended.prev break unless last.cal_date[MONTH-1] == ended.cal_date[MONTH-1] ended = last end if block_given? (begun...ended).map do |date| yield(date) end else begun...ended end end end |
#note?(options = {}) ⇒ Boolean
暦注の一致 or 不一致
627 628 629 |
# File 'lib/when_exe/inspect.rb', line 627 def note?(={}) _calendar_note().note?(self, ) end |
#notes(options = {}) ⇒ Array<Array<Hash{:note=>note, :value=>value}>>
時間位置オブジェクトの暦注を取得し value を暦注の値 (String, When::BasicTypes::M17n or When::Coordinates::Residue)とする Hash で表現
582 583 584 585 586 587 588 589 |
# File 'lib/when_exe/inspect.rb', line 582 def notes(={}) = .kind_of?(Hash) ? : {} [:method] = :to_m17n unless .key?(:method) persistence = .delete(:persistence) if .kind_of?(Hash) retrieved = When::CalendarNote::NotesContainer.retrieve(persistence, self.to_i) return retrieved unless retrieved == false When::CalendarNote::NotesContainer.register(_m17n_form(_notes(), ), persistence, self.to_i) end |
#period ⇒ When::TM::PeriodDuration
分解能に対応する Duration
802 803 804 805 806 807 |
# File 'lib/when_exe/tmposition.rb', line 802 def period return @period if @period period_name = When::Coordinates::PERIOD_NAME[@precision] raise ArgumentError, "Presicion not defined" unless period_name @period = When.Duration(period_name) end |
#prev ⇒ When::TM::TemporalPosition
前の日時
815 816 817 818 819 |
# File 'lib/when_exe/tmposition.rb', line 815 def prev @precision==When::DAY ? _force_euqal_day(-1) : self-period rescue RangeError (When::Gregorian ^ self) - period end |
#rate_of_clock ⇒ Numeric
時間の歩度
609 610 611 |
# File 'lib/when_exe/tmposition.rb', line 609 def rate_of_clock time_standard.rate_of_clock end |
#reference_label ⇒ When::BasicTypes::M17n
参照ラベル
360 361 362 |
# File 'lib/when_exe/inspect.rb', line 360 def reference_label [When::BasicTypes::M17n.new(self.class.to_s.split(/::/)[-1])] end |
#scan(other, leaf = false, &block) ⇒ Array of (element^self) for all When::Parts::Resource registered elements, ...
条件を満たすオブジェクトの抽出
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 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 |
# File 'lib/when_exe/tmposition.rb', line 952 def scan(other, leaf=false, &block) list = [] case other when Numeric, TemporalPosition, Position raise TypeError, "Operand should not be Numeric or (Temporal)Position" when Module objects = [] ObjectSpace.each_object(other) do |object| objects << object if object.registered? end objects.each do |object| element = (object ^ self) if element && !(leaf && element.respond_to?(:leaf?) && !element.leaf?) list << element yield(element) if block_given? end end return list when Array return other.map {|v| scan(v, leaf, &block)} else if other.respond_to?(:_enumerator) enumerator = other._enumerator(self) return enumerator unless block_given? return enumerator.each(&block) end element = (other ^ self) if element && !(leaf && element.respond_to?(:leaf?) && !element.leaf?) list << element yield(element) if block_given? end if (other.respond_to?(:child) && other.child) other.child.each do |object| list += scan(object, leaf, &block) end end return list end end |
#strftime(pattern = @frame.strftime, locale = nil) ⇒ When::BasicTypes::M17n
指定の書式による多言語対応文字列化 - pattern で指定した書式で多言語対応文字列化する
698 699 700 701 702 703 |
# File 'lib/when_exe/inspect.rb', line 698 def strftime(pattern=@frame.strftime, locale=nil) pattern = m17n([pattern]*self.keys.length, nil, nil, {:locale=>self.keys}) if pattern.instance_of?(String) pattern._printf([], locale) do |k, *t| _strftime(k, pattern, ['']) end end |
#succ ⇒ When::TM::TemporalPosition Also known as: next
次の日時
827 828 829 830 831 |
# File 'lib/when_exe/tmposition.rb', line 827 def succ @precision==When::DAY ? _force_euqal_day(+1) : self+period rescue RangeError (When::Gregorian ^ self) + period end |
#time_standard ⇒ When::TimeStandard
時刻系
597 598 599 600 601 602 603 |
# File 'lib/when_exe/tmposition.rb', line 597 def time_standard return @time_standard if @time_standard.kind_of?(When::TimeStandard) @time_standard ||= clock.time_standard if respond_to?(:clock) && clock @time_standard ||= frame.time_standard if frame @time_standard ||= 'UniversalTime' @time_standard = When.Resource(@time_standard, '_t:') end |
#to_clock_time ⇒ When::TM::ClokTime
When::TM::ClockTime オブジェクトへの変換
697 698 699 700 701 702 |
# File 'lib/when_exe/tmposition.rb', line 697 def to_clock_time raise TypeError, "Clock not assigned" unless clock clk_time = clock.to_clk_time(universal_time - (to_i - JulianDate::JD19700101)*Duration::DAY) clk_time.clk_time[0] += to_i return clk_time end |
#to_date(option = {}, start = _default_start) ⇒ ::Date Also known as: to_date_or_datetime
標準ライブラリの Date オブジェクトへの変換
731 732 733 734 |
# File 'lib/when_exe/tmposition.rb', line 731 def to_date(option={}, start=_default_start) return JulianDate.dynamical_time(dynamical_time, option).to_date unless time_standard.rate_of_clock == 1.0 ::Date.jd(to_i, start) end |
#to_datetime(option = {:frame=>When::UTC}, start = _default_start) ⇒ ::DateTime
標準ライブラリの DateTime オブジェクトへの変換
713 714 715 716 717 718 719 720 |
# File 'lib/when_exe/tmposition.rb', line 713 def to_datetime(option={:frame=>When::UTC}, start=_default_start) return JulianDate.dynamical_time(dynamical_time, option).to_datetime unless time_standard.rate_of_clock == 1.0 raise TypeError, "Clock not assigned" unless clock Rational offset = Rational(-(clock.universal_time/Duration::SECOND).to_i, (Duration::DAY/Duration::SECOND).to_i) clk_time = clock.to_clk_time(universal_time - (to_i - JulianDate::JD19700101)*Duration::DAY).clk_time ::DateTime.jd(to_i, clk_time[1], clk_time[2], clk_time[3].to_i, offset, start) end |
#to_f ⇒ Float
ユリウス日時(実数)
653 654 655 |
# File 'lib/when_exe/tmposition.rb', line 653 def to_f JulianDate._t_to_d(universal_time) end |
#to_i ⇒ Integer
ユリウス日(整数)
663 664 665 666 667 668 |
# File 'lib/when_exe/tmposition.rb', line 663 def to_i sd = universal_time sd -= @frame.universal_time if @frame.kind_of?(Clock) div, mod = sd.divmod(Duration::DAY) div + JulianDate::JD19700101 end |
#to_m17n ⇒ When::BasicTypes::M17n
多言語対応文字列化 - When.exe Standard Representation により多言語対応文字列化する
711 712 713 714 |
# File 'lib/when_exe/inspect.rb', line 711 def to_m17n(*args) return m17n(I[@indeterminated_position]) if [Unknown, Max, Min].include?(@indeterminated_position) return m17n(_to_s) end |
#to_residue(remainder, divisor) ⇒ When::Coordinates::Residue
剰余類化
679 680 681 |
# File 'lib/when_exe/tmposition.rb', line 679 def to_residue(remainder, divisor) When::Coordinates::Residue.new(remainder, divisor, {'day'=>to_i}) end |
#to_s ⇒ String
文字列化 - When.exe Standard Representation により文字列化する
724 725 726 |
# File 'lib/when_exe/inspect.rb', line 724 def to_s(*args) to_m17n(*args).to_s end |
#to_time ⇒ ::Time
組み込みライブラリの Time オブジェクトへの変換
741 742 743 |
# File 'lib/when_exe/tmposition.rb', line 741 def to_time time_standard.to_time_object(universal_time) end |
#to_uri ⇒ String
URI要素化 - URI表現の要素として用いる形式に変換
734 735 736 |
# File 'lib/when_exe/inspect.rb', line 734 def to_uri(*args) _to_uri(to_s(*args)) end |
#to_uri_escape ⇒ String
URI要素化 - URI表現の要素として用いる形式に変換(“^”はエスケープ)
744 745 746 |
# File 'lib/when_exe/inspect.rb', line 744 def to_uri_escape(*args) _to_uri(to_s(*args)).gsub('^', '%5E') end |
#universal_time ⇒ Numeric Also known as: local_time
内部時間
621 622 623 624 625 626 627 628 |
# File 'lib/when_exe/tmposition.rb', line 621 def universal_time case @indeterminated_position when Now ; time_standard.from_time_object(Time.now) when Max ; +Float::MAX/4 when Min ; -Float::MAX/4 else ; raise NameError, "Temporal Reference System is not defined" end end |
#week_included(ord, wkst, opt, &block) ⇒ Range, Array
引数 ord, wkst, opt はそのクラスで位置づけを判断するため、引数の順序は任意(省略も可)
含まれる週
385 386 387 388 389 390 391 392 393 394 395 396 |
# File 'lib/when_exe/inspect.rb', line 385 def week_included(*args, &block) begin first, length, wkst, opt = _range(args, 'MO') range = wkst._range_for_week_included(self, first, length, block_given?) rescue RangeError range = wkst._range_for_week_included(@frame ^ self, first, length) end return range.first unless block_given? wkst._column_for_week_included(self, range, opt, &block).unshift(yield(range[0].first, WEEK)).compact end |
#month_included(ord, wkst, opt, block) ⇒ Range, ...
引数 ord, wkst, opt はそのクラスで位置づけを判断するため、引数の順序は任意(省略も可)
含まれる年
494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 |
# File 'lib/when_exe/inspect.rb', line 494 def year_included(*args, &block) first, length, wkst, opt = _range(args) if wkst (first...(first+length)).map {|i| begun = _force_euqal_year(i) ended = _force_euqal_year(i+1) current = begun result = [yield(begun, YEAR)] ended += P1M if ended.floor(MONTH).most_significant_coordinate * 1 == begun.most_significant_coordinate * 1 while current < ended do result << current.month_included(wkst, &block) current += P1M end result.compact } else begun = _force_euqal_year(first) ended = _force_euqal_year(first+length) if block_given? (begun...ended).map do |date| yield(date) end else begun...ended end end end |