Class: When::TM::TemporalPosition

Inherits:
Object
  • Object
show all
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

CalDate, ClockTime, Coordinate, OrdinalPosition

Defined Under Namespace

Modules: Conversion

Constant Summary collapse

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::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 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 included from Parts::Resource

#child, #keys, #locale, #namespace

Class Method Summary collapse

Instance Method Summary collapse

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

Methods included from Conversion

#julian_date, #tm_pos

Methods included from Parts::Resource

base_uri, #each, #enum_for, #hierarchy, #included?, #iri, #leaf?, #m17n, #map, #parent, #registered?, root_dir

Methods included from Parts::Resource::Pool

#[]=, #_setup_

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object (private)

Note:

When::TM::TemporalPosition で定義されていないメソッドは 処理を @frame(class: When::TM::Calendar or When::TM::Clock) または to_date_or_datetime(class: ::Date or ::DateTime) に委譲する

その他のメソッド



1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
# File 'lib/when_exe/tmposition.rb', line 1225

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

#eventsArray<When::Parts::Enumerator>

この時間位置と関連付けられたイベント - additional attribute



232
233
234
# File 'lib/when_exe/tmposition.rb', line 232

def events
  @events
end

#frameWhen::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_positionWhen::TM::IndeterminateValue (readonly) Also known as: indeterminatedPosition

この時間位置の意味づけ



217
218
219
# File 'lib/when_exe/tmposition.rb', line 217

def indeterminated_position
  @indeterminated_position
end

#locationWhen::Coordinates::Spatial

その他の属性 - additional attribute



265
266
267
# File 'lib/when_exe/tmposition.rb', line 265

def location
  @location
end

#optionsHash (readonly)

その他の属性 - additional attribute

Returns:

  • (Hash)

    { String=>Object }



247
248
249
# File 'lib/when_exe/tmposition.rb', line 247

def options
  @options
end

#precisionNumeric

Note:

precision より resolution の方が分解能の意味にふさわしいが ISO19108 で別の意味に用いられているため resolution とした。

この時間位置の分解能 - additional attribute

Returns:



241
242
243
# File 'lib/when_exe/tmposition.rb', line 241

def precision
  @precision
end

#queryHash

その他の属性 - additional attribute

Returns:

  • (Hash)

    { String=>When::BasicTypes::M17n }



259
260
261
# File 'lib/when_exe/tmposition.rb', line 259

def query
  @query
end

#transHash

その他の属性 - additional attribute

Returns:

  • (Hash)

    { String=>Object }



253
254
255
# File 'lib/when_exe/tmposition.rb', line 253

def trans
  @trans
end

Class Method Details

._instance(specification, options = {}) ⇒ When::TM::TemporalPosition, ...

Note:

options の中身は本メソッドによって更新されることがある。

Note:

:tz は 'Asia/Tokyo'など時間帯を表す文字列をキーにして、登録済みのWhen::V::Timezone, When::Parts::Timezoneを検索して使用する。 :clock はWhen::Parts::Timezone::Baseオブジェクトをそのまま使用するか '+09:00'などの文字列をWhen::TM::Clock化して使用する。 :tz の方が :clock よりも優先される。

Temporal Objetct の生成

Parameters:

  • specification (String)

    When.exe Standard Representation

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

    下記の通り

Options Hash (options):

  • :frame (When::TM::ReferenceSystem)

    暦法の指定

  • :clock (When::Parts::Timezone::Base, String)

    時法の指定

  • :tz (String)

    時法の指定(時間帯を指定する場合 :clock の替わりに用いることができる)

  • :abbr (Array<Numeric>)

    ISO8601上位省略形式のためのデフォルト日付(省略時 指定なし)

  • :extra_year_digits (Integer)

    ISO8601拡大表記のための年の構成要素拡大桁数(省略時 1桁)

  • :ordinal_date_digits (Integer)

    ISO8601拡大表記の年内通日の桁数(省略時 3桁)

  • :wkst (String)

    ISO8601週日形式のための暦週開始曜日(省略時 'MO')

  • :precision (Integer)

    生成するオブジェクトの分解能

  • :time_standard (When::TimeStandard::TimeStandard)

    時刻系の指定(省略時 When::TimeStandard::UnversalTime)

  • :location (When::Ephemeris::Spatial)

    観測地の指定(省略時 指定なし)

  • :era_name (String)

    暦年代

  • :trans (Hash)

    暦年代の上下限

    • :count => 条件に合致する暦年代のうち何番目を採用するか

    • :lower => 暦年代適用の下限

      true            - epoch_of_use の始め(省略時)
      :reference_date - 参照事象の日付
      
    • :upper => 暦年代適用の上限

      true            - epoch_of_use の終わり(省略時)
      :reference_date - 参照事象の日付
      
  • :query (Hash)

    暦年代の絞込み条件

    • :area => area による暦年代絞込み

    • :period => period による暦年代絞込み

    • :name => name による暦年代絞込み(epoch の attribute使用可)

