when_exe 0.3.7 → 0.3.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (108) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +210 -171
  3. data/bin/irb.rc +1 -0
  4. data/lib/when_exe.rb +78 -53
  5. data/lib/when_exe/basictypes.rb +27 -8
  6. data/lib/when_exe/calendarnote.rb +848 -805
  7. data/lib/when_exe/calendartypes.rb +110 -240
  8. data/lib/when_exe/coordinates.rb +2440 -2175
  9. data/lib/when_exe/core/compatibility.rb +1 -1
  10. data/lib/when_exe/core/duration.rb +13 -11
  11. data/lib/when_exe/core/extension.rb +38 -45
  12. data/lib/when_exe/ephemeris.rb +43 -14
  13. data/lib/when_exe/ephemeris/eclipse.rb +149 -0
  14. data/lib/when_exe/ephemeris/notes.rb +39 -7
  15. data/lib/when_exe/icalendar.rb +2 -6
  16. data/lib/when_exe/inspect.rb +1408 -1399
  17. data/lib/when_exe/parts/enumerator.rb +486 -477
  18. data/lib/when_exe/parts/resource.rb +1101 -1069
  19. data/lib/when_exe/parts/timezone.rb +6 -5
  20. data/lib/when_exe/region/babylonian.rb +405 -405
  21. data/lib/when_exe/region/bahai.rb +21 -61
  22. data/lib/when_exe/region/chinese/epochs.rb +81 -81
  23. data/lib/when_exe/region/chinese/twins.rb +51 -51
  24. data/lib/when_exe/region/christian.rb +7 -2
  25. data/lib/when_exe/region/coptic.rb +1 -1
  26. data/lib/when_exe/region/discordian.rb +9 -16
  27. data/lib/when_exe/region/french.rb +1 -1
  28. data/lib/when_exe/region/hanke_henry.rb +57 -0
  29. data/lib/when_exe/region/indian.rb +41 -73
  30. data/lib/when_exe/region/international_fixed.rb +97 -0
  31. data/lib/when_exe/region/iranian.rb +203 -203
  32. data/lib/when_exe/region/japanese.rb +13 -13
  33. data/lib/when_exe/region/japanese/eclipses.rb +1194 -0
  34. data/lib/when_exe/region/japanese/notes.rb +1482 -1383
  35. data/lib/when_exe/region/japanese/residues.rb +726 -721
  36. data/lib/when_exe/region/japanese/twins.rb +37 -37
  37. data/lib/when_exe/region/jewish.rb +2 -2
  38. data/lib/when_exe/region/pax.rb +60 -0
  39. data/lib/when_exe/region/positivist.rb +100 -0
  40. data/lib/when_exe/region/roman.rb +333 -334
  41. data/lib/when_exe/region/shire.rb +3 -20
  42. data/lib/when_exe/region/thai.rb +2 -2
  43. data/lib/when_exe/region/tibetan.rb +3 -3
  44. data/lib/when_exe/region/tranquility.rb +208 -0
  45. data/lib/when_exe/region/vanishing_leprechaun.rb +53 -0
  46. data/lib/when_exe/region/vietnamese.rb +4 -4
  47. data/lib/when_exe/region/world.rb +9 -13
  48. data/lib/when_exe/region/world_season.rb +89 -0
  49. data/lib/when_exe/region/zoroastrian.rb +4 -2
  50. data/lib/when_exe/tmobjects.rb +14 -4
  51. data/lib/when_exe/tmposition.rb +239 -81
  52. data/lib/when_exe/tmreference.rb +57 -28
  53. data/lib/when_exe/version.rb +1 -1
  54. data/link_to_online_documents +6 -3
  55. data/test/examples/today.rb +1 -1
  56. data/test/scripts.rb +23 -0
  57. data/test/scripts/2.ext.rb +169 -0
  58. data/test/scripts/2.rb +169 -0
  59. data/test/scripts/3.ext.rb +133 -0
  60. data/test/scripts/3.rb +134 -0
  61. data/test/scripts/4.ext.rb +112 -0
  62. data/test/scripts/4.min.rb +65 -0
  63. data/test/scripts/4.rb +136 -0
  64. data/test/scripts/5.ext.rb +78 -0
  65. data/test/scripts/5.rb +81 -0
  66. data/test/scripts/6.gcal.rb +131 -0
  67. data/test/scripts/6.rb +205 -0
  68. data/test/scripts/6.tz.rb +105 -0
  69. data/test/scripts/7.phase.rb +109 -0
  70. data/test/scripts/7.rb +95 -0
  71. data/test/scripts/7.term.rb +128 -0
  72. data/test/scripts/7.week.rb +84 -0
  73. data/test/scripts/8.ext.rb +61 -0
  74. data/test/scripts/8.rb +62 -0
  75. data/test/scripts/9.ext.rb +131 -0
  76. data/test/scripts/9.rb +130 -0
  77. data/test/scripts/chinese-luni-solar.rb +52 -0
  78. data/test/{examples → scripts}/geometric_complex.rb +41 -41
  79. data/test/scripts/geometric_complex.txt +18 -0
  80. data/test/scripts/korea.rb +59 -0
  81. data/test/scripts/thai-reviewed.txt +211 -0
  82. data/test/scripts/thai.rb +36 -0
  83. data/test/scripts/thai.txt +210 -0
  84. data/test/test.rb +7 -0
  85. data/test/test/basictypes.rb +22 -0
  86. data/test/test/coordinates.rb +2 -1
  87. data/test/test/ephemeris.rb +34 -2
  88. data/test/test/icalendar.rb +12 -0
  89. data/test/test/inspect.rb +37 -1
  90. data/test/test/parts.rb +4 -3
  91. data/test/test/region/armenian.rb +20 -0
  92. data/test/test/region/bahai.rb +58 -0
  93. data/test/test/region/chinese.rb +14 -3
  94. data/test/test/region/christian.rb +16 -35
  95. data/test/test/region/discordian.rb +20 -0
  96. data/test/test/region/indian.rb +30 -2
  97. data/test/test/region/japanese.rb +24 -0
  98. data/test/test/region/jewish.rb +2 -0
  99. data/test/test/region/m17n.rb +9 -0
  100. data/test/test/region/reforms.rb +121 -0
  101. data/test/test/region/residue.rb +17 -11
  102. data/test/test/region/shire.rb +58 -0
  103. data/test/test/region/swedish.rb +45 -0
  104. data/test/test/region/zoroastrian.rb +58 -0
  105. data/test/test/tmobjects.rb +74 -0
  106. data/test/test/tmposition.rb +468 -397
  107. data/when_exe.gemspec +2 -2
  108. metadata +49 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 61d0b1c1a37dc54c8a87505b8ec22282052f56ee
