Class: When::TM::Calendar

Inherits:
ReferenceSystem show all
Includes:
Temporal, Coordinates
Defined in:
lib/when_exe/tmreference.rb

Overview

see gml schema

Constant Summary

Constants included from Coordinates

Coordinates::Bahai, Coordinates::CommonResidue, Coordinates::DefaultDateIndex, Coordinates::DefaultTimeIndex, Coordinates::IndianCities, Coordinates::Javanese, Coordinates::MATCH, Coordinates::Mayan, Coordinates::PERIOD, Coordinates::PERIOD_NAME, Coordinates::PRECISION, Coordinates::PRECISION_NAME, Coordinates::VALUE, Coordinates::Yi

Constants included from Parts::Resource

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

Instance Attribute Summary collapse

Attributes inherited from ReferenceSystem

#domain, #domain_of_validity, #position

Attributes inherited from BasicTypes::Object

#label

Attributes included from Parts::Resource

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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Coordinates

to_deg, to_dms

Methods inherited from ReferenceSystem

#name

Methods inherited from BasicTypes::Object

#tap

Methods included from Parts::Resource

#[], _extract_prefix, _instance, _parse, _path_with_prefix, #each, #enum_for, #hierarchy, #include?, #included?, #iri, #leaf?, #m17n, #map, #next, #parent, #prev, #registered?

Methods included from Parts::Resource::Pool

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

Methods included from Parts::Resource::Synchronize

#synchronize

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class When::Parts::Resource

Instance Attribute Details

#reference_frameArray<When::TM::CalendarEra> (readonly) Also known as: referenceFrame

Note:

マルチスレッド動作時 CalendarEra の生成で 本属性が更新される 参照・更新処理は synchronize { … } の … の部分に書く必要がある

この暦と関連付けられた暦年代 (relation - Basis)

The calendar eras associated with the calendar being described



115
116
117
# File 'lib/when_exe/tmreference.rb', line 115

def reference_frame
  @reference_frame
end

#time_basisArray<When::TM::Clock> (readonly) Also known as: timeBasis

一暦日の中の時間位置を定めるために、この暦とともに使用する時計 (relation - Resolution)

The clock that is used with this calendar to define temporal position within a calendar day

Returns:



125
126
127
# File 'lib/when_exe/tmreference.rb', line 125

def time_basis
  @time_basis
end

Class Method Details

._setup_void

This method returns an undefined value.

初期化



98
99
100
101
102
103
# File 'lib/when_exe/tmreference.rb', line 98

def self._setup_
  @_lock_ = Mutex.new if When.multi_thread
  @_lock_.lock if @_lock_
  @_pool  = {}
  @_lock_.unlock if @_lock_
end

Instance Method Details

#_new_month_(m) ⇒ Numeric

月初の通日

Parameters:

  • m (Integer)

    通月

Returns:



224
225
226
227
228
229
230
231
232
233
234
235
236
# File 'lib/when_exe/tmreference.rb', line 224

def _new_month_(m)
  date = @base.map {|d| d||0}
  if @indices[-2].unit
    date[-2] += m
    _coordinates_to_number(*_decode(date))
  else
    d0        = _coordinates_to_number(*_decode(date))
    date[-3] += (m * @mean_month / @mean_year).floor - 1
    d1        = _coordinates_to_number(*_decode(date))
    date[-2] += m - ((d1 - d0) / @mean_month + 0.5).floor
    _coordinates_to_number(*_decode(date))
  end
end

#_to_month_number_(sdn) ⇒ Array<Numeric>

通日 - > [通月,月内日数,月の日数]

Parameters:

  • sdn (Integer)

    通日

Returns:

  • (Array<Numeric>)

    ( m, d, n )

    m - 通月
    d - 月内の日数 (0 始まり)
    n - 月の日数


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

def _to_month_number_(sdn)
  Residue.mod(sdn) {|m| _new_month(m)}
end

#date_trans(cal_date, time = nil, options = {}) ⇒ When::TM::JulianDate Also known as: dateTrans

日付と時刻をユリウス日(When::TM::JulianDate)に変換する

Parameters:

Returns:



151
152
153
154
155
156
# File 'lib/when_exe/tmreference.rb', line 151

def date_trans(cal_date, time=nil, options={})
  time = cal_date.clk_time if ((time == nil) && cal_date.kind_of?(DateAndTime))
  frac = (time) ? time.universal_time : 0.0
  jdn  = to_julian_date(cal_date.cal_date)
  return JulianDate.universal_time((jdn - JulianDate::JD19700101) * Duration::DAY + frac, options)
end

#jul_trans(jdt, options = {}) ⇒ When::TM::CalDate, When::TM::CalDateAndTime Also known as: julTrans, ^

ユリウス日(When::TM::JulianDate)を日付に変換する

Parameters:

Returns:

  • (When::TM::CalDate)

    if (options[:clock or :tz] == nil)

  • (When::TM::CalDateAndTime)

    if (options[:clock or :tz] != nil)



167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
# File 'lib/when_exe/tmreference.rb', line 167

def jul_trans(jdt, options={})
  unless jdt.kind_of?(When::TimeValue)
    options[:clock] ||= @time_basis unless rate_of_clock == 1.0
    jdt = JulianDate.new(jdt, options)
  end
  cal_options = jdt._attr
  cal_options.delete(:era_name)
  cal_options.delete(:era)
  unless rate_of_clock == jdt.rate_of_clock
    cal_options.delete(:time_standard)
    cal_options[:clock] = @time_basis || When.utc
    jdt = JulianDate.dynamical_time(jdt.dynamical_time, {:time_standard=>time_standard})
  end
  cal_options.update(options)
  cal_options[:frame] = self
  cal_date     = to_cal_date(jdt.to_i)
  cal_date[0] -= cal_options[:era_name][1] if cal_options[:era_name]
  clock = @time_basis || Clock.get_clock_option(cal_options) || jdt.clock
  return CalDate.new(cal_date, cal_options) unless clock
  clock = When.Clock(clock)    if clock.kind_of?(String)
  clock = clock._daylight(jdt) if clock._need_validate
  frac  = clock.universal_time
  sdn, time = (jdt.universal_time - frac).divmod(Duration::DAY)
  cal_options[:clock] = clock
  return DateAndTime.new(to_cal_date(sdn.to_i + JulianDate::JD19700101), time+frac, cal_options)
end

#rate_of_clockNumeric

時間の歩度

Returns:



140
141
142
# File 'lib/when_exe/tmreference.rb', line 140

def rate_of_clock
  @time_basis ? @time_basis.time_standard.rate_of_clock : 1.0
end

#time_standardWhen::TimeStandard?

時刻制 - additional attribute

Returns:



132
133
134
# File 'lib/when_exe/tmreference.rb', line 132

def time_standard
  @time_basis ? @time_basis.time_standard : nil
end

#to_cal_date(jdn) ⇒ Numeric

ユリウス日(Numeric)を日付に変換する

Parameters:

  • jdn (Integer)

Returns:



214
215
216
# File 'lib/when_exe/tmreference.rb', line 214

def to_cal_date(jdn)
  return _encode(_number_to_coordinates(jdn))
end

#to_julian_date(cal_date) ⇒ Integer

日付をユリウス日(Numeric)に変換する

Parameters:

Returns:

  • (Integer)

    JulianDate



202
203
204
205
206
# File 'lib/when_exe/tmreference.rb', line 202

def to_julian_date(cal_date)
  date    = _decode(cal_date)
  date[0] = +date[0]
  return _coordinates_to_number(*date)
end