Class: When::CalendarNote::ShireWeek

Inherits:
Week show all
Defined in:
lib/when_exe/region/shire.rb

Overview

ホビット庄暦の暦週

Constant Summary collapse

Notes =
[When::BasicTypes::M17n, [
  "locale:[=en:, ja=ja:, alias]",
  "names:[Shire, ホビット庄暦]",

  # 年の暦注 ----------------------------
  [When::BasicTypes::M17n,
    "names:[note for year=, 年の暦注=, *year]"
  ],

  # 月の暦注 ----------------------------
  [When::BasicTypes::M17n,
    "names:[note for month=, 月の暦注=, *month]",
    [When::BasicTypes::M17n,
      "names:[month name=en:Month, 月の名前=ja:%%<月_(暦)>, zh:該月的名稱=, *alias:Month=]"
    ]
  ],

  # 日の暦注 ----------------------------
  [When::BasicTypes::M17n,
    "names:[note for day=, 日の暦注=, *day]",
    [When::BasicTypes::M17n,
      "names:[Week, 週, zh:星期]",
      [DayOfWeek, "label:[Saturday,  土曜日, /date/day_names/6]", {'delta'=>7}],
      [DayOfWeek, "label:[Sunday,    日曜日, /date/day_names/0]", {'delta'=>7}],
      [DayOfWeek, "label:[Monday,    月曜日, /date/day_names/1]", {'delta'=>7}],
      [DayOfWeek, "label:[Tuesday,   火曜日, /date/day_names/2]", {'delta'=>7}],
      [DayOfWeek, "label:[Wednesday, 水曜日, /date/day_names/3]", {'delta'=>7}],
      [DayOfWeek, "label:[Thursday,  木曜日, /date/day_names/4]", {'delta'=>7}],
      [DayOfWeek, "label:[Friday,    金曜日, /date/day_names/5]", {'delta'=>7}],
      [DayOfWeek, "label:[lithe,     中日= ]", {'delta'=> 365}],
      [DayOfWeek, "label:[double,    重日= ]", {'delta'=>1827}]
    ],

    "[Common_Week=]"
  ]
]]
FirstDayOfWeek =
[6, 1, 3, 5, 0, 2, 4] * 2
ExtraDayInYear =
{
  [ 8, 2] => 7,
  [ 8, 4] => 0
}
WeekLength =
{
  [ 8, 3] => 8,
  [ 8, 4] => 9
}

Constants inherited from When::CalendarNote

Bahai, CalendarDepend, Chinese, CommonWithRokuyo, CommonWithSovietFiveDay, CommonWithSovietSixDay, Default, HashProperty, Javanese, JulianDay, Mayan, Tibetan, Yis

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

Instance Attribute Summary

Attributes inherited from When::CalendarNote

#event

Attributes inherited from TM::ReferenceSystem

#domain_of_validity, #position

Attributes inherited from BasicTypes::Object

#label

Attributes included from Parts::Resource

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

Instance Method Summary collapse

Methods inherited from Week

#_column_for_week_included, #_range_for_week_included, #common_week, #week_labels

Methods inherited from When::CalendarNote

#copy, #day, #duration, #enum_for, #include?, #month, #note?, #notes, #year

Methods inherited from TM::ReferenceSystem

#domain, #name

Methods included from Parts::Resource

#[], #^, _abbreviation_to_iri, _decode, _encode, _extract_prefix, _instance, _instantiate, _parse, _path_with_prefix, _replace_tags, _setup_, _setup_info, _simplify_path, base_uri, #each, #enum_for, #hierarchy, #include?, #included?, #iri, #leaf?, #m17n, #map, #next, #parent, #prev, #registered?, root_dir

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 Method Details

#_normalize(args = [], options = {}) ⇒ Object

オブジェクトの正規化



188
189
190
191
# File 'lib/when_exe/region/shire.rb', line 188

def _normalize(args=[], options={})
  @event ||= 'saturday'
  super
end

#_to_date_for_note(date) ⇒ Object

暦日を当該暦注計算用クラスに変換



181
182
183
184
# File 'lib/when_exe/region/shire.rb', line 181

def _to_date_for_note(date)
  date = When::Shire ^ date unless date.frame.label.to_s == 'Shire'
  date
end

#lithe(date, parameter = nil) ⇒ When::TM::TemporalPosition

当日または直前の lithe の日

Parameters:

Returns:



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/when_exe/region/shire.rb', line 103

def lithe(date, parameter=nil)
  event_name = 'lithe'
  date  = date.frame.jul_trans(date, {:events=>[event_name]})
  y,m,d = date.cal_date
  m = date.frame.send(:_to_index,[y,m]) + 1
  h,n   = (m+5).divmod(7)
  dow   = 182 * h[0] + 30 * n + d + 1
  if m==8
    case d
    when 2 ; dow = 0
    when 3 ; dow = date.frame._sum([y]) == 365 ? 1 : 0
    when 4 ; dow = 1
    end
  end
  return date if dow == 0
  date += When::TM::PeriodDuration.new([0,0,-dow])
  date.events = [event_name]
  date
end

#week(date, base = nil) ⇒ Hash<:value=>When::CalendarNote::Week::DayOfWeek, :position=>Array<Integer>>

この日は何曜?

Parameters:

Returns:



167
168
169
170
171
172
173
174
175
# File 'lib/when_exe/region/shire.rb', line 167

def week(date, base=nil)
  date    = _to_date_for_note(date)
  y, m, d = date.cal_date
  m = date.frame.send(:_to_index, [y,m]) + 1
  length  = WeekLength[[m, date.length(When::MONTH)]] || 7
  index   = length == 8 ? 0 : 8 if [m,d] == [8,3]
  index ||= ExtraDayInYear[[m,d]] || (FirstDayOfWeek[m-1] + d - 1) % 7
  {:value=>@days_of_week[index], :position=>[index, length]}
end

#week_day(date, parameter = nil) ⇒ When::TM::TemporalPosition

Note:

week_day は saturday, sunday, monday, tuesday, wednesday, thursday, friday に読み替えてください。

Parameters:

Returns:



# File 'lib/when_exe/region/shire.rb', line 123