Returns:



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
# File 'lib/when_exe/tmposition.rb', line 310

def _instance(specification, options={})

  # prefix - RFC 5545 Options
  iso8601form = When::Parts::Resource::ContentLine.extract_rfc5545_Property(specification, options).
                gsub(When::Parts::Resource::IRIDecode) {|c| When::Parts::Resource::IRIDecodeTable[c]}

  # delayed_options
  delayed_options = {}

  # Frame specifications - 暦法指定の取り出し
  if iso8601form =~ /\A(.*[^\d]|.+=[^:]+)\((([-+*&%@!>=<?\d.A-Z:]|\{.+?\})+)\)\z/
    frame, iso8601form = $~[1..2]
    frame.sub!(/_+\z/, '')
  else
    iso8601form, frame, *rest = iso8601form.split(/(?:\^|%5E){1,2}/i)
    delayed_options[:frame] = rest.map{|calendar| When.Resource(calendar, '_c:')} unless rest.empty?
  end

  # add frame to options
  options = options.merge({:frame=>When.Resource(frame, '_c:')}) if frame

  return _instance_element(iso8601form, options, delayed_options) unless iso8601form =~ /\A(.+?)(\.{2,3})(.+)\z/
  first, separater, last = $1, $2, $3
  When::Events::Range.new(_instance_element(first, options.dup, delayed_options.dup),
                          _instance_element(last,  options.dup, delayed_options.dup), separater == '...')
end

._instance_element(iso8601form, options, delayed_options) ⇒ Object



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
# File 'lib/when_exe/tmposition.rb', line 337

def _instance_element(iso8601form, options, delayed_options)

  # indeterminateValue
  if (iso8601form.sub!(/\/After\z|\ABefore\/|\ANow\z|\AUnknown\z|\A[-+]Infinity\z/i, ''))
    options[:indeterminated_position] = When::TimeValue::S[$&.sub('/','')]
    case options[:indeterminated_position]
    when When::TimeValue::Now,
         When::TimeValue::Unknown,
         When::TimeValue::Max,
         When::TimeValue::Min
      return self.new(self._options(options))
    end
  end

  # each specification - '/' で区切られた個々の要素の取り出し
  splitted = iso8601form.gsub(/\{.+?\}/) {|m| m.gsub('/', When::Locale::NUL)}.split('/').map {|m| m.gsub(When::Locale::NUL, '/')}
  if (splitted[0] =~ /\AR(\d+)?(P.+)?\z/)
    repeat = $1 ? $1.to_i : true
    delayed_options[:duration] = When.Duration($2) if $2
    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
  options = self._options(options)
  element = splitted.map { |v|
    d, r, z2 = _date_time_or_duration(v, options.dup)
    delayed_options[:residue] = r  if r
    delayed_options[:clock  ] = z2 if z2
    d
  }

  # 繰り返しの起点と間隔
  base      = element[0].kind_of?(Duration) ? element[1] : element[0]
  frame_len = (base.respond_to?(:frame) ? base.frame : When::Gregorian).indices.length
  duration  = _duration_for_repeat(element)

  # 意味のある繰り返しのない場合
  has_residue_options = delayed_options[:residue] && (delayed_options[:residue][frame_len-2].kind_of?(String) ||
                                                      delayed_options[:residue][frame_len].kind_of?(String))
  case repeat
  when nil ; return _instance_without_repeat(element).apply_delayed_options(delayed_options) unless has_residue_options
  when 0   ; return []
  when Integer
    return [element[0]] * repeat if element.length == 1 && element[0].kind_of?(When::TM::Duration) # JIS X0301 5.6.3
    raise ArgumentError, "Duration or TemporalPosition missing" unless element[1] || has_residue_options
  end

  # 繰り返しのある場合
  if repeat.kind_of?(Integer) && !has_residue_options

    # iCalendar の機能を使用しない
    result = []
    seed   = base
    guard  = (base - When::V::Event.default_until)...(base + When::V::Event.default_until)
    count = 0
    while result.length < repeat && seed >= guard.first && seed < guard.last
      applied = seed.apply_delayed_options(delayed_options)
      applied = When::Parts::GeometricComplex.new(applied, delayed_options[:duration]) if delayed_options[:duration]
      result << applied if applied
      count += 1
      seed = base + duration * count
    end
    result.reverse! if duration.sign < 0
    return result

  else

    return duration.set_repeat(true) unless base

    # iCalendar の機能を使用する
    should_limit = base.precision == When::MONTH &&
                 !(delayed_options[:residue] && delayed_options[:residue][frame_len-2])
    iterator = When::V::Event.iterator_for_ISO8601(base, duration, delayed_options)
    case repeat
    when nil     ; (result=iterator.succ).precision > base.precision && should_limit && base != result ? nil : result
    when Integer ; (0...repeat).to_a.map {iterator.succ}
    else         ; iterator
    end
  end
