A multicultural and multilingualized calendar library based on ISO 8601, ISO 19108 and RFC 5545
When::TM::Calendar の生成/参照
calendar : String
暦法を表す文字列
returns : When::TM::Calendar
calendar に対応する When::TM::Calendar オブジェクト
# File when.rb, line 294
294: def Calendar(calendar)
295: Parts::IRI._instance(calendar, '_c:')
296: end
When::TM::CalendarEra の生成/参照
key : When::BasicTypes::M17n
検索する暦年代またはその文字列の一部
epoch : Integer
年数を昇順にカウントする方式での暦元(0年)の通年(デフォルトは nil - 指定なし)
reverse : Integer
年数を降順にカウントする方式での暦元(0年)の通年(デフォルトは nil - 指定なし)
options : Hash
:area => When::BasicTypes::M17n
暦年代の使用地域の指定(デフォルトは nil - 指定なし)
:period => When::BasicTypes::M17n
暦年代の使用時代の指定(デフォルトは nil - 指定なし)
:count => Integer
何件ヒットするまで検索するかを指定(デフォルトは 1件)
the others => String
例えば When::TM::CalendarEra オブジェクトの epoch_of_use に 'name' などの指定がある場合、
:name に指定しておけば、検索での絞り込みに使用できる。
returns : [When::TM::CalendarEra]
検索結果を When::TM::CalendarEra オブジェクトの Array で返す
ヒット数が不足している場合は、setup で指定した順序で When::TM::CalendarEra オブジェクトを
生成しつつ読み込んで検索する。
# File when.rb, line 282
282: def CalendarEra(*args)
283: TM::CalendarEra._instance(*args)
284: end
When::TM::Clock の生成/参照
clock : String
時法を表す文字列
(When::TM::Clockならそのまま返す)
returns : When::TM::Clock
clock に対応する When::TM::Clock オブジェクト
# File when.rb, line 307
307: def Clock(clock)
308: case clock
309: when 'Z' ; return utc
310: when TM::Clock ; return clock
311: when String
312: c = TM::Clock[clock] || V::Timezone[clock]
313: return c if c
314: Parts::IRI._instance("_tm:Clock?label=" + clock)
315: else ; raise TypeError, "Invalid Type: #{clock.class}"
316: end
317: end
period : duration の指定
String - When Standard Representation として解釈して生成する
Numeric - When::TM::IntervalLength::SYSTEM 単位の値として解釈して生成する
Array - 要素を個別に解釈して生成したオブジェクトのArrayを返す
When::TM::Duration - 処理を行わず、そのまま返す
options : 現時点では未使用
returns : When::TM::Duration or [When::TM::Duration]
# File when.rb, line 236
236: def Duration(period, options={})
237: case period
238: when Array
239: return period.map {|e| Duration(e, options)}
240:
241: when TM::Duration
242: return period
243:
244: else
245: # IntervalLength
246: args = TM::IntervalLength._to_array(period)
247: return TM::IntervalLength.new(*args) if args
248:
249: # PeriodDuration
250: sign, *args = TM::PeriodDuration._to_array(period)
251: raise TypeError, "Argument 'period' is not a Duration" unless (sign)
252: args << options
253: duration = TM::PeriodDuration.new(*args)
254: return (sign >= 0) ? duration : -duration
255: end
256: end
When::Parts::IRI の生成/参照
iri : String
IRI を表す文字列
namespace : String
デフォルトの namespace
returns : When::Parts::IRI
iri (または namespace:iri) に対応する When::Parts::IRI オブジェクト
# File when.rb, line 334
334: def IRI(iri, namespace=nil)
335: Parts::IRI._instance(iri, namespace)
336: end
When::BasicTypes::M17n の生成/参照
source : locale と 文字列の対応 namespace : prefix の指定 locale : locale の定義順序の指定 returns : When::BasicTypes::M17n
see When::BasicTypes::M17n.new
# File when.rb, line 347
347: def M17n(source, namespace=nil, locale=nil)
348: case source
349: when Array ; BasicTypes::M17n.new(source, namespace, locale)
350: when BasicTypes::M17n ; source
351: when String
352: return Parts::IRI[$1] if source =~ /^\s*\[::([^\]]+)\]/
353: BasicTypes::M17n.new(source, namespace, locale)
354: else ; raise TypeError, "Invalid Type: #{source.class}"
355: end
356: end
trunk : 幹の要素 branch : 枝の要素 returns : When::Coordinates::Pair
# File when.rb, line 365
365: def Pair(pair, branch=nil)
366: return Coordinates::Pair._force_pair(pair, branch)
367: end
When::TM::TemporalPosition の生成
specification : String or [String, Integer], Numeric, ...
String - 年号
[String, Integer] * 年号と 0 年の通年
以上省略可
Numeric - 年月日時分秒(途中で打ち切り可)
options : Hash (暦法や時法などの指定)
:validate => Boolean
true - 日時が存在することを確認する(デフォルト)
false - 日時が存在することを確認しない
see also When::TM::TemporalPosition._instance
returns : When::TM::TemporalPosition
options[:validate] が true(または指定なし)で、日時が存在しない場合は ArgumentError を発生する
# File when.rb, line 152
152: def TemporalPosition(*args)
153: # 引数の解釈
154: options = args[1].kind_of?(Hash) ? args.pop.dup : {}
155: validate = options.delete(:validate)
156: validate = true if validate == nil
157: options[:frame] ||= 'Gregorian'
158: options[:frame] = IRI(options[:frame], '_c:') if options[:frame].kind_of?(String)
159: options[:era_name] = args.shift if args[0].kind_of?(String) || args[0].kind_of?(Array)
160:
161: # 時間位置の生成
162: date = Array.new(options[:frame].indices.length+1) {args.shift}
163: if (args.length > 0)
164: options[:clock] ||= TM::Clock.local_time || utc
165: time = Array.new(options[:clock].indices.length) {args.shift}
166: position = TM::DateAndTime.new(date, time.unshift(0), options)
167: else
168: position = TM::CalDate.new(date, options)
169: end
170: return position unless validate
171:
172: # 時間位置の存在確認
173: date[0] = -date[0] if position.calendar_era_name && position.calendar_era_name[2] # 紀元前
174: date.each_index do |i|
175: break unless date[i]
176: raise ArgumentError, "Specified date not found: #{date}" unless Coordinates::Pair._force_pair(date[i]) ==
177: Coordinates::Pair._force_pair(position.cal_date[i])
178: end
179: return position unless time
180: time.each_index do |i|
181: break unless time[i]
182: return nil unless Coordinates::Pair._force_pair(time[i]) ==
183: Coordinates::Pair._force_pair(position.clk_time.clk_time[i])
184: end
185: return position
186: end
現在日時に対応する When::TM::TemporalPosition を取得する When::TM::DateAndTime of now
メソッド実行時の「現在日時」である。@indeterminated_position は設定しないので、 自動的に日時が進むことはない options : 暦法や時法などの指定
see When::TM::TemporalPosition._instance
returns : When::TM::DateAndTime or When::TM::CalDate
# File when.rb, line 198
198: def now(options={})
199: options = options._attr if options.kind_of?(TM::TemporalPosition)
200: options[:frame] ||= 'Gregorian'
201: options[:frame] = IRI(options[:frame], '_c:') if options[:frame].kind_of?(String)
202: clock = options[:clock] || TM::Clock.local_time || utc
203: jdt = TM::JulianDate.new(Time.now.to_f * TM::IntervalLength::SECOND, {:frame=>clock})
204: options[:clock] = jdt.frame
205: date = options[:frame].jul_trans(jdt, options)
206: date = TM::CalDate.new(date.cal_date, options) if options[:precision] &&
207: options[:precision] <= Coordinates::DAY
208: return date
209: end
Initializations
options : Hash
:alias => Locale の読替パターン ({読替前のlocale=>読替後のlocale})
:order => CalendarEra の検索順序 ([String of IRI])
:local => デフォルトの地方時 (When::TM::Clock or When::V::Timezone)
:format => strftime で用いる記号の定義 ({記号=>[書式,項目名] or 記号列}
:until => V::Event::Enumerator の until (When::TM::IntervalLength)
:leap_seconds => 閏秒の挿入記録 ([[JD, TAI-UTC, (MJD, OFFSET)]])
# File when.rb, line 379
379: def setup(options={})
380: Parts::IRI.setup
381: Parts::Locale.setup(options[:alias])
382: TM::CalendarEra.setup(options[:order])
383: TM::Clock.setup(options[:local])
384: TM::TemporalPosition.setup(options[:format])
385: V::Event.setup(options[:until])
386: V::Timezone.setup
387: Ephemeris::TimeStandard.setup(options[:leap_seconds])
388: end
本日に対応する When::TM::CalDate を取得する When::TM::CalDate of today
メソッド実行時の「本日」である。@indeterminated_position は設定しないので、 自動的に日時が進むことはない options : 暦法や時法などの指定
see When::TM::TemporalPosition._instance
returns : When::TM::CalDate
# File when.rb, line 221
221: def today(options={})
222: now(options.merge({:precision=>Coordinates::DAY}))
223: end
When::CalendarTypes::UTC の生成/参照
# File when.rb, line 320
320: def utc
321: Parts::IRI._instance("_c:UTC")
322: end
Generation of Temporal Objetct, duration or When::Parts::GeometricComplex
specification :
String - When Standard Representation として解釈して生成する
Numeric - ユリウス日として解釈して生成する
Array - 要素を個別に解釈して生成したオブジェクトのArrayを返す
When::TM::TemporalPosition - 処理を行わず、そのまま返す
When::Parts::GeometricComplex - 処理を行わず、そのまま返す
options : 暦法や時法などの指定
see When::TM::TemporalPosition._instance
returns : Temporal Objetct, duration or When::Parts::GeometricComplex
# File when.rb, line 112
112: def when?(specification, options={})
113:
114: # フォーマットごとの処理
115: case specification
116: when TM::TemporalPosition, Parts::GeometricComplex
117: return specification
118:
119: when Numeric
120: return TM::JulianDate.new((+specification - (TM::JulianDate::JD19700101-0.5))*TM::IntervalLength::DAY,
121: TM::TemporalPosition._options(options))
122:
123: when Array
124: options = TM::TemporalPosition._options(options)
125: return specification.map {|e| when?(e, options)}
126:
127: when String
128: return when?(specification.split(/[\n\r]+/), options) if specification =~ /[\n\r]+/
129: return TM::TemporalPosition._instance(specification, options)
130:
131: else
132: return nil
133: end
134: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.