Class: When::TM::CalDate
- Inherits:
-
TemporalPosition
- Object
- TemporalPosition
- When::TM::CalDate
- Defined in:
- lib/when_exe/tmposition.rb,
lib/when_exe/inspect.rb
Overview
暦日
see gml schema
Direct Known Subclasses
Constant Summary collapse
Constants inherited from TemporalPosition
TemporalPosition::AMPM, TemporalPosition::DateTimeInstanceMethods, TemporalPosition::Format, TemporalPosition::HashProperty
Constants included from Coordinates
Coordinates::Bahai, Coordinates::Common, Coordinates::DefaultDateIndices, Coordinates::DefaultDayIndex, Coordinates::DefaultTimeIndices, Coordinates::Indian, Coordinates::Iranian, Coordinates::Javanese, Coordinates::MATCH, Coordinates::Mayan, Coordinates::PERIOD, Coordinates::PERIOD_NAME, Coordinates::PRECISION, Coordinates::PRECISION_NAME, Coordinates::Tibetan, Coordinates::VALUE, Coordinates::Yi
Constants included from When
CENTURY, 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
Constants included from Parts::Resource
Parts::Resource::ConstList, Parts::Resource::ConstTypes, Parts::Resource::IRIHeader, Parts::Resource::LabelProperty
Constants included from IndeterminateValue
IndeterminateValue::After, IndeterminateValue::Before, IndeterminateValue::I, IndeterminateValue::Max, IndeterminateValue::Min, IndeterminateValue::Now, IndeterminateValue::S, IndeterminateValue::Unknown
Instance Attribute Summary collapse
-
#cal_date ⇒ Array<Numeric>
(also: #calDate)
readonly
日付要素.
-
#calendar_era ⇒ When::TM::CalendarEra
(also: #calendarEra)
readonly
暦年代.
-
#calendar_era_name ⇒ Array
(also: #calendarEraName)
readonly
暦年代名.
Attributes inherited from TemporalPosition
#events, #frame, #indeterminated_position, #location, #options, #precision, #query, #trans
Attributes included from Parts::Resource
#_pool, #child, #keys, #locale, #namespace
Instance Method Summary collapse
-
#%(other) ⇒ Numeric
ユリウス日または通年の剰余.
-
#&(other) ⇒ When::TM::CalDate
ユリウス日または通年が指定の剰余となる日.
-
#_attr ⇒ Object
属性の Hash.
-
#_event_form(other = nil, round_precision = nil) ⇒ String
event を 文字列化 - 日時で与えられた event を文字列化する.
-
#_to_h(options = {}) ⇒ Hash
Hash 化.
-
#calendar_name ⇒ Array
暦法名.
-
#ceil(digit = DAY, precision = digit) ⇒ When::TM::CalDate
下位桁の切り上げ.
-
#clock ⇒ Object
時法の取得 - ダミー.
-
#cwday ⇒ Numeric
七曜(暦週).
-
#cweek(d = 0) ⇒ Numeric
暦週.
-
#cwyear(d = 0) ⇒ Numeric
暦週の年.
-
#day(d = 0) ⇒ Numeric
日.
-
#floor(digit = DAY, precision = digit) ⇒ When::TM::CalDate
下位桁の切り捨て.
-
#leaf? ⇒ Boolean
暦年代が末端の参照であるか?.
-
#least_significant_coordinate ⇒ Numeric
最下位の要素.
-
#length(upper, lower = DAY) ⇒ Integer
要素数 ― 上位要素に含まれる下位要素の数.
-
#mday(d = 0) ⇒ Numeric
月内通日.
-
#month(d = 0) ⇒ Numeric
(also: #mon)
月.
-
#most_significant_coordinate ⇒ Numeric
最上位の要素.
-
#mweek(w = 6, m = 7, d = 0) ⇒ Numeric
月内通週.
-
#name(index, format = nil) ⇒ When::BasicTypes::M17n
要素の多言語対応文字列化.
-
#reference_label ⇒ When::BasicTypes::M17n
参照ラベル.
-
#to_i ⇒ Integer
ユリウス日.
-
#to_m17n(precision = @precision, round = false) ⇒ When::BasicTypes::M17n
多言語対応文字列化 - When.exe Standard Representation により多言語対応文字列化する.
-
#to_residue(remainder, divisor) ⇒ When::Coordinates::Residue
剰余類化.
-
#to_s(precision = @precision, round = false) ⇒ String
文字列化 - When.exe Standard Representation により文字列化する.
-
#universal_time ⇒ Numeric
(also: #local_time)
内部時間.
-
#value(index) ⇒ Numeric
要素の参照.
-
#wday ⇒ Numeric
七曜.
-
#yday(d = 0) ⇒ Numeric
年内通日.
-
#year(d = 0) ⇒ Numeric
年.
-
#ymon(d1 = 0, d2 = 0) ⇒ Numeric
年内通月.
-
#yweek(w = 6, m = 7, d = 0) ⇒ Numeric
年内通週.
Methods inherited from TemporalPosition
#+, #+@, #-, #<=>, #==, #[], #^, _instance, #_notes, _options, _setup_, _setup_info, _temporal_position, #_term, #_to_s, _verify, #caret_frame, #clock_name, #copy, #dynamical_time, format, #has_next?, #has_time?, #include?, #inspect, #is?, #month_included, #note?, #notes, #period, #prev, #rate_of_clock, #scan, #strftime, #succ, #time_standard, #to_clock_time, #to_date, #to_datetime, #to_f, #to_time, #week_included, #year_included
Methods included from Coordinates
Methods included from When
Border, Calendar, CalendarEra, CalendarNote, Clock, Duration, Index, Location, M17n, MonthName, Pair, Residue, Resource, TemporalPosition, Wikipedia, _const_missing, _define_common_calendar_types, _setup_, _setup_info, at, client, column, config, const_missing, era, free_conv, m17n, now, server, today, when?
Methods included from TemporalPosition::Conversion
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, #m17n, #map, #next, #parent, #prev, #registered?, root_dir
Methods included from Parts::Resource::Pool
#[], #[]=, #_pool, #_setup_, #pool_keys
Methods included from Parts::Resource::Synchronize
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class When::TM::TemporalPosition
Instance Attribute Details
#cal_date ⇒ Array<Numeric> (readonly) Also known as: calDate
ISO19108 では sequence<Integer> だが、閏月などが表現可能なよう Numeric としている。
日付要素
1599 1600 1601 |
# File 'lib/when_exe/tmposition.rb', line 1599 def cal_date @cal_date end |
#calendar_era ⇒ When::TM::CalendarEra Also known as: calendarEra
暦年代
1626 1627 1628 |
# File 'lib/when_exe/tmposition.rb', line 1626 def calendar_era @calendar_era end |
#calendar_era_name ⇒ Array Also known as: calendarEraName
暦年代名
1618 1619 1620 |
# File 'lib/when_exe/tmposition.rb', line 1618 def calendar_era_name @calendar_era_name end |
Instance Method Details
#%(other) ⇒ Numeric
ユリウス日または通年の剰余
1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 |
# File 'lib/when_exe/tmposition.rb', line 1753 def %(other) raise TypeError,"The right operand should be When::Coordinates::Residue" unless other.kind_of?(Residue) if precision <= When::YEAR && other.units['year'] && other.event != 'year' other.to('year') % (most_significant_coordinate + @frame.epoch_in_CE) else case other.event when 'day' ; other % least_significant_coordinate when 'year' ; other % (most_significant_coordinate + @frame.epoch_in_CE) else ; raise ArgumentError,"The right operand should have a unit 'day' or 'year'" end end end |
#&(other) ⇒ When::TM::CalDate
ユリウス日または通年が指定の剰余となる日
1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 |
# File 'lib/when_exe/tmposition.rb', line 1723 def &(other) raise TypeError,"The right operand should be When::Coordinates::Residue" unless other.kind_of?(Residue) case other.event when 'day' # 指定の剰余となる日 sdn = other & to_i = {:date=>_date_with_era(@frame.to_cal_date(sdn)), :events=>nil, :query=>@query, :validate=>:done} [:precision] = When::DAY if precision < When::DAY result = self.dup._copy() result.send(:_force_euqal_day, sdn-result.to_i) when 'year' # 指定の剰余となる年 date = @frame.send(:_decode, _date_without_era) date[0] = (other & (date[0] + @frame.diff_to_CE)) - @frame.diff_to_CE = {:date=>_date_with_era(@frame.send(:_encode, date)), :events=>nil, :query=>@query} [:precision] = When::YEAR if precision < When::YEAR return self.dup._copy() else raise ArgumentError,"The right operand should have a unit 'day' or 'year'" end end |
#_attr ⇒ Object
属性の Hash
1826 1827 1828 |
# File 'lib/when_exe/tmposition.rb', line 1826 def _attr super.merge({:era_name=>@calendar_era_name, :era=>@calendar_era}) end |
#_event_form(other = nil, round_precision = nil) ⇒ String
events 配列なし - 日時をそのまま文字列化 日時の精度が日より細かい - イベント名(イベント時刻) 日時の精度が日 - イベント名(当日までの経過日数)
event を 文字列化 - 日時で与えられた event を文字列化する
1251 1252 1253 1254 1255 1256 1257 1258 |
# File 'lib/when_exe/inspect.rb', line 1251 def _event_form(other=nil, round_precision=nil) return to_m17n unless events return events[0] + '(' + _clk_time_for_inspect(round_precision).to_s(round_precision || precision)[/[:*=0-9]+/] + ')' if precision > When::DAY return events[0] unless other other = JulianDate.dynamical_time(other.dynamical_time, {:time_standard=>time_standard}) unless time_standard.rate_of_clock == other.time_standard.rate_of_clock events[0] + '(' + (other.to_i - to_i).to_s + ')' end |
#_to_h(options = {}) ⇒ Hash
Hash 化
1045 1046 1047 |
# File 'lib/when_exe/inspect.rb', line 1045 def _to_h(={}) super.update({:cal_date=>@cal_date}) end |
#calendar_name ⇒ Array
暦法名
1001 1002 1003 1004 1005 1006 |
# File 'lib/when_exe/inspect.rb', line 1001 def calendar_name void, epoch, reverse, back = @calendar_era_name name = [@calendar_era || @frame, epoch, reverse, back] name.pop until name[-1] return name end |
#ceil(digit = DAY, precision = digit) ⇒ When::TM::CalDate
下位桁の切り上げ
1788 1789 1790 |
# File 'lib/when_exe/tmposition.rb', line 1788 def ceil(digit=DAY, precision=digit) (self + PeriodDuration.new(1, digit, (-@frame.indices.length)..0)).floor(digit, precision) end |
#clock ⇒ Object
時法の取得 - ダミー
1631 1632 1633 |
# File 'lib/when_exe/tmposition.rb', line 1631 def clock nil end |
#cwday ⇒ Numeric
七曜(暦週)
1115 1116 1117 |
# File 'lib/when_exe/inspect.rb', line 1115 def cwday (to_i % 7) + 1 end |
#cweek(d = 0) ⇒ Numeric
暦週
1125 1126 1127 1128 1129 1130 1131 |
# File 'lib/when_exe/inspect.rb', line 1125 def cweek(d=0) [1,0,-1].each do |i| start = ((self + PeriodDuration.new(i, YEAR-d)).floor(YEAR-d,DAY) + PeriodDuration.new(4, DAY)) & Residue.new(0,7,-1) return ((to_i - start.to_i).div 7) + 1 if self >= start end raise IndexError, 'Cannot decide year number' end |
#cwyear(d = 0) ⇒ Numeric
暦週の年
1201 1202 1203 1204 1205 1206 1207 |
# File 'lib/when_exe/inspect.rb', line 1201 def cwyear(d=0) [1,0,-1].each do |i| start = ((self + PeriodDuration.new(i, YEAR-d)).floor(YEAR-d,DAY) + PeriodDuration.new(4, DAY)) & Residue.new(0,7,-1) return year(d)+i if self >= start end raise IndexError, 'Cannot decide year number' end |
#day(d = 0) ⇒ Numeric
日
1079 1080 1081 |
# File 'lib/when_exe/inspect.rb', line 1079 def day(d=0) @cal_date[DAY-1-d] end |
#floor(digit = DAY, precision = digit) ⇒ When::TM::CalDate
下位桁の切り捨て
1774 1775 1776 1777 1778 |
# File 'lib/when_exe/tmposition.rb', line 1774 def floor(digit=DAY, precision=digit) = {:date=>@cal_date[0..(digit-1)], :events=>nil, :query=>nil} [:precision] = precision if precision self.dup._copy() end |
#leaf? ⇒ Boolean
暦年代が末端の参照であるか?
1816 1817 1818 1819 1820 1821 1822 |
# File 'lib/when_exe/tmposition.rb', line 1816 def leaf? name, = @calendar_era_name return true unless name.respond_to?(:_pool) era = name._pool['..'] return true unless era.respond_to?(:leaf?) return era.leaf? end |
#least_significant_coordinate ⇒ Numeric
最下位の要素
1713 1714 1715 |
# File 'lib/when_exe/tmposition.rb', line 1713 def least_significant_coordinate return to_i + @frame.indices[-1].shift end |
#length(upper, lower = DAY) ⇒ Integer
要素数 ― 上位要素に含まれる下位要素の数
1799 1800 1801 1802 1803 |
# File 'lib/when_exe/tmposition.rb', line 1799 def length(upper, lower=DAY) range = [floor(upper).to_i, ceil(upper).to_i] range = range.map {|d| (Residue.mod(d) {|m| frame._new_month(m)})[0]} if lower == MONTH range[1] - range[0] end |
#mday(d = 0) ⇒ Numeric
月内通日
1089 1090 1091 |
# File 'lib/when_exe/inspect.rb', line 1089 def mday(d=0) to_i - floor(MONTH-d).to_i + 1 end |
#month(d = 0) ⇒ Numeric Also known as: mon
月
1164 1165 1166 |
# File 'lib/when_exe/inspect.rb', line 1164 def month(d=0) @cal_date[MONTH-1-d] end |
#most_significant_coordinate ⇒ Numeric
最上位の要素
1699 1700 1701 1702 1703 1704 1705 1706 |
# File 'lib/when_exe/tmposition.rb', line 1699 def most_significant_coordinate coordinate = @cal_date[0] coordinate += @calendar_era_name[1] if @calendar_era_name @frame.index_of_MSC.times do |i| coordinate = +coordinate * @frame.indices[i].unit + @cal_date[i+1] - @frame.indices[i].base end coordinate end |
#mweek(w = 6, m = 7, d = 0) ⇒ Numeric
月内通週
1141 1142 1143 |
# File 'lib/when_exe/inspect.rb', line 1141 def mweek(w=6, m=7, d=0) 1 + (to_i - (floor(MONTH-d,DAY) & Residue.new(w,m)).to_i).div(7) end |
#name(index, format = nil) ⇒ When::BasicTypes::M17n
要素の多言語対応文字列化
1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 |
# File 'lib/when_exe/inspect.rb', line 1056 def name(index, format=nil) digit = _digit(index) {|digit| digit <= DAY} coordinate = @cal_date[digit-1] return m17n(format % coordinate) if format indices = @frame.indices[digit-1] if indices trunk = indices.trunk branch = indices.branch end format = branch ? m17n("%02d-") : "%02d" return m17n(format % coordinate) unless trunk trunk = trunk[coordinate * 1] return m17n(trunk) unless branch return trunk.prefix(branch[coordinate * 0||0]) end |
#reference_label ⇒ When::BasicTypes::M17n
参照ラベル
1013 1014 1015 1016 1017 |
# File 'lib/when_exe/inspect.rb', line 1013 def reference_label return @calendar_era.hierarchy.map {|e| e.label} if @calendar_era return [@frame.label] if @frame.label [When::BasicTypes::M17n.new(@frame.class.to_s.split(/::/)[-1])] end |
#to_i ⇒ Integer
ユリウス日
1653 1654 1655 |
# File 'lib/when_exe/tmposition.rb', line 1653 def to_i @sdn ||= _to_i end |
#to_m17n(precision = @precision, round = false) ⇒ When::BasicTypes::M17n
多言語対応文字列化 - When.exe Standard Representation により多言語対応文字列化する
1216 1217 1218 1219 1220 1221 1222 |
# File 'lib/when_exe/inspect.rb', line 1216 def to_m17n(precision=@precision, round=false) date = m17n(_date_to_s(precision)) return date unless @calendar_era return _parent_labels.inject(m17n(@calendar_era_name[0])) {|era_name, parent| era_name.prefix(m17n(parent) + '::') } + date end |
#to_residue(remainder, divisor) ⇒ When::Coordinates::Residue
剰余類化
1679 1680 1681 1682 |
# File 'lib/when_exe/tmposition.rb', line 1679 def to_residue(remainder, divisor) When::Coordinates::Residue.new(remainder, divisor, {'day' => least_significant_coordinate, 'year' => most_significant_coordinate}) end |
#to_s(precision = @precision, round = false) ⇒ String
文字列化 - When.exe Standard Representation により文字列化する
1231 1232 1233 1234 1235 1236 1237 |
# File 'lib/when_exe/inspect.rb', line 1231 def to_s(precision=@precision, round=false) date = _date_to_s(precision) return date unless @calendar_era return _parent_labels.inject(@calendar_era_name[0].to_s) {|era_name, parent| parent.to_s + '::' + era_name } + date end |
#universal_time ⇒ Numeric Also known as: local_time
内部時間
1641 1642 1643 1644 |
# File 'lib/when_exe/tmposition.rb', line 1641 def universal_time return super if [Now, Max, Min].include?(@indeterminated_position) @universal_time ||= JulianDate._d_to_t(to_i) end |
#value(index) ⇒ Numeric
要素の参照
1690 1691 1692 |
# File 'lib/when_exe/tmposition.rb', line 1690 def value(index) @cal_date[(_digit(index) {|digit| digit <= DAY})-1] end |
#wday ⇒ Numeric
七曜
1107 1108 1109 |
# File 'lib/when_exe/inspect.rb', line 1107 def wday (to_i + 1) % 7 end |
#yday(d = 0) ⇒ Numeric
年内通日
1099 1100 1101 |
# File 'lib/when_exe/inspect.rb', line 1099 def yday(d=0) to_i - floor(YEAR-d).to_i + 1 end |
#year(d = 0) ⇒ Numeric
年
1191 1192 1193 |
# File 'lib/when_exe/inspect.rb', line 1191 def year(d=0) @cal_date[YEAR-1-d] end |
#ymon(d1 = 0, d2 = 0) ⇒ Numeric
年内通月
1176 1177 1178 1179 1180 1181 1182 1183 |
# File 'lib/when_exe/inspect.rb', line 1176 def ymon(d1=0, d2=0) current = floor(YEAR-d1, MONTH-d2) @frame._length(@cal_date[(YEAR-1-d1)...(MONTH-1-d2)]).times do |i| return i+1 if current == self current = current.succ end raise IndexError, 'Cannot decide month number' end |