end

._setup_(format = nil) ⇒ void

Note:

format の指定がない場合、format は Format(モジュール定数)と解釈する

This method returns an undefined value.

When::TM::TemporalPosition Class のグローバルな設定を行う

Parameters:

  • format (Hash) (defaults to: nil)

    strftime で用いる記号の定義



329
330
331
# File 'lib/when_exe/inspect.rb', line 329

def _setup_(format=nil)
  @format = format ? Format.merge(format) : Format
end

._setup_infoHash

設定情報を取得する

Returns:

  • (Hash)

    設定情報



337
338
339
# File 'lib/when_exe/inspect.rb', line 337

def _setup_info
  {:format => format}
end

._temporal_position(*args) ⇒ Object

When::TM::TemporalPosition の生成



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
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
498
499
500
# File 'lib/when_exe/tmposition.rb', line 430

def _temporal_position(*args)
  # 引数の解釈
  options  = args[-1].kind_of?(Hash) ? args.pop.dup : {}
  validate = options.delete(:invalid)
  options  = TemporalPosition._options(options)
  options[:frame]  ||= 'Gregorian'
  options[:frame]    = When.Resource(options[:frame], '_c:') if options[:frame].kind_of?(String)
  frame_len = options[:frame].indices.length
  case args[0]
  when String
    options[:era_name]    = When::EncodingConversion.to_internal_encoding(args.shift)
  when Array
    options[:era_name]    = args.shift
    options[:era_name][0] = When::EncodingConversion.to_internal_encoding(options[:era_name][0])
  end

  # 時間位置の生成
  res   = []
  abbrs = Array(options[:abbr])
  date  = Array.new(frame_len-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
  }
  parse = options.delete(:parse)
  if parse && parse[:residue] && parse[:residue][frame_len]
    res << parse[:residue][frame_len]
  end
  if args.length > 0
    options[:clock] ||= Clock.local_time
    options[:clock]   = When.Clock(options[:clock])
    time = Array.new(options[:clock].indices.length) {args.shift}
    position = DateAndTime.new(date, time.unshift(0), options)
  else
    position = CalDate.new(date, options)
  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

.formatObject

strftime で用いる書式のハッシュ



342
343
344
# File 'lib/when_exe/inspect.rb', line 342

def format
  @format ||= Format
end

Instance Method Details

#+(other) ⇒ When::TM::TemporalPosition

加算

Parameters:

  • other (Numeric, When::TM::Duration)

Returns:



837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
# File 'lib/when_exe/tmposition.rb', line 837

def +(other)
  case other
  when Integer  ; return self + PeriodDuration.new(other, When::DAY)
  when Numeric  ; return self + IntervalLength.new(other, 'day')
  when Duration ; begin other = other.set_repeat(false); return other.enum_for(self+other, :forward) end if other.repeat
  when Array    ; return other.map {|o| self + o}
  else          ; raise TypeError, "The right operand should be Numeric or Duration"
  end
  return _plus(other) if other.kind_of?(PeriodDuration)
  options = self._attr
  time    = dynamical_time + other.duration
  @frame.kind_of?(Calendar) ? @frame.jul_trans(JulianDate.dynamical_time(time, {:time_standard=>options[:time_standard]}), options) :
                                               JulianDate.dynamical_time(time,  options)
