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::Format, TemporalPosition::HashProperty
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 When
CENTURY, DAY, DECADE, DurationP1D, DurationP1M, DurationP1W, DurationP1Y, EUCJP, HOUR, MINUTE, MONTH, SECOND, STRING, SYSTEM, SourceURI, When::TimeValue, UTF8, VERSION, W31J, WEEK, YEAR
Constants included from Parts::Resource
Parts::Resource::LabelProperty, Parts::Resource::Prefix, Parts::Resource::PrefixIndex, Parts::Resource::PrefixKeys, Parts::Resource::PrefixValues
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)
暦年代.
-
#calendar_era_name ⇒ Array
(also: #calendarEraName)
暦年代名.
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.
-
#_date_to_s(precision) ⇒ String
日付の年号以外の部分を文字列化する.
-
#_event_form(other = nil) ⇒ Object
event を 文字列化 - 日時で与えられた event を文字列化する.
-
#_to_hash(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) ⇒ When::BasicTypes::M17n
多言語対応文字列化 - When.exe Standard Representation により多言語対応文字列化する.
-
#to_residue(remainder, divisor) ⇒ When::Coordinates::Residue
剰余類化.
-
#to_s(precision = @precision) ⇒ String
文字列化 - When.exe Standard Representation により文字列化する.
-
#universal_time ⇒ Numeric
内部時間.
-
#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_, #_to_s, #clock_name, #copy, #dynamical_time, #has_next?, #has_time?, #include?, #is?, #month_included, #note?, #notes, #period, #prev, #rate_of_clock, #scan, #strftime, #succ, #term, #time_standard, #to_clock_time, #to_date, #to_date_time, #to_date_uri, #to_f, #to_time, #to_uri, #week_included, #year_included
Methods included from Coordinates
Methods included from When
Calendar, CalendarEra, CalendarNote, Clock, Duration, M17n, MonthName, Pair, Residue, Resource, TemporalPosition, _free_conv, _parse, _setup_, at, client, config, era, free_conv, m17n, now, server, today, utc, when?
Methods included from TemporalPosition::Conversion
Methods included from Parts::Resource
#[], #^, _extract_prefix, _instance, _parse, _path_with_prefix, #each, #enum_for, #hierarchy, #include?, #included?, #iri, #m17n, #map, #next, #parent, #prev, #registered?
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
日付要素
1349 1350 1351 |
# File 'lib/when_exe/tmposition.rb', line 1349 def cal_date @cal_date end |
#calendar_era ⇒ When::TM::CalendarEra Also known as: calendarEra
暦年代
1367 1368 1369 |
# File 'lib/when_exe/tmposition.rb', line 1367 def calendar_era @calendar_era end |
#calendar_era_name ⇒ Array Also known as: calendarEraName
暦年代名
1360 1361 1362 |
# File 'lib/when_exe/tmposition.rb', line 1360 def calendar_era_name @calendar_era_name end |
Instance Method Details
#%(other) ⇒ Numeric
ユリウス日または通年の剰余
1483 1484 1485 1486 1487 1488 1489 1490 |
# File 'lib/when_exe/tmposition.rb', line 1483 def %(other) raise TypeError,"The right operand should be When::Coordinates::Residue" unless other.kind_of?(Residue) case other.event when 'day' ; other % least_significant_coordinate when 'year' ; other % (most_significant_coordinate + @frame._diff_to_CE) else ; raise ArgumentError,"The right operand should have a unit 'day' or 'year'" end end |
#&(other) ⇒ When::TM::CalDate
ユリウス日または通年が指定の剰余となる日
1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 |
# File 'lib/when_exe/tmposition.rb', line 1455 def &(other) raise TypeError,"The right operand should be When::Coordinates::Residue" unless other.kind_of?(Residue) case other.event when 'day' # 指定の剰余となる日 other -= @frame.indices[-1].shift unless @frame.indices[-1].shift == 0 date = @frame.to_cal_date(other & to_i) date[0] -= @calendar_era_name[1] if @calendar_era_name return self.dup._copy({:events=>nil, :query=>@query, :validate=>:done, :date=>date}) when 'year' # 指定の剰余となる年 date = @cal_date.dup date[0] = (other & (most_significant_coordinate + @frame._diff_to_CE)) - @frame._diff_to_CE date[0] -= @calendar_era_name[1] if @calendar_era_name return self.dup._copy({:date=>date, :events=>nil, :query=>@query}) else raise ArgumentError,"The right operand should have a unit 'day' or 'year'" end end |
#_attr ⇒ Object
属性の Hash
1552 1553 1554 |
# File 'lib/when_exe/tmposition.rb', line 1552 def _attr super.merge({:era_name=>@calendar_era_name, :era=>@calendar_era}) end |
#_date_to_s(precision) ⇒ String
日付の年号以外の部分を文字列化する
1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 |
# File 'lib/when_exe/inspect.rb', line 1130 def _date_to_s(precision) # 準備 precision = [precision, 1 - @cal_date.length].max precision = [precision, DAY].min terms = [] format = "" # 年 year_by_epoch = @cal_date[0] if (@calendar_era_name) era, epoch, reverse = @calendar_era_name year_in_term = reverse ? -year_by_epoch : year_by_epoch year_by_calendar = epoch + year_by_epoch if epoch terms << year_in_term format += (0..99) === (year_in_term * 1) ? "%02d." : "%04d." if year_by_calendar && year_by_calendar != year_in_term terms << (year_by_calendar * 1) format += "(%04d)" end else terms << year_by_epoch format += (0..9999) === (year_by_epoch * 1) ? "%04d." : "%06d." end # 月日 ((1-@cal_date.length)..-1).each do |i| break if (i >= precision) terms << @cal_date[i] format += "%02d." end # 結果 date = Pair._format([format] + terms) date.sub!(/([^\d])\(([-+\d]+)\)/, '(\2)\1') if era date = date[0..-2] unless @frame.pair[precision-1] || date[-1..-1] != '.' date.gsub!(/\./, '-') if (@frame.indices.length <= DefaultDateIndex.length) && !era return date end |
#_event_form(other = nil) ⇒ Object
events 配列なし - 日時をそのまま文字列化 日時の精度が日より細かい - イベント名(イベント時刻) 日時の精度が日 - イベント名(当日までの経過日数)
event を 文字列化 - 日時で与えられた event を文字列化する
1115 1116 1117 1118 1119 1120 1121 1122 |
# File 'lib/when_exe/inspect.rb', line 1115 def _event_form(other=nil) return to_m17n unless events return events[0] + '(' + clk_time.to_s[/[:*=0-9]+/] + ')' if precision > When::DAY return events[0] unless other other = JulianDate.dynamical_time(other.dynamical_time, {:time_standard=>time_standard}) unless rate_of_clock == other.rate_of_clock events[0] + '(' + (other.to_i - to_i).to_s + ')' end |
#_to_hash(options = {}) ⇒ Hash
Hash 化
918 919 920 |
# File 'lib/when_exe/inspect.rb', line 918 def _to_hash(={}) super.update({:cal_date=>@cal_date}) end |
#calendar_name ⇒ Array
暦法名
874 875 876 877 878 879 |
# File 'lib/when_exe/inspect.rb', line 874 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
下位桁の切り上げ
1514 1515 1516 |
# File 'lib/when_exe/tmposition.rb', line 1514 def ceil(digit=DAY, precision=digit) (self + PeriodDuration.new(1, digit, (-@frame.indices.length)..0)).floor(digit, precision) end |
#clock ⇒ Object
時法の取得 - ダミー
1371 1372 1373 |
# File 'lib/when_exe/tmposition.rb', line 1371 def clock nil end |
#cwday ⇒ Numeric
七曜(暦週)
988 989 990 |
# File 'lib/when_exe/inspect.rb', line 988 def cwday (to_i % 7) + 1 end |
#cweek(d = 0) ⇒ Numeric
暦週
998 999 1000 1001 1002 1003 1004 |
# File 'lib/when_exe/inspect.rb', line 998 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
暦週の年
1074 1075 1076 1077 1078 1079 1080 |
# File 'lib/when_exe/inspect.rb', line 1074 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
日
952 953 954 |
# File 'lib/when_exe/inspect.rb', line 952 def day(d=0) @cal_date[DAY-1-d] end |
#floor(digit = DAY, precision = digit) ⇒ When::TM::CalDate
下位桁の切り捨て
1500 1501 1502 1503 1504 |
# File 'lib/when_exe/tmposition.rb', line 1500 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
暦年代が末端の参照であるか?
1542 1543 1544 1545 1546 1547 1548 |
# File 'lib/when_exe/tmposition.rb', line 1542 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
最下位の要素
1445 1446 1447 |
# File 'lib/when_exe/tmposition.rb', line 1445 def least_significant_coordinate return to_i + @frame.indices[-1].shift end |
#length(upper, lower = DAY) ⇒ Integer
要素数 ― 上位要素に含まれる下位要素の数
1525 1526 1527 1528 1529 |
# File 'lib/when_exe/tmposition.rb', line 1525 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
月内通日
962 963 964 |
# File 'lib/when_exe/inspect.rb', line 962 def mday(d=0) to_i - floor(MONTH-d).to_i + 1 end |
#month(d = 0) ⇒ Numeric Also known as: mon
月
1037 1038 1039 |
# File 'lib/when_exe/inspect.rb', line 1037 def month(d=0) @cal_date[MONTH-1-d] end |
#most_significant_coordinate ⇒ Numeric
最上位の要素
1431 1432 1433 1434 1435 1436 1437 1438 |
# File 'lib/when_exe/tmposition.rb', line 1431 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
月内通週
1014 1015 1016 |
# File 'lib/when_exe/inspect.rb', line 1014 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
要素の多言語対応文字列化
929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 |
# File 'lib/when_exe/inspect.rb', line 929 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
参照ラベル
886 887 888 889 890 |
# File 'lib/when_exe/inspect.rb', line 886 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
ユリウス日
1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 |
# File 'lib/when_exe/tmposition.rb', line 1392 def to_i return @sdn if @sdn name, base = @calendar_era_name if base date = @cal_date.dup date[0] += base else date = @cal_date end @sdn = @frame.to_julian_date(date) end |
#to_m17n(precision = @precision) ⇒ When::BasicTypes::M17n
多言語対応文字列化 - When.exe Standard Representation により多言語対応文字列化する
1088 1089 1090 1091 1092 1093 |
# File 'lib/when_exe/inspect.rb', line 1088 def to_m17n(precision=@precision) era, = @calendar_era_name date = _date_to_s(precision) return m17n(date) unless era return m17n(era) + date end |
#to_residue(remainder, divisor) ⇒ When::Coordinates::Residue
剰余類化
1411 1412 1413 1414 |
# File 'lib/when_exe/tmposition.rb', line 1411 def to_residue(remainder, divisor) When::Coordinates::Residue.new(remainder, divisor, {'day' => least_significant_coordinate, 'year' => most_significant_coordinate}) end |
#to_s(precision = @precision) ⇒ String
文字列化 - When.exe Standard Representation により文字列化する
1101 1102 1103 1104 1105 1106 |
# File 'lib/when_exe/inspect.rb', line 1101 def to_s(precision=@precision) era, = @calendar_era_name date = _date_to_s(precision) return date unless era return era.to_s + date end |
#universal_time ⇒ Numeric
内部時間
1381 1382 1383 1384 |
# File 'lib/when_exe/tmposition.rb', line 1381 def universal_time return super if [Now, Max, Min].include?(@indeterminated_position) @universal_time ||= JulianDate._d_to_t(to_i) end |
#value(index) ⇒ Numeric
要素の参照
1422 1423 1424 |
# File 'lib/when_exe/tmposition.rb', line 1422 def value(index) @cal_date[(_digit(index) {|digit| digit <= DAY})-1] end |
#wday ⇒ Numeric
七曜
980 981 982 |
# File 'lib/when_exe/inspect.rb', line 980 def wday (to_i + 1) % 7 end |
#yday(d = 0) ⇒ Numeric
年内通日
972 973 974 |
# File 'lib/when_exe/inspect.rb', line 972 def yday(d=0) to_i - floor(YEAR-d).to_i + 1 end |
#year(d = 0) ⇒ Numeric
年
1064 1065 1066 |
# File 'lib/when_exe/inspect.rb', line 1064 def year(d=0) @cal_date[YEAR-1-d] end |
#ymon(d1 = 0, d2 = 0) ⇒ Numeric
年内通月
1049 1050 1051 1052 1053 1054 1055 1056 |
# File 'lib/when_exe/inspect.rb', line 1049 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 |