4
- data.tar.gz: 88aa53ad73c559c3d40f9992c4bd932f5292a48c
3
+ metadata.gz: ca90b8ebed96ce64a2c0b93e067defebd8869ea1
4
+ data.tar.gz: c6cb89d2565a62f2c29ebc74dfc5f2d0bcab216e
5
5
  SHA512:
6
- metadata.gz: c1d4d428fb2704611c027aae6f1d1301da50a69e76e386ed7ed56a2a9079c5f65d89b88b6084848cc9f04ebbfd2c4f5aa22e4bc26499c554179000f70d50cb20
7
- data.tar.gz: cd39d0b62c40b1628c6ce1a06620064f095bcdd5115bafda9a1d297595c915d44c29b2fe0036ad3b7d582496fbb13e1b8d38d194b80b1bee57e06439a89b98f4
6
+ metadata.gz: 20e83d837a520301666ac114cfef67fed2bc17cf76d22109840338b97002426afb28ea829deb6cae32536c9e1e5d5d7818c9b7a2c9c6378ad25178924e49a012
7
+ data.tar.gz: 164603f56b00c452fda7a0a27233a3451c7402db412807adc835523fc82292ac3324963dcd26deb9190fd06076816cb1ce504b112388f04b05805ab4dce319b2
data/README.md CHANGED
@@ -1,171 +1,210 @@
1
- when_exe - A multicultural and multilingualized calendar library
2
- ================================================================
3
-
4
- [![Gem Version](https://badge.fury.io/rb/when_exe.svg)](http://badge.fury.io/rb/when_exe)
5
-
6
- [when_exe](http://rubygems.org/gems/when_exe) is a multicultural and multilingualized calendar library based on ISO 8601, ISO 19108, RFC 5545 and RFC6350.
7
-
8
- Installation
9
- ------------
10
-
11
- The when_exe gem can be installed by running:
12
-
13
- gem install when_exe
14
-
15
-
16
- Documentation
17
- -------------
18
-
19
- API documentation for when_exe is available on [RubyDoc.info](http://rubydoc.info/gems/when_exe/frames).
20
-
21
-
22
- License
23
- -------
24
-
25
- This beta version's license is limited. Please see [LICENSE.txt](https://github.com/suchowan/when_exe/blob/master/LICENSE.txt) for details.
26
-
27
-
28
- Source Code
29
- -----------
30
-
31
- Source code for when_exe is available on [GitHub](https://github.com/suchowan/when_exe).
32
-
33
-
34
- Example Usage
35
- -------------
36
-
37
- require 'when_exe'
38
-
39
- # When::TM::CalDate
40
-
41
- gregorian_date = When.tm_pos(2014, 8, 1)
42
- p gregorian_date #=> 2014-08-01
43
- p When.when?('2014-08-01') #=> 2014-08-01, the same date
44
- p gregorian_date.to_i #=> 2456871, Julian Day Number(Integer)
45
- p gregorian_date.to_f #=> 2456871.0, at noon for UTC
46
- p gregorian_date.class #=> When::TM::CalDate
47
- p gregorian_date.frame.iri #=> "http://hosi.org/When/CalendarTypes/Gregorian"
48
- puts gregorian_date.name(When::MONTH) / 'en' #=> August
49
- puts gregorian_date.name(When::MONTH) / 'fr' #=> août
50
- puts gregorian_date.name(When::MONTH) / 'ar' #=> اغسطس
51
- p gregorian_date.easter #=> 2014-04-20
52
- p gregorian_date.is?('Easter') #=> false
53
- p When.tm_pos(2014, 4, 20).is?('Easter') #=> true
54
-
55
- islamic_date = When::TabularIslamic ^ gregorian_date
56
- p islamic_date #=> 1435-10-04
57
- p islamic_date.frame.iri #=> ""http://hosi.org/When/CalendarTypes/TabularIslamic"
58
- puts islamic_date.name(When::MONTH) / 'en' #=> Shawwal
59
- puts islamic_date.name(When::MONTH) / 'ar' #=> شوال
60
-
61
- # When::TM::DateAndTime
62
-
63
- gregorian_date = When.tm_pos(2014, 8, 1, 9, 0, 0, :clock=>'+09:00')
64
- p gregorian_date #=> 2014-08-01T09:00:00+09:00
65
- p When.when?('2014-08-01T09:00:00+09:00') #=> 2014-08-01T09:00:00+09:00, the same date
66
- p gregorian_date.to_i #=> 2456871, Julian Day Number(Integer)
67
- p gregorian_date.to_f #=> 2456870.5 at 09:00:00 of Timezone +09:00
68
- p gregorian_date.class #=> When::TM::DateAndTime
69
- p gregorian_date.frame.iri #=> "http://hosi.org/When/CalendarTypes/Gregorian"
70
- p gregorian_date.clk_time.class #=> When::TM::ClockTime
71
- p gregorian_date.clk_time.frame.iri #=> "http://hosi.org/When/TM/Clock?label=+09:00"
72
-
73
- gregorian_date = When.tm_pos(2014, 8, 1, 9, 0, 0, :clock=>'+09:00',
74
- :long=>'139.413012E', :lat=>'35.412222N')
75
- p gregorian_date #=> 2014-08-01T09:00:00+09:00
76
- p gregorian_date.location.iri #=> "http://hosi.org/When/Coordinates/Spatial?long=139.413012E&lat=35.412222N&alt=0"
77
- p gregorian_date.sunrise.floor(When::MINUTE) #=> 2014-08-01T04:48+09:00
78
- p gregorian_date.sunset.floor(When::MINUTE) #=> 2014-08-01T18:46+09:00
79
-
80
- darian_date = When::Darian ^ gregorian_date
81
- p darian_date #=> 0216-13-23T15:12:11MTC
82
- p darian_date.to_i #=> 49974, Serial Day Number(Integer)
83
- p darian_date.to_f #=> 49974.13346485421
84
- p darian_date.frame.iri #=> "http://hosi.org/When/CalendarTypes/Darian"
85
- p darian_date.clk_time.frame.iri #=> "http://hosi.org/When/CalendarTypes/MTC"
86
- p darian_date.time_standard.iri #=> "http://hosi.org/When/TimeStandard/MartianTimeCoordinated?location=(_l:long=0&datum=Mars)"
87
-
88
- # When::TM::CalendarEra
89
-
90
- babylonian_date = When.tm_pos('NebuchadnezzarII', 1, 1, 1)
91
- p babylonian_date #=> NebuchadnezzarII01(-603).01.01
92
- p When.when?('NebuchadnezzarII1.1.1') #=> NebuchadnezzarII01(-603).01.01, the same date
93
- p babylonian_date.to_i #=> 1500904, Julian Day Number(Integer)
94
- p When.era('NebuchadnezzarII') #=> [_e:AncientOrient::Neo-Babylonian::NebuchadnezzarII]
95
- p When.era('NebuchadnezzarII')[0] ^ 1500904 #=> NebuchadnezzarII01(-603).01.01, the same date
96
- p babylonian_date.to_f #=> 1500904.0, at noon for UTC
97
- p babylonian_date.frame.iri #=> "http://hosi.org/When/CalendarTypes/BabylonianPD"
98
- p babylonian_date.calendar_era.iri #=> "http://hosi.org/When/TM/CalendarEra/AncientOrient::Neo-Babylonian::NebuchadnezzarII"
99
-
100
- babylonian_date = When.when?('NebuchadnezzarII1.1.1T18:13:00',
101
- :clock=>'+03:00?long=45&lat=32&border=Sunset')
102
- 4.times do
103
- p [babylonian_date , babylonian_date .to_i] #=>
104
- # [NebuchadnezzarII01(-603).01.01T:18:13:00+03:00, 1500904]
105
- # [NebuchadnezzarII01(-603).01.01T:18:14:00+03:00, 1500904]
106
- # [NebuchadnezzarII01(-603).01.02T*18:15:00+03:00, 1500905]
107
- # [NebuchadnezzarII01(-603).01.02T*18:16:00+03:00, 1500905]
108
- babylonian_date += When::PT1M
109
- end
110
-
111
- # TZInfo
112
- # https://rubygems.org/gems/tzinfo is required for this section's operations.
113
- # Please install tzinfo before operation.
114
-
115
- gregorian_date = When.tm_pos(2014, 8, 1, 9, 0, 0, :tz=>'Asia/Tokyo')
116
- p gregorian_date #=> 2014-08-01T09:00:00+09:00
117
- p gregorian_date.location.iri #=> "http://hosi.org/When/Coordinates/Spatial?long=139.4441E&lat=35.3916N&label=Asia/Tokyo"
118
- p gregorian_date.sunrise.floor(When::MINUTE) #=> 2014-08-01T04:48+09:00
119
- p gregorian_date.sunset.floor(When::MINUTE) #=> 2014-08-01T18:45+09:00
120
-
121
- jst = When.tm_pos(1997, 4, 6, 15, 30, 00, :tz=>'Asia/Tokyo')
122
- p jst #=> 1997-04-06T15:30:00+09:00
123
- est = When.Clock('America/New_York') ^ jst
124
- p est #=> 1997-04-06T01:30:00-05:00
125
- jst = When.tm_pos(1997, 4, 6, 16, 30, 00, :tz=>'Asia/Tokyo')
126
- p jst #=> 1997-04-06T16:30:00+09:00
127
- edt = When.Clock('America/New_York') ^ jst
128
- p edt #=> 1997-04-06T03:30:00-04:00
129
-
130
- p When.when?('TZID=America/New_York:1997-10-26T01:30') #=> 1997-10-26T01:30-04:00
131
- p When.when?('TZID=America/New_York:1997-10-26T01=30') #=> 1997-10-26T01:30-05:00
132
- p When.when?('TZID=America/New_York:1997-10-26T02:30') #=> 1997-10-26T02:30-05:00
133
- p When.when?('TZID=America/New_York:1997-10-26T03:30') #=> 1997-10-26T03:30-05:00
134
-
135
- # Google Calendar
136
- # https://github.com/suchowan/gcalapi is required for this section's operations.
137
- # Please install gcalapi before operation.
138
- # Please replace xxxxxxxx and ******** to valid pair of id and password.
139
-
140
- service = GoogleCalendar::Service.new('xxxxxxxx@gmail.com', '********')
141
- feed = "http://www.google.com/calendar/feeds/%s__%s%%40holiday.calendar.google.com/public/full" %
142
- ['japanese', 'ja']
143
- gcal = GoogleCalendar::Calendar::new(service, feed)
144
- gcal.enum_for({'start-min'=>'2014-01-01', 'start-max'=>'2015-01-01',
145
- 'orderby'=>'starttime', 'sortorder'=>'a'
146
- }).each do |range|
147
- puts '%s - %s' % [range, range.events[0].summary] #=>
148
- # 2014-01-01T00:00:00.00+09:00...2014-01-02T00:00:00.00+09:00 - 元日
149
- # 2014-01-02T00:00:00.00+09:00...2014-01-03T00:00:00.00+09:00 - 銀行休業日
150
- # 2014-01-03T00:00:00.00+09:00...2014-01-04T00:00:00.00+09:00 - 銀行休業日
151
- # 2014-01-13T00:00:00.00+09:00...2014-01-14T00:00:00.00+09:00 - 成人の日
152
- # 2014-02-11T00:00:00.00+09:00...2014-02-12T00:00:00.00+09:00 - 建国記念の日
153
- # 2014-03-21T00:00:00.00+09:00...2014-03-22T00:00:00.00+09:00 - 春分の日
154
- # 2014-04-29T00:00:00.00+09:00...2014-04-30T00:00:00.00+09:00 - 昭和の日
155
- # 2014-05-03T00:00:00.00+09:00...2014-05-04T00:00:00.00+09:00 - 憲法記念日
156
- # 2014-05-04T00:00:00.00+09:00...2014-05-05T00:00:00.00+09:00 - みどりの日
157
- # 2014-05-05T00:00:00.00+09:00...2014-05-06T00:00:00.00+09:00 - こどもの日
158
- # 2014-05-06T00:00:00.00+09:00...2014-05-07T00:00:00.00+09:00 - みどりの日 振替休日
159
- # 2014-07-21T00:00:00.00+09:00...2014-07-22T00:00:00.00+09:00 - 海の日
160
- # 2014-09-15T00:00:00.00+09:00...2014-09-16T00:00:00.00+09:00 - 敬老の日
161
- # 2014-09-23T00:00:00.00+09:00...2014-09-24T00:00:00.00+09:00 - 秋分の日
162
- # 2014-10-13T00:00:00.00+09:00...2014-10-14T00:00:00.00+09:00 - 体育の日
163
- # 2014-11-03T00:00:00.00+09:00...2014-11-04T00:00:00.00+09:00 - 文化の日
164
- # 2014-11-23T00:00:00.00+09:00...2014-11-24T00:00:00.00+09:00 - 勤労感謝の日
165
- # 2014-11-24T00:00:00.00+09:00...2014-11-25T00:00:00.00+09:00 - 勤労感謝の日 振替休日
166
- # 2014-12-23T00:00:00.00+09:00...2014-12-24T00:00:00.00+09:00 - 天皇誕生日
167
- # 2014-12-25T00:00:00.00+09:00...2014-12-26T00:00:00.00+09:00 - クリスマス
168
- # 2014-12-31T00:00:00.00+09:00...2015-01-01T00:00:00.00+09:00 - 大晦日
169
- end
170
-
171
- For further detail, please refer to the [when_exe Wiki](http://www2u.biglobe.ne.jp/~suchowan/when_exe_wiki.html) pages.
1
+ when_exe - A multicultural and multilingualized calendar library
2
+ ================================================================
3
+
4
+ [![Gem Version](https://badge.fury.io/rb/when_exe.svg)](http://badge.fury.io/rb/when_exe)
5
+
6
+ [when_exe](http://rubygems.org/gems/when_exe) is a multicultural and multilingualized calendar library based on [ISO 8601](http://en.wikipedia.org/wiki/ISO_8601), [ISO 19108](http://www.iso.org/iso/home/store/catalogue_tc/catalogue_detail.htm?csnumber=26013), [RFC 5545(iCalendar)](http://tools.ietf.org/html/rfc5545) and [RFC6350](http://tools.ietf.org/html/rfc6350).
7
+
8
+ [<img alt='Architecture' title='display this figure at actual size' src='http://www2u.biglobe.ne.jp/~suchowan/u/pic/architecture.png' width='637' height='408'/>](http://www2u.biglobe.ne.jp/~suchowan/u/pic/architecture.png)
9
+
10
+ Installation
11
+ ------------
12
+
13
+ The when_exe gem can be installed by running:
14
+
15
+ gem install when_exe
16
+
17
+
18
+ Web Server
19
+ ----------
20
+
21
+ Web server for when_exe demonstration is available on [hosi.org](http://hosi.org).
22
+
23
+ You can see examples of [When.exe Standard Representation](http://www.asahi-net.or.jp/~dd6t-sg/when_rdoc/when_en.html#label-8) and Reference System IRI at the top-left corner of Date frame.
24
+
25
+ Preferences are changeable on [hosi.org/cookies](http://hosi.org/cookies).
26
+
27
+
28
+ Documentation
29
+ -------------
30
+
31
+ API documentation for when_exe is available on [RubyDoc.info](http://rubydoc.info/gems/when_exe/frames).
32
+
33
+ Available calendars and clocks are defined as subclasses of TM_Calendar and TM_Clock or using definition tables in [CalendarTypes namespace](http://rubydoc.info/gems/when_exe/frames/When/CalendarTypes).
34
+
35
+ Available calendar eras are defined using definition tables in [CalendarEra namespace](http://rubydoc.info/gems/when_exe/frames/When/TM/CalendarEra).
36
+
37
+ License
38
+ -------
39
+
40
+ This beta version's license is limited. Please see [LICENSE.txt](https://github.com/suchowan/when_exe/blob/master/LICENSE.txt) for details.
41
+
42
+
43
+ Source Code
44
+ -----------
45
+
46
+ Source code for when_exe is available on [GitHub](https://github.com/suchowan/when_exe).
47
+
48
+
49
+ Example Usage
50
+ -------------
51
+
52
+ require 'when_exe'
53
+
54
+ # When::TM::CalDate ---------------------------
55
+
56
+ gregorian_date = When.tm_pos(2014, 8, 1)
57
+ p gregorian_date #=> 2014-08-01
58
+ p When.when?('2014-08-01') #=> 2014-08-01, the same date
59
+ p gregorian_date.to_i #=> 2456871, Julian Day Number(Integer)
60
+ p gregorian_date.to_f #=> 2456871.0, at noon for UTC
61
+ p gregorian_date.class #=> When::TM::CalDate
62
+ p gregorian_date.frame.iri #=> "http://hosi.org/When/CalendarTypes/Gregorian"
63
+ puts gregorian_date.name(When::MONTH).class #=> When::BasicTypes::M17n
64
+ puts gregorian_date.name(When::MONTH).iri #=> http://hosi.org/When/BasicTypes/M17n/Calendar::Month::August
65
+ puts gregorian_date.name(When::MONTH) / 'en' #=> August
66
+ puts gregorian_date.name(When::MONTH) / 'fr' #=> août
67
+ puts gregorian_date.name(When::MONTH) / 'ar' #=> اغسطس
68
+ p gregorian_date.easter #=> 2014-04-20
69
+ p gregorian_date.is?('Easter') #=> false
70
+ p When.tm_pos(2014, 4, 20).is?('Easter') #=> true
71
+
72
+ islamic_date = When::TabularIslamic ^ gregorian_date
73
+ p islamic_date #=> 1435-10-04
74
+ p When.tm_pos(1435, 10, 4, :frame=>'TabularIslamic')
75
+ #=> 1435-10-04, the same date
76
+ p When.when?('1435-10-4^TabularIslamic') #=> 1435-10-04, the same date
77
+ p islamic_date.frame.iri #=> "http://hosi.org/When/CalendarTypes/TabularIslamic"
78
+ puts islamic_date.name(When::MONTH) / 'en' #=> Shawwal
79
+ puts islamic_date.name(When::MONTH) / 'ar' #=> شوال
80
+
81
+ # When::TM::DateAndTime ------------------------
82
+
83
+ gregorian_date = When.tm_pos(2014, 8, 1, 9, 0, 0, :clock=>'+09:00')
84
+ p gregorian_date #=> 2014-08-01T09:00:00+09:00
85
+ p When.when?('2014-08-01T09:00:00+09:00') #=> 2014-08-01T09:00:00+09:00, the same date
86
+ p gregorian_date.to_i #=> 2456871, Julian Day Number(Integer)
87
+ p gregorian_date.to_f #=> 2456870.5 at 09:00:00 of Timezone +09:00
88
+ p gregorian_date.class #=> When::TM::DateAndTime
89
+ p gregorian_date.frame.iri #=> "http://hosi.org/When/CalendarTypes/Gregorian"
90
+ p gregorian_date.clk_time.class #=> When::TM::ClockTime
91
+ p gregorian_date.clk_time.frame.iri #=> "http://hosi.org/When/TM/Clock?label=+09:00"
92
+
93
+ gregorian_date = When.tm_pos(2014, 8, 1, 9, 0, 0, :clock=>'+09:00',
94
+ :long=>'139.413012E', :lat=>'35.412222N')
95
+ p gregorian_date #=> 2014-08-01T09:00:00+09:00
96
+ p gregorian_date.location.iri #=> "http://hosi.org/When/Coordinates/Spatial?long=139.413012E&lat=35.412222N&alt=0"
97
+ p gregorian_date.sunrise.floor(When::MINUTE) #=> 2014-08-01T04:48+09:00
98
+ p gregorian_date.sunset.floor(When::MINUTE) #=> 2014-08-01T18:46+09:00
99
+
100
+ darian_date = When::Darian ^ gregorian_date
101
+ p darian_date #=> 0216-13-23T15:12:11MTC
102
+ p darian_date.to_i #=> 49974, Serial Day Number(Integer)
103
+ p darian_date.to_f #=> 49974.13346485421
104
+ p darian_date.frame.iri #=> "http://hosi.org/When/CalendarTypes/Darian"
105
+ p darian_date.clk_time.frame.iri #=> "http://hosi.org/When/CalendarTypes/MTC"
106
+ p darian_date.time_standard.iri #=> "http://hosi.org/When/TimeStandard/MartianTimeCoordinated?location=(_l:long=0&datum=Mars)"
107
+
108
+ # When::TM::CalendarEra ------------------------
109
+
110
+ babylonian_date = When.tm_pos('NebuchadnezzarII', 1, 1, 1)
111
+ p babylonian_date #=> NebuchadnezzarII01(-603).01.01
112
+ p When.when?('NebuchadnezzarII1.1.1') #=> NebuchadnezzarII01(-603).01.01, the same date
113
+ p babylonian_date.to_i #=> 1500904, Julian Day Number(Integer)
114
+ p When.era('NebuchadnezzarII') #=> [_e:AncientOrient::Neo-Babylonian::NebuchadnezzarII]
115
+ p When.era('NebuchadnezzarII')[0] ^ 1500904 #=> NebuchadnezzarII01(-603).01.01, the same date
116
+ p babylonian_date.to_f #=> 1500904.0, at noon for UTC
117
+ p babylonian_date.frame.iri #=> "http://hosi.org/When/CalendarTypes/BabylonianPD"
118
+ p babylonian_date.calendar_era.iri #=> "http://hosi.org/When/TM/CalendarEra/AncientOrient::Neo-Babylonian::NebuchadnezzarII"
119
+
120
+ babylonian_date = When.when?('NebuchadnezzarII1.1.1T18:13:00',
121
+ :clock=>'+03:00?long=45&lat=32&border=Sunset')
122
+ 4.times do
123
+ p [babylonian_date, babylonian_date.to_i] #=>
124
+ # [NebuchadnezzarII01(-603).01.01T:18:13:00+03:00, 1500904]
125
+ # [NebuchadnezzarII01(-603).01.01T:18:14:00+03:00, 1500904]
126
+ # [NebuchadnezzarII01(-603).01.02T*18:15:00+03:00, 1500905]
127
+ # [NebuchadnezzarII01(-603).01.02T*18:16:00+03:00, 1500905]
128
+ babylonian_date += When::PT1M
129
+ end
130
+
131
+ # Web service ----------------------------------
132
+ # retrieve JSON response from http://hosi.org:3000 (when_exe demonstration web server)
133
+ require 'open-uri'
134
+ open('http://hosi.org:3000/Date/2014-04-20.json') do |json|
135
+ puts json.read #=> newlines and blanks are inserted for readability.
136
+ # {"frame" : "http://hosi.org/When/CalendarTypes/Gregorian",
137
+ # "precision": 0,
138
+ # "location" : "http://hosi.org/When/Coordinates/Spatial?long=139.4441E&lat=35.3916N&alt=0.0",
139
+ # "sdn" : 2456768,
140
+ # "calendar" : ["http://hosi.org/When/CalendarTypes/Gregorian"],
141
+ # "notes" : [[{"note":"Month","value":"April"}],
142
+ # [{"note":"Week","value":"Sunday(6)"}]],
143
+ # "clock" : "Asia/Tokyo+09:00",
144
+ # "clk_time" : [2456768,0,0,0],
145
+ # "dynamical": 1397919667.184082,
146
+ # "universal": 1397919600.0,
147
+ # "cal_date" : [2014,4,20]}
148
+ end
149
+
150
+ # TZInfo --------------------------------------
151
+ # https://rubygems.org/gems/tzinfo is required for this section's operations.
152
+ # Please install tzinfo before operation.
153
+
154
+ gregorian_date = When.tm_pos(2014, 8, 1, 9, 0, 0, :tz=>'Asia/Tokyo')
155
+ p gregorian_date #=> 2014-08-01T09:00:00+09:00
156
+ p gregorian_date.location.iri #=> "http://hosi.org/When/Coordinates/Spatial?long=139.4441E&lat=35.3916N&label=Asia/Tokyo"
157
+ p gregorian_date.sunrise.floor(When::MINUTE) #=> 2014-08-01T04:48+09:00
158
+ p gregorian_date.sunset.floor(When::MINUTE) #=> 2014-08-01T18:45+09:00
159
+
160
+ jst = When.tm_pos(1997, 4, 6, 15, 30, 00, :tz=>'Asia/Tokyo')
161
+ p jst #=> 1997-04-06T15:30:00+09:00
162
+ est = When.Clock('America/New_York') ^ jst
163
+ p est #=> 1997-04-06T01:30:00-05:00
164
+ jst = When.tm_pos(1997, 4, 6, 16, 30, 00, :tz=>'Asia/Tokyo')
165
+ p jst #=> 1997-04-06T16:30:00+09:00
166
+ edt = When.Clock('America/New_York') ^ jst
167
+ p edt #=> 1997-04-06T03:30:00-04:00
168
+
169
+ p When.when?('TZID=America/New_York:1997-10-26T01:30') #=> 1997-10-26T01:30-04:00
170
+ p When.when?('TZID=America/New_York:1997-10-26T01=30') #=> 1997-10-26T01:30-05:00, '=' indicates "leep hour"
171
+ p When.when?('TZID=America/New_York:1997-10-26T02:30') #=> 1997-10-26T02:30-05:00
172
+ p When.when?('TZID=America/New_York:1997-10-26T03:30') #=> 1997-10-26T03:30-05:00
173
+
174
+ # Google Calendar ------------------------------
175
+ # https://github.com/suchowan/gcalapi is required for this section's operations.
176
+ # Please install gcalapi before operation.
177
+ # Please replace xxxxxxxx and ******** to valid id/password pair and access Google Calendar.
178
+
179
+ service = GoogleCalendar::Service.new('xxxxxxxx@gmail.com', '********')
180
+ feed = "http://www.google.com/calendar/feeds/%s__%s%%40holiday.calendar.google.com/public/full" %
181
+ ['japanese', 'ja']
182
+ gcal = GoogleCalendar::Calendar::new(service, feed)
183
+ gcal.enum_for({'start-min'=>'2014-01-01', 'start-max'=>'2015-01-01',
184
+ 'orderby'=>'starttime', 'sortorder'=>'a'
185
+ }).each do |range|
186
+ puts '%s - %s' % [range, range.events[0].summary] #=>
187
+ # 2014-01-01T00:00:00.00+09:00...2014-01-02T00:00:00.00+09:00 - 元日
188
+ # 2014-01-02T00:00:00.00+09:00...2014-01-03T00:00:00.00+09:00 - 銀行休業日
189
+ # 2014-01-03T00:00:00.00+09:00...2014-01-04T00:00:00.00+09:00 - 銀行休業日
190
+ # 2014-01-13T00:00:00.00+09:00...2014-01-14T00:00:00.00+09:00 - 成人の日
191
+ # 2014-02-11T00:00:00.00+09:00...2014-02-12T00:00:00.00+09:00 - 建国記念の日
192
+ # 2014-03-21T00:00:00.00+09:00...2014-03-22T00:00:00.00+09:00 - 春分の日
193
+ # 2014-04-29T00:00:00.00+09:00...2014-04-30T00:00:00.00+09:00 - 昭和の日
194
+ # 2014-05-03T00:00:00.00+09:00...2014-05-04T00:00:00.00+09:00 - 憲法記念日
195
+ # 2014-05-04T00:00:00.00+09:00...2014-05-05T00:00:00.00+09:00 - みどりの日
196
+ # 2014-05-05T00:00:00.00+09:00...2014-05-06T00:00:00.00+09:00 - こどもの日
197
+ # 2014-05-06T00:00:00.00+09:00...2014-05-07T00:00:00.00+09:00 - みどりの日 振替休日
198
+ # 2014-07-21T00:00:00.00+09:00...2014-07-22T00:00:00.00+09:00 - 海の日
199
+ # 2014-09-15T00:00:00.00+09:00...2014-09-16T00:00:00.00+09:00 - 敬老の日
200
+ # 2014-09-23T00:00:00.00+09:00...2014-09-24T00:00:00.00+09:00 - 秋分の日
201
+ # 2014-10-13T00:00:00.00+09:00...2014-10-14T00:00:00.00+09:00 - 体育の日
202
+ # 2014-11-03T00:00:00.00+09:00...2014-11-04T00:00:00.00+09:00 - 文化の日
203
+ # 2014-11-23T00:00:00.00+09:00...2014-11-24T00:00:00.00+09:00 - 勤労感謝の日
204
+ # 2014-11-24T00:00:00.00+09:00...2014-11-25T00:00:00.00+09:00 - 勤労感謝の日 振替休日
205
+ # 2014-12-23T00:00:00.00+09:00...2014-12-24T00:00:00.00+09:00 - 天皇誕生日
206
+ # 2014-12-25T00:00:00.00+09:00...2014-12-26T00:00:00.00+09:00 - クリスマス
207
+ # 2014-12-31T00:00:00.00+09:00...2015-01-01T00:00:00.00+09:00 - 大晦日
208
+ end
209
+
210
+ For further detail, please refer to the [when_exe Wiki](http://www2u.biglobe.ne.jp/~suchowan/when_exe_wiki.html) pages.
data/bin/irb.rc CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'pp'
2
+ require 'date'
2
3
  require 'when_exe'
3
4
  require 'when_exe/core/extension'
4
5
  require 'when_exe/mini_application'
data/lib/when_exe.rb CHANGED
@@ -187,20 +187,49 @@ module When
187
187
  # Module Constants
188
188
  #
189
189
 
190
+ # 1 second period duration
190
191
  PT1S = TM::PeriodDuration.new(nil,[0,0,0,1])
192
+
193
+ # 1 minute period duration
191
194
  PT1M = TM::PeriodDuration.new(nil,[0,0,1,0])
195
+
196
+ # 1 hour period duration
192
197
  PT1H = TM::PeriodDuration.new(nil,[0,1,0,0])
198
+
199
+ # 1 day period duration
193
200
  P1D = TM::PeriodDuration.new([0,0,1])
201
+
202
+ # 1 week period duration
194
203
  P1W = TM::PeriodDuration.new([0,0,7])
204
+
205
+ # 1 month period duration
195
206
  P1M = TM::PeriodDuration.new([0,1,0])
207
+
208
+ # 1 year period duration
196
209
  P1Y = TM::PeriodDuration.new([1,0,0])
210
+
211
+ # kind of When::TM::Position or When::TM::TemporalPosition
197
212
  TimeValue = TM::IndeterminateValue
198
213
 
214
+ # 7 days week residue
215
+ Week = When::Parts::Resource._instance('_co:Common::Week')
216
+
217
+ # Gregorian months
218
+ Month = When::Parts::Resource._instance('_m:Calendar::Month')
219
+
220
+ # + ∞
199
221
  PlusInfinity = TM::TemporalPosition.new({:indeterminated_position=>TimeValue::Max})
222
+
223
+ # - ∞
200
224
  MinusInfinity = TM::TemporalPosition.new({:indeterminated_position=>TimeValue::Min})
201
225
 
226
+ # UTF-8 encoding
202
227
  UTF8 = '.UTF-8'
228
+
229
+ # Windows-31J encoding
203
230
  W31J = '.Windows-31J'
231
+
232
+ # eucJP encoding
204
233
  EUCJP = '.eucJP'
205
234
 
206
235
  class BasicTypes::M17n
@@ -221,8 +250,17 @@ module When
221
250
  autoload :Coptic, 'when_exe/region/coptic'
222
251
  autoload :French, 'when_exe/region/french'
223
252
  autoload :World, 'when_exe/region/world'
253
+ autoload :Positivist, 'when_exe/region/positivist'
254
+ autoload :InternationalFixed, 'when_exe/region/international_fixed'
255
+ autoload :WorldSeason, 'when_exe/region/world_season'
256
+ autoload :Tranquility, 'when_exe/region/tranquility'
257
+ autoload :Pax, 'when_exe/region/pax'
258
+ autoload :HankeHenry, 'when_exe/region/hanke_henry'
224
259
  autoload :Shire, 'when_exe/region/shire'
260
+ autoload :Dee, 'when_exe/region/dee'
261
+ autoload :VanishingLeprechaun, 'when_exe/region/vanishing_leprechaun'
225
262
  autoload :Yerm, 'when_exe/region/yerm'
263
+ autoload :Goddess, 'when_exe/region/goddess'
226
264
  autoload :Martian, 'when_exe/region/martian'
227
265
  autoload :WeekDate, 'when_exe/region/weekdate'
228
266
  end
@@ -283,14 +321,20 @@ module When
283
321
  autoload :FrenchRepublican, 'when_exe/region/french'
284
322
  autoload :World, 'when_exe/region/world'
285
323
  autoload :LongCount, 'when_exe/region/mayan'
324
+ autoload :Positivist, 'when_exe/region/positivist'
325
+ autoload :InternationalFixed, 'when_exe/region/international_fixed'
326
+ autoload :WorldSeason, 'when_exe/region/world_season'
327
+ autoload :Pax, 'when_exe/region/pax'
328
+ autoload :Tranquility, 'when_exe/region/tranquility'
329
+ autoload :HankeHenry, 'when_exe/region/hanke_henry'
286
330
  autoload :Discordian, 'when_exe/region/discordian'
287
331
  autoload :Shire, 'when_exe/region/shire'
288
- autoload :ShireG, 'when_exe/region/shire'
289
332
  autoload :Sym454, 'when_exe/region/symmetry'
290
333
  autoload :Sym010, 'when_exe/region/symmetry'
291
- autoload :Yerm, 'when_exe/region/yerm'
292
334
  autoload :Dee, 'when_exe/region/dee'
293
335
  autoload :DeeCecil, 'when_exe/region/dee'
336
+ autoload :VanishingLeprechaun, 'when_exe/region/vanishing_leprechaun'
337
+ autoload :Yerm, 'when_exe/region/yerm'
294
338
  autoload :Goddess, 'when_exe/region/goddess'
295
339
  autoload :Darian, 'when_exe/region/martian'
296
340
  autoload :WeekDate, 'when_exe/region/weekdate'
@@ -328,6 +372,10 @@ module When
328
372
  autoload :SovietSixDayWeek, 'when_exe/region/soviet'
329
373
  # autoload :Yerm, 'when_exe/region/yerm'
330
374
  autoload :WorldWeek, 'when_exe/region/world'
375
+ autoload :PositivistWeek, 'when_exe/region/positivist'
376
+ autoload :InternationalFixedWeek, 'when_exe/region/international_fixed'
377
+ autoload :TranquilityWeek, 'when_exe/region/tranquility'
378
+ autoload :WorldSeasonWeek, 'when_exe/region/world_season'
331
379
  autoload :ShireWeek, 'when_exe/region/shire'
332
380
 
333
381
  Default = [['_m:Calendar::Month'], ['Common::Week']]
@@ -461,15 +509,15 @@ module When
461
509
  # フォーマットごとの処理
462
510
  case specification
463
511
  when TM::TemporalPosition, Parts::GeometricComplex ; specification
464
- when TM::Position ; specification.any_other
465
- when Array ; begin options = TM::TemporalPosition._options(options) ; specification.map {|e| when?(e, options)} end
466
- when /\Atoday\z/i ; today(options)
467
- when /\Anow\z/i ; now(options)
468
- when /[JS]DN(\z|\^)/i; TM::JulianDate.parse(specification, options)
469
- when /[\n\r]+/ ; when?(specification.split(/[\n\r]+/), options)
470
- when String ; TM::TemporalPosition._instance(EncodingConversion.to_internal_encoding(specification), options)
471
- when Numeric ; TM::JulianDate.new(+specification, TM::TemporalPosition._options(options))
472
- else ; Calendar(options[:frame] || 'Gregorian').jul_trans(specification, options)
512
+ when TM::Position ; specification.any_other
513
+ when Array ; begin options = TM::TemporalPosition._options(options) ; specification.map {|e| when?(e, options)} end
514
+ when /\Atoday\z/i ; today(options)
515
+ when /\Anow\z/i ; now(options)
516
+ when /(JDN|MJD|SDN|CEP)(\z|\^)/i; TM::JulianDate.parse(specification, options)
517
+ when /[\n\r]+/ ; when?(specification.split(/[\n\r]+/), options)
518
+ when String ; TM::TemporalPosition._instance(EncodingConversion.to_internal_encoding(specification), options)
519
+ when Numeric ; TM::JulianDate.new(+specification, TM::TemporalPosition._options(options))
520
+ else ; Calendar(options[:frame] || 'Gregorian').jul_trans(specification, options)
473
521
  end
474
522
  end
475
523
 
@@ -492,48 +540,7 @@ module When
492
540
  # options[ :invalid ] が :raise で、日時が存在しない場合
493
541
  #
494
542
  def TemporalPosition(*args)
495
- # 引数の解釈
496
- options = args[-1].kind_of?(Hash) ? args.pop.dup : {}
497
- validate = options.delete(:invalid)
498
- options = TM::TemporalPosition._options(options)
499
- options[:frame] ||= 'Gregorian'
500
- options[:frame] = Resource(options[:frame], '_c:') if options[:frame].kind_of?(String)
501
- case args[0]
502
- when String
503
- options[:era_name] = EncodingConversion.to_internal_encoding(args.shift)
504
- when Array
505
- options[:era_name] = args.shift
506
- options[:era_name][0] = EncodingConversion.to_internal_encoding(options[:era_name][0])
507
- end
508
-
509
- # 時間位置の生成
510
- date = Array.new(options[:frame].indices.length+1) {args.shift}
511
- if (args.length > 0)
512
- options[:clock] ||= TM::Clock.local_time
513
- options[:clock] = Clock(options[:clock])
514
- time = Array.new(options[:clock].indices.length) {args.shift}
515
- position = TM::DateAndTime.new(date, time.unshift(0), options)
516
- else
517
- position = TM::CalDate.new(date, options)
518
- end
519
- return position unless [:raise, :check].include?(validate)
520
-
521
- # 時間位置の存在確認
522
- date[0] = -date[0] if position.calendar_era_name && position.calendar_era_name[2] # 紀元前
523
- date.each_index do |i|
524
- break unless date[i]
525
- next if Coordinates::Pair._force_pair(date[i]) == Coordinates::Pair._force_pair(position.cal_date[i])
526
- return nil if validate == :check
527
- raise ArgumentError, "Specified date not found: #{date}"
528
- end
529
- return position unless time
530
- time.each_index do |i|
531
- break unless time[i]
532
- next if Coordinates::Pair._force_pair(time[i]) == Coordinates::Pair._force_pair(position.clk_time.clk_time[i])
533
- return nil if validate == :check
534
- raise ArgumentError, "Specified time not found: #{time}"
535
- end
536
- return position
543
+ TM::TemporalPosition._temporal_position(*args)
537
544
  end
538
545
 
539
546
  alias :tm_pos :TemporalPosition
@@ -760,6 +767,24 @@ module When
760
767
  Parts::Resource._instance(iri)
761
768
  end
762
769
 
770
+ # When::Coordinates::Border の生成/参照
771
+ #
772
+ # @param [String] border 年/日境界を表す文字列
773
+ #
774
+ # @return [When::Coordinates::Border] border に対応する When::Coordinates::Border オブジェクト
775
+ #
776
+ def Border(border)
777
+ case border
778
+ when Coordinates::Border ; return border
779
+ when /\([-\d]+?\)/ ; border = "_co:MultiBorder?borders=#{border}"
780
+ when /\A[^A-Z_]/i ; border = "_co:Border?border=#{border}"
781
+ end
782
+
783
+ Parts::Resource._instance(border, '_co:') do |iri|
784
+ Coordinates::CalendarBorder.send(:_behalf_of, iri)
785
+ end
786
+ end
787
+
763
788
  #
764
789
  # 曜日(剰余類)
765
790
  #