rescue RangeError
  (@frame ^ self) + other
end

#+@Float

ユリウス日時(実数)

Returns:

  • (Float)

    dynamical time での経過日数を, ユリウス日と1970-01-01T00:00:00TTで時計あわせしたもの



766
767
768
# File 'lib/when_exe/tmposition.rb', line 766

def +@
  JulianDate._t_to_d(dynamical_time)
end

#-(other) ⇒ When::TM::TemporalPosition, When::TM::Duration

減算

Parameters:

Returns:

  • (When::TM::TemporalPosition)

    if other is a Numeric or When::TM::Duration

  • (When::TM::Duration)

    if other is a When::TM::TemporalPosition



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

def -(other)
  case other
  when TimeValue; return 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  ; return self - PeriodDuration.new(other, When::DAY)
  when Numeric  ; return self - IntervalLength.new(other, 'day')
  when Duration ; begin other = other.set_repeat(false); return other.enum_for(self-other, :reverse) end if other.repeat
  when Array    ; return other.map {|o| self - o}
  else          ; raise TypeError, "The right operand should be Numeric, Duration or TemporalPosition"
  end
  return _plus(-other) if other.kind_of?(PeriodDuration)
  options = self._attr
  time    = dynamical_time - other.duration
  @frame.kind_of?(Calendar) ? @frame.jul_trans(JulianDate.dynamical_time(time, {:time_standard=>options[:time_standard]}), options) :
                                               JulianDate.dynamical_time(time,  options)
rescue RangeError
  (@frame ^ self) - other
end

#<=>(other) ⇒ Integer

大小比較

Parameters:

  • other (When::TM::TemporalPosition)

    チェックされる日時

  • other (Numeric)

    チェックされる日時の universal time(self と同じtime_standardとみなす)

Returns:

  • (Integer)

    (-1, 0, 1)

    分解能の低い方にあわせて比較を行う

    Ex. when?('2011-03') <=> when?('2011-03-10') -> 0
    


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
995
996
997
998
999
1000
# File 'lib/when_exe/tmposition.rb', line 961

def <=>(other)
  other = other.first if other.kind_of?(Range)
  return universal_time <=> other unless other.respond_to?(:indeterminated_position)

  [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]
  elsif prec < DAY && precision < other.precision
    return +1 if other.to_i <  self.to_i
    return -1 if other.to_i >= succ.to_i
    return  0
  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

オブジェクトの同値

Parameters:

  • other (比較先)

Returns:

  • (Boolean)
    true - 同値
    false - 非同値


944
945
946
947
948
# File 'lib/when_exe/tmposition.rb', line 944

def ==(other)
  (self <=> other) == 0
rescue
  false
end

#[](index) ⇒ Numeric

要素の参照

Parameters:

  • index (Integer, String)

    参照する要素の指定

Returns:



826
827
828
829
# File 'lib/when_exe/tmposition.rb', line 826

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, ...

条件を満たすオブジェクトの抽出

Parameters:

Returns:

  • (Array of (element^self) for all When::Parts::Resource registered elements)

    (If other is Module)

  • (Array of (self^element) for elemnt of other which belong to the specified module or class)

    (If other is [Array])

  • (Enumerator which generates temporal position sequence begins from self with the specified duration)

    (If other is [When::TM::Duration])

  • (Array of temporal position using the specified calendar as a frame)

    (If other is [When::TM::Calendar])

  • (Array of temporal position using the specified calendar era as a calendarEraName)

    (If other is [When::TM::CalendarEra])



1063
1064
1065
# File 'lib/when_exe/tmposition.rb', line 1063

def ^(other, leaf=true, &block)
  scan(other, leaf, &block)
end

#_notes(options = {}) ⇒ Array<Array<Hash{:note=>note, :value=>value}>>

Note:

When::TM::TemporalPosition の場合、events に暦注名の入ったその暦注に該当する日付である。 (例) Christian クラス で easter を計算した場合、当該年の復活祭の日付オブジェクトが返る。 暦注サブクラスの場合、要素が増えたり、:note の暦注要素の型が変わったりすることがある。

時間位置オブジェクトの暦注を取得

Parameters:

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

    { :notes => String } という Hash の指定と等価

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

    { :indices => Integer } という Hash の指定と等価

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

    下記のとおり

Options Hash (options):

