Class: When::CalendarNote::SovietFiveDayWeek

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

Overview

五曜

Constant Summary collapse

Holidays =
{
  [1,22] => 5, [2,29] => 6, [5,1] => 5, [5,2] => 5, [11,7] => 5, [11,8] => 5
}
FirstDay =
[0, 0, 3, 4, 4, 3, 3, 4, 0, 0, 1, 4]
SkipDay =
{
  1 => [23,1], 5 => [3,2], 11 => [9,2]
}
Notes =

暦注要素の定義

[When::BasicTypes::M17n, [
  "locale:[=en:, ja=ja:, alias]",
  "names:[SovietFiveDay]",

  # 日の暦注 ----------------------------
  [When::BasicTypes::M17n,
    "names:[day]",
    [When::BasicTypes::M17n,
      "names:[FiveDay, 五曜]",
      [DayOfWeek, "label:[I=      ]", {'delta'=>5}],
      [DayOfWeek, "label:[II=     ]", {'delta'=>5}],
      [DayOfWeek, "label:[III=    ]", {'delta'=>5}],
      [DayOfWeek, "label:[IV=     ]", {'delta'=>5}],
      [DayOfWeek, "label:[V=      ]", {'delta'=>5}],
      [DayOfWeek, "label:[Holiday=]", {'delta'=>190}],
      [DayOfWeek, "label:[Leapday=]", {'delta'=>1461}]
    ]
  ]
]]

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

#_to_date_for_note(date) ⇒ Object

暦日をグレゴリオ暦日に変換



124
125
126
127
# File 'lib/when_exe/region/russian.rb', line 124

def _to_date_for_note(date)
  return date if date.frame.kind_of?(When::CalendarTypes::Gregorian)
  return When::Gregorian ^ date
end

#first(date, base = nil) ⇒ Object



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/when_exe/region/russian.rb', line 88

def first(date, base=nil)
  count = 0
  d0 = d1 = _to_date_for_note(date)
  r0 = r1 = nil
  loop do
    y,m,d = d1.cal_date
    r1    = fiveday_index(m,d)
    break if r1 == 0
    d0 = d1
    r0 = r1
    d1 = d0 - When::P1D
    count += 1
  end
  date -= count if count > 0
  date.events = [@days_of_week[r1]]
  date
end

#first_delta(parameter = nil) ⇒ Object



116
117
118
# File 'lib/when_exe/region/russian.rb', line 116

def first_delta(parameter=nil)
  When::P5D
end

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

この日は何曜?

Parameters:

Returns:



79
80
81
82
83
84
# File 'lib/when_exe/region/russian.rb', line 79

def fiveday(date, base=nil)
  date  = _to_date_for_note(date)
  y,m,d = date.cal_date
  index = fiveday_index(m,d)
  {:value=>@days_of_week[index], :position=>[index, 7]}
end

#fiveday_index(m, d) ⇒ Object



107
108
109
110
111
112
113
# File 'lib/when_exe/region/russian.rb', line 107

def fiveday_index(m,d)
  index = Holidays[[m,d]]
  return index if index
  day, shift = SkipDay[m]
  d -= shift if day && d >= day
  (FirstDay[m-1] + d - 1) % 5
end