Class: When::CalendarNote::RokuyoWeek

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

Overview

六曜

Constant Summary collapse

Notes =

暦注要素の定義

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

  # 日の暦注 ----------------------------
  [When::BasicTypes::M17n,
    "names:[day]",
    [When::BasicTypes::M17n,
      "names:[Rokuyo=, 六曜, 六曜=zh:%%<六曜>]",
      [DayOfWeek, "label:[Taian=,      *大安, 大安]", {'delta'=>6}],
      [DayOfWeek, "label:[Shakko=,     *赤口, 赤口]", {'delta'=>6}],
      [DayOfWeek, "label:[Sensho=,     *先勝, 先勝]", {'delta'=>6}],
      [DayOfWeek, "label:[Tomobiki=,   *友引, 友引]", {'delta'=>6}],
      [DayOfWeek, "label:[Sembu=,      *先負, 先負]", {'delta'=>6}],
      [DayOfWeek, "label:[Butsumetsu=, *仏滅, 仏滅]", {'delta'=>6}]
    ]
  ]
]]

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

暦日を太陰太陽暦日に変換



96
97
98
99
100
# File 'lib/when_exe/region/japanese/weeks.rb', line 96

def _to_date_for_note(date)
  return date if date.frame.kind_of?(When::CalendarTypes::ChineseLuniSolar)
  return When::Japanese ^ date if date.most_significant_coordinate >= 1873
  return Japanese._to_japanese_date(date)
end

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

この日は何曜?

Parameters:

Returns:



50
51
52
53
54
55
# File 'lib/when_exe/region/japanese/weeks.rb', line 50

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

#rokuyo_index(m, d) ⇒ Object



64
65
66
# File 'lib/when_exe/region/japanese/weeks.rb', line 64

def rokuyo_index(m,d)
  (m*1 + d) % 6
end

#rokuyo_value(m, d) ⇒ Object



59
60
61
# File 'lib/when_exe/region/japanese/weeks.rb', line 59

def rokuyo_value(m,d)
  @days_of_week[rokuyo_index(m,d)]
end

#taian(date, base = nil) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/when_exe/region/japanese/weeks.rb', line 69

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