Returns:

  • (Array<Array<Hash{:note=>note, :value=>value}>>)
    note [String, When::BasicTypes::M17n, When::Coordinates::Residue

    暦注名 ]

    value [String, When::BasicTypes::M17n, When::Coordinates::Residue, When::TM::TemporalPosition

    暦注の値 ]



628
629
630
# File 'lib/when_exe/inspect.rb', line 628

def _notes(options={})
  _calendar_note(options).notes(self, options)
end

#_to_h(options = {}) ⇒ Hash

時間位置オブジェクトの内容を Hash 化

Parameters:

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

    { :notes => String } という Hash の指定と等価

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

    { :indices => Integer } という Hash の指定と等価

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

    下記のとおり

Options Hash (options):

Returns:

  • (Hash)
    • :sdn 日の通し番号 - ユリウス通日(Integer)

    • :calendar calendar_name の結果 - Array<暦法または暦年代(, 付属情報..)>

    • :notes Hash (の Array (の Array)) - _notes(options)

    clock が定義されている場合、さらに下記も出力する

    • :clock 時計(When::Parts::Timezone::Base)

    • :clk_time to_clock_time の結果 - ( 日, 時, 分, 秒 )

    • :dynamical dynamical_time / 秒

    • :universal universal_time / 秒



694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
# File 'lib/when_exe/inspect.rb', line 694

def _to_h(options={})
  hash = super.update({
    :sdn      => to_i,
    :calendar => calendar_name,
    :notes    => _notes(options)
  })

  hash.update({
    :clock     => clock,
    :clk_time  => to_clock_time,
    :dynamical => dynamical_time * clock.second,
    :universal => universal_time * clock.second
  }) if clock
  hash
end

#apply_delayed_options(options) ⇒ When::TM::TemporalPosition

オブジェクト変換オプションの遅延適用

Parameters:

  • options (Hash)

    以下の通り

Options Hash (options):

Returns:



1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
# File 'lib/when_exe/tmposition.rb', line 1076

def apply_delayed_options(options)
  position  = self
  frame_len = frame.indices.length
  if options[:residue]
    options[:residue].keys.sort.each do |count|
      options[:residue][count] = When.Residue(options[:residue][count]) unless options[:residue][count].kind_of?(When::Coordinates::Residue)
      residue = options[:residue][count]
      if count == frame_len - 2
        residue   = residue.to('year')
        position &= residue
      else
        upper     = position
        position  = position.succ if residue.carry < 0
        position &= residue
        return nil if self.precision == When::MONTH && !(upper == position)
      end
    end
  end
  if options[:clock]
    position = options[:clock] ^ position
  end
  if options[:frame]
    position = options[:frame].inject(position) {|p,c| c.jul_trans(p)}
  end
  position
end

#calendar_nameArray<Class>

暦法名

Returns:

  • (Array<Class>)

    Class 暦法のクラスオブジェクト



360
361
362
# File 'lib/when_exe/inspect.rb', line 360

def calendar_name
  [self.class]
end

#clock_name(prefix = true) ⇒ Array<String>

時法名

Parameters:

  • prefix (Boolean) (defaults to: true)

    true ならIRI の先頭部分を簡約表現にする

Returns:



370
371
372
# File 'lib/when_exe/inspect.rb', line 370

def clock_name(prefix=true)
  [clock.iri(prefix)]
end

#copy(options = {}) ⇒ When::TM::TemporalPosition

属性を変更したコピーを作る

Parameters:

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

    { 属性=>属性値 }

Returns:



1109
1110
1111
1112
1113
# File 'lib/when_exe/tmposition.rb', line 1109

def copy(options={})
  position = self.dup
  position._copy(options)
  position
end

#dynamical_timeNumeric

外部時間

Returns:

  • (Numeric)

    1970-01-01T00:00:00TT からの terrestrial time の経過時間 / 128秒



714
715
716
717
718
719
720
721
722
# File 'lib/when_exe/tmposition.rb', line 714

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

下位桁の切り捨て

Parameters:

  • digit (Integer) (defaults to: DAY)

    これより下の桁を切り捨てる(省略すると When::DAY)

  • precision (Integer) (defaults to: digit)

    切り捨て結果の分解能

Returns:



911
912
913
# File 'lib/when_exe/tmposition.rb', line 911

def floor(digit=DAY, precision=digit)
  self
end

#has_next?Boolean

前後の日時を取得可能か?

Returns:

  • (Boolean)
    true - 可能
    false - 不可


899
900
901
# File 'lib/when_exe/tmposition.rb', line 899

def has_next?
  When::Coordinates::PERIOD_NAME[@precision] != nil
end

#has_time?Boolean

分解能が時刻を持つか

Returns:

  • (Boolean)


919
920
921
# File 'lib/when_exe/tmposition.rb', line 919

def has_time?
  (@precision > DAY)
end

#include?(date) ⇒ Boolean

指定の日時を含むか?

Parameters:

Returns:

  • (Boolean)
    true - 含む
    false - 含まない


931
932
933
934
# File 'lib/when_exe/tmposition.rb', line 931

def include?(date)
  return false if self.precision > date.precision
  return self == date
end

#inspectString

When::TM::TemporalPosition オブジェクトを分かりやすい文字列にして返します

Returns:



351
352
353
# File 'lib/when_exe/inspect.rb', line 351

def inspect
  When::EncodingConversion.to_external_encoding(to_s)
end

#is?(event = nil, options = {}) ⇒ Boolean

指定の日時が指定イベントに該当するか?

Parameters:

  • event (String) (defaults to: nil)

    options=:notes=>String または :notes=>String または :value=>String という指定と等価 (指定の event が存在する場合は前者、指定の notes が存在する場合は中央、しない場合は後者)

  • event (Integer) (defaults to: nil)

    options={ :indices=> Integer } という指定と等価

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

    下記のとおり

Options Hash (options):

Returns:

  • (Boolean)
    true - 該当する
    false - 該当しない


666
667
668
669
670
671
672
673
# File 'lib/when_exe/inspect.rb', line 666

def is?(*args)
  options = args.last.kind_of?(Hash) ? args.pop.dup : {}
  note    = _calendar_note(options)
  event   = args.first || options.delete(:event) || note.event
  return note.note?(self, options) unless options.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, ...

Note:

引数 ord, wkst, opt はそのクラスで位置づけを判断するため、引数の順序は任意(省略も可)

含まれる月

Parameters:

  • ord (Numeric, Range)

    月の番号(default: 今月) 今月を 0 とする月番号(Integer) または月番号の範囲(Range)

    -1 - 先月
     0 - 今月
    +1 - 来月
    
  • wkst (String)

    週の開始曜日(defaultはなし)

  • wkst (When::CalendarNote)

    暦注オブジェクト

  • wkst (Array<When::CalendarNote, String>)

    暦注オブジェクトとそのイベントメソッド名 (暦注オブジェクトは、そのIRI文字列を指定しても良い)

  • opt (Hash)

    下記の通り

  • block (Block)

Options Hash (opt):

  • :Range (Range)

    上位繰り返し範囲(ユリウス通日…ユリウス通日)

Returns:

  • (Range)

    含まれる月を範囲として表現する Range (block 指定なし)

  • (Array)

    含まれる月の各日をブロックに渡した結果の Array (block 指定あり, wkst なし)

  • (Array<Array>)

    含まれる月の各日をブロックに渡した結果の 七曜表(block 指定あり, wkst あり)



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
# File 'lib/when_exe/inspect.rb', line 439

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 不一致

Parameters:

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

    { :notes => String } または { :value => String } という Hash の指定と等価 (指定の notes が存在する場合は前者、しない場合は後者)

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

    { :indices => Integer } という Hash の指定と等価

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

    下記のとおり

Options Hash (options):

Returns:

  • (Boolean)
    true - 暦注が一致
    false - 暦注が不一致


646
647
648
# File 'lib/when_exe/inspect.rb', line 646

def note?(options={})
  _calendar_note(options).note?(self, options)
end

#notes(options = {}) ⇒ Array<Array<Hash{:note=>note, :value=>value}>>

時間位置オブジェクトの暦注を取得し value を暦注の値 (String, When::BasicTypes::M17n or When::Coordinates::Residue)とする Hash で表現

Parameters:

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

    { :notes => String } という Hash の指定と等価

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

    { :indices => Integer } という Hash の指定と等価

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

    下記のとおり

Options Hash (options):

Returns:

  • (Array<Array<Hash{:note=>note, :value=>value}>>)
    note [String, When::BasicTypes::M17n

    暦注名 ]

    value [String, When::BasicTypes::M17n, When::Coordinates::Residue

    暦注の値 ]



601
602
603
604
605
606
607
608
# File 'lib/when_exe/inspect.rb', line 601

def notes(options={})
  form_options = options.kind_of?(Hash) ? options : {}
  form_options[:method] = :to_m17n unless form_options.key?(:method)
  persistence = options.delete(:persistence) if options.kind_of?(Hash)
  retrieved   = When::CalendarNote::NotesContainer.retrieve(persistence, self.to_i)
  return retrieved if retrieved
  When::CalendarNote::NotesContainer.register(_m17n_form(_notes(options), form_options), persistence, self.to_i)
end

#periodWhen::TM::PeriodDuration

分解能に対応する Duration

Returns:

Raises:

  • (ArgumentError)


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

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

#rate_of_clockNumeric

時間の歩度

Returns:



686
687
688
# File 'lib/when_exe/tmposition.rb', line 686

def rate_of_clock
  time_standard.rate_of_clock
end

#reference_labelWhen::BasicTypes::M17n

参照ラベル



379
380
381
# File 'lib/when_exe/inspect.rb', line 379

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, ...

条件を満たすオブジェクトの抽出

Parameters:

Returns:

  • (Array of (element^self) for all When::Parts::Resource registered elements)

    (If other is Module)

  • (Array of (self^element) for elemnt of other which belong to the specified module or class)

    (If other is [Array])

  • (Enumerator which generates temporal position sequence begins from self with the specified duration)

    (If other is [When::TM::Duration])

  • (Array of temporal position using the specified calendar as a frame)

    (If other is [When::TM::Calendar])

  • (Array of temporal position using the specified calendar era as a calendarEraName)

    (If other is [When::TM::CalendarEra])



1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
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
1052
1053
1054
1055
1056
# File 'lib/when_exe/tmposition.rb', line 1014

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(format = @frame.strftime, locale = nil) ⇒ When::BasicTypes::M17n

指定の書式による多言語対応文字列化 - format で指定した書式で多言語対応文字列化する

Parameters:

  • format (When::BasicTypes::M17n) (defaults to: @frame.strftime)

    書式

  • locale (String, Array<String>) (defaults to: nil)

    文字列化を行う locale の指定(デフォルト : オブジェクト生成時に保持している locale すべて)

Returns:



717
718
719
720
721
722
# File 'lib/when_exe/inspect.rb', line 717

def strftime(format=@frame.strftime, locale=nil)
  format = m17n([format]*self.keys.length, nil, nil, {:locale=>self.keys}) if format.instance_of?(String)
  format._printf([], locale) do |k, *t|
    _strftime(k, format, [''])
  end
end

#time_standardWhen::TimeStandard

時刻系

Returns:



674
675
676
677
678
679
680
# File 'lib/when_exe/tmposition.rb', line 674

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_timeWhen::TM::ClokTime

When::TM::ClockTime オブジェクトへの変換

Returns:

  • (When::TM::ClokTime)

Raises:

  • (TypeError)


774
775
776
777
778
779
# File 'lib/when_exe/tmposition.rb', line 774

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(start = _default_start, option = {}) ⇒ ::Date Also known as: to_date_or_datetime

標準ライブラリの Date オブジェクトへの変換

Parameters:

  • start (Integer) (defaults to: _default_start)

    ::DateTime オブジェクトのグレゴリオ改暦日(ユリウス通日)

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

    時間の歩度が1.0でない場合のための option see _instance

Returns:



806
807
808
809
# File 'lib/when_exe/tmposition.rb', line 806

def to_date(start=_default_start, option={})
  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(start = _default_start, option = {:frame=>When::UTC}) ⇒ ::DateTime

標準ライブラリの DateTime オブジェクトへの変換

Parameters:

  • start (Integer) (defaults to: _default_start)

    ::DateTime オブジェクトのグレゴリオ改暦日(ユリウス通日)

  • option (Hash) (defaults to: {:frame=>When::UTC})

    時間の歩度が1.0でない場合のための option see _instance

Returns:

  • (::DateTime)

Raises:

  • (TypeError)


789
790
791
792
793
794
795
796
# File 'lib/when_exe/tmposition.rb', line 789

def to_datetime(start=_default_start, option={:frame=>When::UTC})
  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_fFloat

ユリウス日時(実数)

Returns:

  • (Float)

    universal time での経過日数を, ユリウス日と1970-01-01T00:00:00Zで時計あわせしたもの



730
731
732
# File 'lib/when_exe/tmposition.rb', line 730

def to_f
  JulianDate._t_to_d(universal_time)
end

#to_iInteger

ユリウス日(整数)

Returns:

  • (Integer)

    -4712-01-01T12:00:00Z からの経過日数に対応する通番(当該時間帯での午前0時に1進める)



740
741
742
743
744
745
# File 'lib/when_exe/tmposition.rb', line 740

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_m17nWhen::BasicTypes::M17n

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



730
731
732
733
# File 'lib/when_exe/inspect.rb', line 730

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

剰余類化

Parameters:

  • remainder (Numeric)

    剰余

  • divisor (Integer)

    法(>0)

Returns:



756
757
758
# File 'lib/when_exe/tmposition.rb', line 756

def to_residue(remainder, divisor)
  When::Coordinates::Residue.new(remainder, divisor, {'day'=>to_i})
end

#to_sString

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

Returns:



743
744
745
# File 'lib/when_exe/inspect.rb', line 743

def to_s(*args)
  to_m17n(*args).to_s
end

#to_time::Time

組み込みライブラリの Time オブジェクトへの変換

Returns:



816
817
818
# File 'lib/when_exe/tmposition.rb', line 816

def to_time
  time_standard.to_time_object(universal_time)
end

#to_uriString

URI要素化 - URI表現の要素として用いる形式に変換

Returns:



753
754
755
# File 'lib/when_exe/inspect.rb', line 753

def to_uri(*args)
  _to_uri(to_s(*args))
end

#to_uri_escapeString

URI要素化 - URI表現の要素として用いる形式に変換(“^”はエスケープ)

Returns:



763
764
765
# File 'lib/when_exe/inspect.rb', line 763

def to_uri_escape(*args)
  _to_uri(to_s(*args)).gsub('^', '%5E')
end

#universal_timeNumeric Also known as: local_time

内部時間

Returns:

  • (Numeric)

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

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



698
699
700
701
702
703
704
705
# File 'lib/when_exe/tmposition.rb', line 698

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

Note:

引数 ord, wkst, opt はそのクラスで位置づけを判断するため、引数の順序は任意(省略も可)

含まれる週

Parameters:

  • ord (Numeric, Range)

    週の番号(default: 今週) 今週を 0 とする週番号(Integer) または週番号の範囲(Range)

    -1 - 先週
     0 - 今週
    +1 - 来週
    
  • wkst (String)

    週の開始曜日(defaultは 月曜)

  • wkst (When::CalendarNote)

    暦注オブジェクト

  • wkst (Array<When::CalendarNote, String>)

    暦注オブジェクトとそのイベントメソッド名 (暦注オブジェクトは、そのIRI文字列を指定しても良い)

  • opt (Hash)

    下記の通り

  • block (Block)

Options Hash (opt):

  • :Range (Range)

    上位繰り返し範囲(ユリウス通日…ユリウス通日)

Returns:

  • (Range)

    含まれる週を範囲として表現する Range (block 指定なし)

  • (Array)

    含まれる週の各日をブロックに渡した結果の Array (block 指定あり)



404
405
406
407
408
409
410
411
412
413
414
415
# File 'lib/when_exe/inspect.rb', line 404

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, ...

Note:

引数 ord, wkst, opt はそのクラスで位置づけを判断するため、引数の順序は任意(省略も可)

含まれる年

Parameters:

  • ord (Numeric, Range)

    年の番号(default: 今年) 今年を 0 とする年番号(Integer) または年番号の範囲(Range)

    -1 - 先年
     0 - 今年
    +1 - 来年
    
  • wkst (String)

    週の開始曜日(defaultはなし)

  • wkst (When::CalendarNote)

    暦注オブジェクト

  • wkst (Array<When::CalendarNote, String>)

    暦注オブジェクトとそのイベントメソッド名 (暦注オブジェクトは、そのIRI文字列を指定しても良い)

  • opt (Hash)

    下記の通り

  • block (Block)

Options Hash (opt):

  • :Range (Range)

    上位繰り返し範囲(ユリウス通日…ユリウス通日)

Returns:

  • (Range)

    含まれる年を範囲として表現する Range (block 指定なし)

  • (Array)

    含まれる年の各日をブロックに渡した結果の Array (block 指定あり, wkst なし)

  • (Array<Array>)

    含まれる年の各日をブロックに渡した結果の 七曜表(block 指定あり, wkst あり)



513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
# File 'lib/when_exe/inspect.rb', line 513

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