when_exe 0.2.100 → 0.3.1

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 (193) hide show
  1. data/LICENSE.ja.txt +25 -25
  2. data/LICENSE.txt +31 -31
  3. data/bin/irb.rc +5 -0
  4. data/bin/locales.rb +2 -2
  5. data/bin/when.rb +16 -0
  6. data/bin/when.rb.config +7 -0
  7. data/lib/when_exe.rb +616 -14
  8. data/lib/when_exe/basictypes.rb +615 -0
  9. data/lib/when_exe/calendartypes.rb +1700 -0
  10. data/lib/when_exe/coordinates.rb +1936 -0
  11. data/lib/when_exe/core/compatibility.rb +54 -0
  12. data/lib/when_exe/core/duration.rb +72 -72
  13. data/lib/when_exe/core/extension.rb +382 -0
  14. data/lib/when_exe/ephemeris.rb +1845 -0
  15. data/lib/when_exe/googlecalendar.rb +140 -0
  16. data/lib/when_exe/icalendar.rb +1587 -0
  17. data/lib/when_exe/inspect.rb +1237 -0
  18. data/lib/when_exe/locales/af.rb +90 -0
  19. data/lib/when_exe/locales/ar.rb +145 -0
  20. data/lib/when_exe/locales/az.rb +90 -0
  21. data/lib/when_exe/locales/bg.rb +90 -0
  22. data/lib/when_exe/locales/bn.rb +94 -0
  23. data/lib/when_exe/locales/bs.rb +121 -0
  24. data/lib/when_exe/locales/ca.rb +92 -0
  25. data/lib/when_exe/locales/cs.rb +107 -0
  26. data/lib/when_exe/locales/cy.rb +150 -0
  27. data/lib/when_exe/locales/da.rb +84 -0
  28. data/lib/when_exe/locales/de.rb +92 -0
  29. data/lib/when_exe/locales/de_AT.rb +92 -0
  30. data/lib/when_exe/locales/de_CH.rb +92 -0
  31. data/lib/when_exe/locales/el.rb +93 -0
  32. data/lib/when_exe/locales/en.rb +88 -0
  33. data/lib/when_exe/locales/en_AU.rb +88 -0
  34. data/lib/when_exe/locales/en_CA.rb +88 -0
  35. data/lib/when_exe/locales/en_GB.rb +88 -0
  36. data/lib/when_exe/locales/en_IN.rb +88 -0
  37. data/lib/when_exe/locales/en_NZ.rb +88 -0
  38. data/lib/when_exe/locales/eo.rb +89 -0
  39. data/lib/when_exe/locales/es.rb +84 -0
  40. data/lib/when_exe/locales/es_419.rb +84 -0
  41. data/lib/when_exe/locales/es_AR.rb +84 -0
  42. data/lib/when_exe/locales/es_CL.rb +84 -0
  43. data/lib/when_exe/locales/es_CO.rb +84 -0
  44. data/lib/when_exe/locales/es_MX.rb +84 -0
  45. data/lib/when_exe/locales/es_PE.rb +85 -0
  46. data/lib/when_exe/locales/es_VE.rb +84 -0
  47. data/lib/when_exe/locales/et.rb +94 -0
  48. data/lib/when_exe/locales/eu.rb +95 -0
  49. data/lib/when_exe/locales/fa.rb +80 -0
  50. data/lib/when_exe/locales/fi.rb +89 -0
  51. data/lib/when_exe/locales/fr.rb +88 -0
  52. data/lib/when_exe/locales/fr_CA.rb +88 -0
  53. data/lib/when_exe/locales/fr_CH.rb +88 -0
  54. data/lib/when_exe/locales/gl.rb +81 -0
  55. data/lib/when_exe/locales/he.rb +84 -0
  56. data/lib/when_exe/locales/hi.rb +80 -0
  57. data/lib/when_exe/locales/hi_IN.rb +84 -0
  58. data/lib/when_exe/locales/hr.rb +128 -0
  59. data/lib/when_exe/locales/hu.rb +84 -0
  60. data/lib/when_exe/locales/id.rb +89 -0
  61. data/lib/when_exe/locales/is.rb +89 -0
  62. data/lib/when_exe/locales/it.rb +87 -0
  63. data/lib/when_exe/locales/it_CH.rb +87 -0
  64. data/lib/when_exe/locales/ja.rb +78 -0
  65. data/lib/when_exe/locales/kn.rb +86 -0
  66. data/lib/when_exe/locales/ko.rb +78 -0
  67. data/lib/when_exe/locales/links.rb +2342 -0
  68. data/lib/when_exe/locales/lo.rb +123 -0
  69. data/lib/when_exe/locales/locales.rb +91 -0
  70. data/lib/when_exe/locales/lt.rb +111 -0
  71. data/lib/when_exe/locales/lv.rb +118 -0
  72. data/lib/when_exe/locales/mk.rb +93 -0
  73. data/lib/when_exe/locales/mn.rb +80 -0
  74. data/lib/when_exe/locales/nb.rb +81 -0
  75. data/lib/when_exe/locales/ne.rb +81 -0
  76. data/lib/when_exe/locales/nl.rb +92 -0
  77. data/lib/when_exe/locales/nn.rb +73 -0
  78. data/lib/when_exe/locales/or.rb +84 -0
  79. data/lib/when_exe/locales/pl.rb +128 -0
  80. data/lib/when_exe/locales/pt.rb +88 -0
  81. data/lib/when_exe/locales/pt_BR.rb +88 -0
  82. data/lib/when_exe/locales/rm.rb +143 -0
  83. data/lib/when_exe/locales/ro.rb +105 -0
  84. data/lib/when_exe/locales/ru.rb +128 -0
  85. data/lib/when_exe/locales/sk.rb +109 -0
  86. data/lib/when_exe/locales/sl.rb +122 -0
  87. data/lib/when_exe/locales/sr.rb +122 -0
  88. data/lib/when_exe/locales/sv.rb +83 -0
  89. data/lib/when_exe/locales/sw.rb +89 -0
  90. data/lib/when_exe/locales/th.rb +78 -0
  91. data/lib/when_exe/locales/tl.rb +99 -0
  92. data/lib/when_exe/locales/tr.rb +96 -0
  93. data/lib/when_exe/locales/uk.rb +128 -0
  94. data/lib/when_exe/locales/uz.rb +128 -0
  95. data/lib/when_exe/locales/vi.rb +94 -0
  96. data/lib/when_exe/locales/wo.rb +82 -0
  97. data/lib/when_exe/locales/zh_CN.rb +77 -0
  98. data/lib/when_exe/locales/zh_HK.rb +77 -0
  99. data/lib/when_exe/locales/zh_TW.rb +77 -0
  100. data/lib/when_exe/mini_application.rb +252 -0
  101. data/lib/when_exe/parts/enumerator.rb +472 -0
  102. data/lib/when_exe/parts/geometric_complex.rb +379 -0
  103. data/lib/when_exe/parts/locale.rb +513 -0
  104. data/lib/when_exe/parts/method_cash.rb +207 -0
  105. data/lib/when_exe/parts/resource.rb +806 -0
  106. data/lib/when_exe/parts/timezone.rb +182 -0
  107. data/lib/when_exe/region/bahai.rb +145 -0
  108. data/lib/when_exe/region/balinese.rb +627 -0
  109. data/lib/when_exe/region/chinese.rb +896 -0
  110. data/lib/when_exe/region/chinese_calendar.rb +919 -0
  111. data/lib/when_exe/region/chinese_epoch.rb +1245 -0
  112. data/lib/when_exe/region/christian.rb +644 -0
  113. data/lib/when_exe/region/far_east.rb +192 -0
  114. data/lib/when_exe/region/french.rb +66 -0
  115. data/lib/when_exe/region/geologicalage.rb +639 -0
  116. data/lib/when_exe/region/indian.rb +1066 -0
  117. data/lib/when_exe/region/iranian.rb +66 -0
  118. data/lib/when_exe/region/islamic.rb +105 -0
  119. data/lib/when_exe/region/japanese.rb +851 -0
  120. data/lib/when_exe/region/japanese_notes.rb +964 -0
  121. data/lib/when_exe/region/japanese_residues.rb +1149 -0
  122. data/lib/when_exe/region/javanese.rb +228 -0
  123. data/lib/when_exe/region/jewish.rb +127 -0
  124. data/lib/when_exe/region/korean.rb +267 -0
  125. data/lib/when_exe/region/m17n.rb +115 -0
  126. data/lib/when_exe/region/martian.rb +215 -0
  127. data/lib/when_exe/region/mayan.rb +122 -0
  128. data/lib/when_exe/region/moon.rb +333 -0
  129. data/lib/when_exe/region/nihon_shoki.rb +73 -0
  130. data/lib/when_exe/region/planets.rb +585 -0
  131. data/lib/when_exe/region/pope.rb +298 -0
  132. data/lib/when_exe/region/residue.rb +229 -0
  133. data/lib/when_exe/region/roman.rb +325 -0
  134. data/lib/when_exe/region/ryukyu.rb +98 -0
  135. data/lib/when_exe/region/shire.rb +254 -0
  136. data/lib/when_exe/region/sun.rb +210 -0
  137. data/lib/when_exe/region/thai.rb +227 -0
  138. data/lib/when_exe/region/tibetan.rb +233 -0
  139. data/lib/when_exe/region/v50.rb +111 -0
  140. data/lib/when_exe/region/vietnamese.rb +173 -0
  141. data/lib/when_exe/region/world.rb +197 -0
  142. data/lib/when_exe/timestandard.rb +547 -0
  143. data/lib/when_exe/tmduration.rb +330 -330
  144. data/lib/when_exe/tmobjects.rb +1295 -0
  145. data/lib/when_exe/tmposition.rb +1955 -0
  146. data/lib/when_exe/tmreference.rb +1547 -0
  147. data/lib/when_exe/version.rb +10 -3
  148. data/link_to_online_documents +4 -0
  149. data/test/examples/JapanHolidays.ics +456 -0
  150. data/test/examples/Millennium.ics +17 -0
  151. data/test/examples/NewYork.ics +61 -0
  152. data/test/examples/Residue.m17n +135 -0
  153. data/test/examples/Spatial.m17n +179 -0
  154. data/test/examples/Terms.m17n +39 -0
  155. data/test/examples/Test.ics +53 -0
  156. data/test/examples/USA-DST.ics +61 -0
  157. data/test/examples/geometric_complex.rb +41 -0
  158. data/test/examples/sample.xml +14 -0
  159. data/test/examples/today.rb +61 -0
  160. data/test/test.rb +54 -19
  161. data/test/test.rb.config +1 -0
  162. data/test/test/basictypes.rb +368 -0
  163. data/test/test/calendartypes.rb +57 -0
  164. data/test/test/coordinates.rb +380 -0
  165. data/test/test/ephemeris.rb +127 -0
  166. data/test/test/googlecalendar.rb +167 -0
  167. data/test/test/icalendar.rb +848 -0
  168. data/test/test/inspect.rb +115 -0
  169. data/test/test/parts.rb +480 -0
  170. data/test/test/region/chinese.rb +161 -0
  171. data/test/test/region/french.rb +33 -0
  172. data/test/test/region/geologicalage.rb +14 -0
  173. data/test/test/region/indian.rb +55 -0
  174. data/test/test/region/iran.rb +54 -0
  175. data/test/test/region/islamic.rb +18 -0
  176. data/test/test/region/japanese.rb +62 -0
  177. data/test/test/region/jewish.rb +61 -0
  178. data/test/test/region/m17n.rb +181 -0
  179. data/test/test/region/mayan.rb +78 -0
  180. data/test/test/region/moon.rb +14 -0
  181. data/test/test/region/planets.rb +14 -0
  182. data/test/test/region/residue.rb +123 -0
  183. data/test/test/region/sun.rb +14 -0
  184. data/test/test/region/thai.rb +94 -0
  185. data/test/test/region/tibetan.rb +30 -0
  186. data/test/test/tmobjects.rb +356 -57
  187. data/test/test/tmposition.rb +237 -0
  188. data/test/test/tmreference.rb +95 -0
  189. data/when_exe.gemspec +2 -2
  190. metadata +187 -7
  191. data/doc/COPYING +0 -31
  192. data/doc/COPYING.ja +0 -25
  193. data/doc/document_url +0 -1
@@ -0,0 +1,30 @@
1
+ # -*- coding: utf-8 -*-
2
+ =begin
3
+ Copyright (C) 2011 Takashi SUGA
4
+
5
+ You may use and/or modify this file according to the license
6
+ described in the LICENSE.txt file included in this archive.
7
+ =end
8
+
9
+ module Test
10
+
11
+ class Tibetan < Test::Unit::TestCase
12
+ Sample = [
13
+ "1991-05-01-", "1991-05-02-", "1991-05-03-", "1991-05-04-", "1991-05-05%", "1991-05-07-", "1991-05-08-", "1991-05-09-",
14
+ "1991-05-10-", "1991-05-11-", "1991-05-12-", "1991-05-13-", "1991-05-14-", "1991-05-15-", "1991-05-15=", "1991-05-16-",
15
+ "1991-05-17-", "1991-05-18-", "1991-05-19-", "1991-05-20-", "1991-05-21-", "1991-05-22-", "1991-05-23-", "1991-05-24-",
16
+ "1991-05-25-", "1991-05-26-", "1991-05-27-", "1991-05-28%", "1991-05-30-"
17
+ ]
18
+
19
+ def test_tibetan_date
20
+ cc = When.Resource('_c:Tibetan')
21
+ date = When.when?('1991-05-01', {:frame=>cc})
22
+ start = 2448421
23
+ Sample.size.times do |i|
24
+ assert_equal([Sample[i], start+i], [date.to_s, date.to_i])
25
+ date += When.Duration('P1D')
26
+ end
27
+ end
28
+ end
29
+ end
30
+
@@ -1,57 +1,356 @@
1
- # -*- coding: utf-8 -*-
2
- =begin
3
- Copyright (C) 2011-2013 Takashi SUGA
4
-
5
- You may use and/or modify this file according to the license
6
- described in the COPYING file included in this archive.
7
- =end
8
-
9
- module Test::TM
10
- class Duration < Test::Unit::TestCase
11
- def test__duration_constructors
12
- assert_equal( 1, When::TM::Duration.new(1).duration)
13
- assert_equal( 1.0/128, When::TM::Duration.second(1).duration)
14
- assert_equal( 60.0/128, When::TM::Duration.minute(1).duration)
15
- assert_equal( 3600.0/128, When::TM::Duration.hour(1).duration)
16
- assert_equal(86400.0/128, When::TM::Duration.day(1).duration)
17
- assert_equal(93784.0/128, When::TM::Duration.dhms(1,2,3,4).duration)
18
- end
19
-
20
- def test__duration_values
21
- assert_equal(1, When::TM::Duration.new(1).system)
22
- assert_equal(2, When::TM::Duration.second(2).second)
23
- assert_equal(3, When::TM::Duration.minute(3).minute)
24
- assert_equal(4, When::TM::Duration.hour(4).hour)
25
- assert_equal(5, When::TM::Duration.day(5).day)
26
- assert_equal([1,2,3,4], When::TM::Duration.dhms(1,2,3,4).to_dhms)
27
- assert_equal([-2,21,56,56], (-When::TM::Duration.dhms(1,2,3,4)).to_dhms)
28
- end
29
-
30
- def test__duration_elements
31
- duration = When::TM::Duration.dhms(1,2,3,4.5)
32
- assert_equal(1, duration[0])
33
- assert_equal(2, duration[1])
34
- assert_equal(3, duration[2])
35
- assert_equal(4.5, duration[3])
36
- end
37
-
38
- def test__duration_arithmetics
39
- assert_equal(When::TM::Duration.dhms(-2,21,56,56), -When::TM::Duration.dhms(1,2,3,4))
40
- assert_equal(When::TM::Duration.dhms(2,3,4,5), When::TM::Duration.dhms(1,2,3,4) + When::TM::Duration.dhms(1,1,1,1))
41
- assert_equal(When::TM::Duration.dhms(0,1,2,3), When::TM::Duration.dhms(1,2,3,4) - When::TM::Duration.dhms(1,1,1,1))
42
- assert_equal(When::TM::Duration.dhms(2,4,6,8), When::TM::Duration.dhms(1,2,3,4) * 2)
43
- assert_equal(When::TM::Duration.dhms(1,2,3,4), When::TM::Duration.dhms(2,4,6,8) / 2)
44
- assert_equal(2, When::TM::Duration.dhms(2,4,6,8) / When::TM::Duration.dhms(1,2,3,4))
45
- end
46
-
47
- def test__duration_and_time
48
- start = Time.now
49
- duration = When::TM::Duration.dhms(1,2,3,4.4)
50
- stop = start + duration
51
- assert_equal((RUBY_VERSION.to_f<1.9 ? 93784.4 : 93784), stop-start)
52
- require 'when_exe/core/duration'
53
- stop = start + duration
54
- assert_equal(93784.4, stop-start)
55
- end
56
- end
57
- end
1
+ # -*- coding: utf-8 -*-
2
+ =begin
3
+ Copyright (C) 2011-2013 Takashi SUGA
4
+
5
+ You may use and/or modify this file according to the license
6
+ described in the LICENSE.txt file included in this archive.
7
+ =end
8
+
9
+ module Test::TM
10
+
11
+ #
12
+ # (5.2) Temporal Objects Package
13
+ #
14
+ #
15
+
16
+ class Separation < Test::Unit::TestCase
17
+ def test_nothing
18
+ end
19
+ end
20
+
21
+ class Order < Test::Unit::TestCase
22
+ def test_nothing
23
+ end
24
+ end
25
+
26
+ class RelativePosition < Test::Unit::TestCase
27
+ def test_nothing
28
+ end
29
+ end
30
+
31
+ class Object < Test::Unit::TestCase
32
+ def test_nothing
33
+ end
34
+ end
35
+
36
+ class Complex < Test::Unit::TestCase
37
+ def test_nothing
38
+ end
39
+ end
40
+
41
+ class TopologicalComplex < Test::Unit::TestCase
42
+ def test_nothing
43
+ end
44
+ end
45
+
46
+ class Primitive < Test::Unit::TestCase
47
+ def test_nothing
48
+ end
49
+ end
50
+
51
+ class GeometricPrimitive < Test::Unit::TestCase
52
+ def test_nothing
53
+ end
54
+ end
55
+
56
+ class Instant < Test::Unit::TestCase
57
+
58
+ include When::TM::RelativePosition
59
+
60
+ def test__distance
61
+ position = []
62
+ instant = []
63
+ When.when?('20110201/06').each do |sample|
64
+ position << When.when?(sample)
65
+ instant << When::TM::Instant.new(position[-1])
66
+ end
67
+ period_0202_0204 = When::TM::Period.new(instant[1], instant[3])
68
+
69
+ sample = ['P2D', 'P1D', 'P0D', 'P1D', 'P2D', 'P3D']
70
+ instant.each do |i|
71
+ assert_equal(sample.shift, i.distance(instant[2]).to_s)
72
+ end
73
+
74
+ sample = ['P1D', 'P0D', 'P0D', 'P0D', 'P1D', 'P2D']
75
+ instant.each do |i|
76
+ assert_equal(sample.shift, i.distance(period_0202_0204).to_s)
77
+ end
78
+ end
79
+
80
+ def test__relative_position
81
+ position = []
82
+ instant = []
83
+ When.when?('20110201/06').each do |sample|
84
+ position << When.when?(sample)
85
+ instant << When::TM::Instant.new(position[-1])
86
+ end
87
+ period_0202_0204 = When::TM::Period.new(instant[1], instant[3])
88
+
89
+ sample = [Before, Before, Equals, After, After, After]
90
+ instant.each do |i|
91
+ assert_equal(sample.shift, i.relative_position(instant[2]))
92
+ end
93
+
94
+ sample = [Before, Begins, During, Ends, After, After]
95
+ instant.each do |i|
96
+ assert_equal(sample.shift, i.relative_position(period_0202_0204))
97
+ end
98
+ end
99
+ end
100
+
101
+ class Period < Test::Unit::TestCase
102
+
103
+ include When::TM::RelativePosition
104
+
105
+ def test__distance
106
+ position = []
107
+ instant = []
108
+ When.when?('20110201/06').each do |sample|
109
+ position << When.when?(sample)
110
+ instant << When::TM::Instant.new(position[-1])
111
+ end
112
+ assert_equal(["2011-02-01", "2011-02-02", "2011-02-03",
113
+ "2011-02-04", "2011-02-05", "2011-02-06"],
114
+ position.map {|v| v.to_s})
115
+
116
+ period_0201_0202 = When::TM::Period.new(instant[0], instant[1])
117
+ period_0202_0203 = When::TM::Period.new(instant[1], instant[2])
118
+ period_0203_0204 = When::TM::Period.new(instant[2], instant[3])
119
+ period_0204_0205 = When::TM::Period.new(instant[3], instant[4])
120
+ period_0205_0206 = When::TM::Period.new(instant[4], instant[5])
121
+
122
+ period_0202_0204 = When::TM::Period.new(instant[1], instant[3])
123
+ period_0204_0206 = When::TM::Period.new(instant[3], instant[5])
124
+ period_0203_0206 = When::TM::Period.new(instant[2], instant[5])
125
+ period_0201_0206 = When::TM::Period.new(instant[0], instant[5])
126
+
127
+ sample = ['P1D', 'P0D', 'P0D', 'P0D', 'P1D', 'P2D']
128
+ instant.each do |i|
129
+ assert_equal(sample.shift, period_0202_0204.distance(i).to_s)
130
+ end
131
+
132
+ [['P2D', period_0201_0202, period_0204_0206],
133
+ ['P0D', period_0201_0202, period_0202_0204],
134
+ ['P0D', period_0202_0203, period_0202_0204],
135
+ ['P0D', period_0203_0204, period_0202_0204],
136
+ ['P0D', period_0204_0205, period_0202_0204],
137
+ ['P0D', period_0203_0206, period_0202_0204],
138
+ ['P1D', period_0205_0206, period_0202_0204]].each do |sample|
139
+ assert_equal(sample[0], sample[1].distance(sample[2]).to_s)
140
+ assert_equal(sample[0], sample[2].distance(sample[1]).to_s)
141
+ end
142
+ end
143
+
144
+ def test__relative_position
145
+ position = []
146
+ instant = []
147
+ When.when?('20110201/06').each do |sample|
148
+ position << When.when?(sample)
149
+ instant << When::TM::Instant.new(position[-1])
150
+ end
151
+ period_0201_0202 = When::TM::Period.new(instant[0], instant[1])
152
+ period_0202_0203 = When::TM::Period.new(instant[1], instant[2])
153
+ period_0203_0204 = When::TM::Period.new(instant[2], instant[3])
154
+ period_0204_0205 = When::TM::Period.new(instant[3], instant[4])
155
+ period_0205_0206 = When::TM::Period.new(instant[4], instant[5])
156
+
157
+ period_0202_0204 = When::TM::Period.new(instant[1], instant[3])
158
+ period_0203_0206 = When::TM::Period.new(instant[2], instant[5])
159
+ period_0204_0206 = When::TM::Period.new(instant[3], instant[5])
160
+ period_0201_0206 = When::TM::Period.new(instant[0], instant[5])
161
+
162
+ sample = [After, BegunBy, Contains, EndedBy, Before, Before]
163
+ instant.each do |i|
164
+ assert_equal(sample.shift, period_0202_0204.relative_position(i))
165
+ end
166
+
167
+ [[Before, period_0201_0202, period_0204_0206],
168
+ [Meets, period_0201_0202, period_0202_0204],
169
+ [Overlaps, period_0202_0204, period_0203_0206],
170
+ [Begins, period_0202_0203, period_0202_0204],
171
+ [BegunBy, period_0202_0204, period_0202_0203],
172
+
173
+ [During, period_0202_0204, period_0201_0206],
174
+ [Contains, period_0201_0206, period_0202_0204],
175
+ [Equals, period_0202_0204, period_0202_0204],
176
+
177
+ [OverlappedBy, period_0203_0206, period_0202_0204],
178
+ [Ends, period_0203_0204, period_0202_0204],
179
+ [EndedBy, period_0202_0204, period_0203_0204],
180
+ [MetBy, period_0204_0205, period_0202_0204],
181
+ [After, period_0205_0206, period_0202_0204]].each do |sample|
182
+ assert_equal(sample[0], sample[1].relative_position(sample[2]))
183
+ end
184
+
185
+ end
186
+ end
187
+
188
+ class TopologicalPrimitive < Test::Unit::TestCase
189
+ def test_nothing
190
+ end
191
+ end
192
+
193
+ class Node < Test::Unit::TestCase
194
+ def test_nothing
195
+ end
196
+ end
197
+
198
+ class Edge < Test::Unit::TestCase
199
+ def test_nothing
200
+ end
201
+ end
202
+
203
+ class Duration < Test::Unit::TestCase
204
+ def test__duration_constructors
205
+ assert_equal( 1, When::TM::Duration.new(1).duration)
206
+ assert_equal( 1.0/128, When::TM::Duration.second(1).duration)
207
+ assert_equal( 60.0/128, When::TM::Duration.minute(1).duration)
208
+ assert_equal( 3600.0/128, When::TM::Duration.hour(1).duration)
209
+ assert_equal(86400.0/128, When::TM::Duration.day(1).duration)
210
+ assert_equal(93784.0/128, When::TM::Duration.dhms(1,2,3,4).duration)
211
+ end
212
+
213
+ def test__duration_values
214
+ assert_equal(1, When::TM::Duration.new(1).system)
215
+ assert_equal(2, When::TM::Duration.second(2).second)
216
+ assert_equal(3, When::TM::Duration.minute(3).minute)
217
+ assert_equal(4, When::TM::Duration.hour(4).hour)
218
+ assert_equal(5, When::TM::Duration.day(5).day)
219
+ assert_equal([1,2,3,4], When::TM::Duration.dhms(1,2,3,4).to_dhms)
220
+ assert_equal([-2,21,56,56], (-When::TM::Duration.dhms(1,2,3,4)).to_dhms)
221
+ end
222
+
223
+ def test__duration_elements
224
+ duration = When::TM::Duration.dhms(1,2,3,4.5)
225
+ assert_equal(1, duration[0])
226
+ assert_equal(2, duration[1])
227
+ assert_equal(3, duration[2])
228
+ assert_equal(4.5, duration[3])
229
+ end
230
+
231
+ def test__duration_arithmetics
232
+ assert_equal(When::TM::Duration.dhms(-2,21,56,56), -When::TM::Duration.dhms(1,2,3,4))
233
+ assert_equal(When::TM::Duration.dhms(2,3,4,5), When::TM::Duration.dhms(1,2,3,4) + When::TM::Duration.dhms(1,1,1,1))
234
+ assert_equal(When::TM::Duration.dhms(0,1,2,3), When::TM::Duration.dhms(1,2,3,4) - When::TM::Duration.dhms(1,1,1,1))
235
+ assert_equal(When::TM::Duration.dhms(2,4,6,8), When::TM::Duration.dhms(1,2,3,4) * 2)
236
+ assert_equal(When::TM::Duration.dhms(1,2,3,4), When::TM::Duration.dhms(2,4,6,8) / 2)
237
+ assert_equal(2, When::TM::Duration.dhms(2,4,6,8) / When::TM::Duration.dhms(1,2,3,4))
238
+ end
239
+
240
+ def test__duration_and_time
241
+ start = Time.now
242
+ duration = When::TM::Duration.dhms(1,2,3,4.4)
243
+ stop = start + duration
244
+ assert_equal((RUBY_VERSION.to_f<1.9 ? 93784.4 : 93784), stop-start)
245
+ require 'when_exe/core/duration'
246
+ stop = start + duration
247
+ assert_equal(93784.4, stop-start)
248
+
249
+ stop = start + When.Duration('P1DT2H3M4S')
250
+ assert_equal(93784, stop-start)
251
+
252
+ assert_raise(TypeError) {
253
+ stop = start + When.Duration('P2M1DT2H3M4S')
254
+ }
255
+ end
256
+ end
257
+
258
+ class PeriodDuration < Test::Unit::TestCase
259
+ def test__period_duration
260
+ period = When.Duration('P2Y3M4D')
261
+ [[-2, 2], [-1, 3], [0, 4]].each do |sample|
262
+ assert_equal(sample[1], period[sample[0]])
263
+ end
264
+ period = When.Duration('PT5H6M7S')
265
+ [[1, 5], [2, 6], [3, 7]].each do |sample|
266
+ assert_equal(sample[1], period[sample[0]])
267
+ end
268
+ period = When.Duration('P2Y3M4DT5H6M7S')
269
+ [[-2, 2], [-1, 3], [0, 4], [1, 5], [2, 6], [3, 7]].each do |sample|
270
+ assert_equal(sample[1], period[sample[0]])
271
+ end
272
+ period = When.Duration('P8W9D')
273
+ [[-0.5, 8], [0, 8*7+9]].each do |sample|
274
+ assert_equal(sample[1], period[sample[0]])
275
+ end
276
+ end
277
+
278
+ def test__julian_gregorian_change
279
+ epoch = When.when?('CE1582.10.3') ^ When.Duration('P1D')
280
+ sample = [
281
+ "CE1582.10.03",
282
+ "CE1582.10.04",
283
+ "CE1582.10.15",
284
+ "CE1582.10.16"
285
+ ]
286
+ 4.times do
287
+ assert_equal(sample.shift, epoch.next.to_s)
288
+ end
289
+
290
+ sample = [
291
+ "CE1582.10.16",
292
+ "CE1582.10.15",
293
+ "CE1582.10.04",
294
+ "CE1582.10.03"
295
+ ]
296
+ epoch = When.when?('CE1582.10.16') ^ -When.Duration('P1D')
297
+ 4.times do
298
+ assert_equal(sample.shift, epoch.next.to_s)
299
+ end
300
+
301
+ assert_equal(
302
+ [["October 1582",
303
+ ["-", 1, 2, 3, 4, 15, 16],
304
+ [17, 18, 19, 20, 21, 22, 23],
305
+ [24, 25, 26, 27, 28, 29, 30],
306
+ [31, "-", "-", "-", "-", "-", "-"]]],
307
+ When.when?('CE1582.10').month_included('SU') {|date, type|
308
+ case type
309
+ when When::YEAR,
310
+ When::MONTH ; date.strftime("%B %Y")
311
+ when When::WEEK ; nil
312
+ when When::DAY ; date[0]
313
+ else ; '-'
314
+ end
315
+ })
316
+ end
317
+ end
318
+
319
+ class IntervalLength < Test::Unit::TestCase
320
+ def test__interval_length
321
+ [
322
+ ['7E-3s', 7, 3, 10, 'second', '7E-3s' ],
323
+ ['8X-2m', 8, 2, 60, 'minute', '8X-2m' ],
324
+ ['6(12)7D', 6, -7, 12, 'day', '6(12)+7D' ],
325
+ ['1(16)4*10S', 1, -4, 16, '10', '1(16)+4*10S']
326
+ ].each do |sample|
327
+ interval = When.Duration(sample[0])
328
+ assert_equal(sample[1..5], [interval.value, interval.factor, interval.radix, interval.unit, interval.to_s])
329
+ end
330
+ end
331
+
332
+ def test__julian_gregorian_change
333
+ epoch = When.when?('CE1582.10.03') ^ When.Duration('1D')
334
+ sample = [
335
+ "CE1582.10.03",
336
+ "CE1582.10.04",
337
+ "CE1582.10.15",
338
+ "CE1582.10.16"
339
+ ]
340
+ 4.times do
341
+ assert_equal(sample.shift, epoch.next.to_s)
342
+ end
343
+
344
+ sample = [
345
+ "CE1582.10.16",
346
+ "CE1582.10.15",
347
+ "CE1582.10.04",
348
+ "CE1582.10.03"
349
+ ]
350
+ epoch = When.when?('CE1582.10.16') ^ -When.Duration('1D')
351
+ 4.times do
352
+ assert_equal(sample.shift, epoch.next.to_s)
353
+ end
354
+ end
355
+ end
356
+ end
@@ -0,0 +1,237 @@
1
+ # -*- coding: utf-8 -*-
2
+ =begin
3
+ Copyright (C) 2011-2012 Takashi SUGA
4
+
5
+ You may use and/or modify this file according to the license
6
+ described in the LICENSE.txt file included in this archive.
7
+ =end
8
+
9
+ module Test::TM
10
+
11
+ #
12
+ # (5.4) Temporal Position Package
13
+ #
14
+ #
15
+
16
+ class IndeterminateValue < Test::Unit::TestCase
17
+ def test_nothing
18
+ end
19
+ end
20
+
21
+ class Position < Test::Unit::TestCase
22
+ def test_nothing
23
+ end
24
+ end
25
+
26
+ class TemporalPosition < Test::Unit::TestCase
27
+ def test__instance
28
+ [["19800203T234512.33+0900", "1980-02-03T23:45:12.33+09:00"],
29
+ ["19800203T234512.33Z", "1980-02-03T23:45:12.33Z"],
30
+ ["19800203T234512", "1980-02-03T23:45:12Z"],
31
+ ["19800203T2345", "1980-02-03T23:45Z"],
32
+ ["19800203T23", "1980-02-03T23Z"],
33
+ ["19800203T", "1980-02-03TZ"],
34
+ ["19800203", "1980-02-03"],
35
+ ["1980-02", "1980-02"],
36
+ ["S33.07.31", "S33(1958).07.31"],
37
+ ["S33.07.31/", "S33(1958).07.31"],
38
+ ["1980T-0700", "1980T-07:00"],
39
+ ["T234512-0700", "T23:45:12-07:00"],
40
+ ["H2(1990)-05-11T23:45:12-07:00", "H02(1990).05.11T23:45:12-07:00"],
41
+ ["T3(1914)=05-11T23:45:12-07:00", "T03(1914)=05.11T23:45:12-07:00"], # TODO
42
+ ["S64.01.07", "S64(1989).01.07"],
43
+ ["2001-08-02/After", "2001-08-02"],
44
+ ["Before/2001-09-10", "2001-09-10"]].each do |sample|
45
+ assert_equal(sample[1], When.when?(sample[0]).to_s)
46
+ end
47
+ assert_equal(["1980-02-03","1980-02-05","1980-02-06","1980-02-09"], When.when?(<<LIST).map {|date| date.to_s})
48
+ 19800203
49
+ 19800205
50
+ 19800206
51
+ 19800209
52
+ LIST
53
+ assert_equal("2001-08-02..2001-09-10", When.when?("2001-08-02/09-10").to_s)
54
+ assert_equal("1980-02-01", When.when?("800201", {:abbr=>1970}).to_s)
55
+ # assert_equal(nil, When.TemporalPosition(2011,2,29))
56
+ assert_equal('2011-03-01', When.TemporalPosition(2011,2,29).to_s)
57
+ assert_equal(nil, When.TemporalPosition(2011,2,29, {:invalid=>:check}))
58
+ assert_raises(ArgumentError) { When.TemporalPosition(2011,2,29, {:invalid=>:raise}) }
59
+ end
60
+
61
+ def test__to_date
62
+ if ::Object.const_defined?(:Date) && Date.respond_to?(:civil)
63
+ assert(/^Tue Jun 7 00:00:00 (\+00:00|Z) 2011$/ =~ When.when?("2011-06-07").to_date.strftime('%+'))
64
+ end
65
+ end
66
+
67
+ def test__to_date_time
68
+ if ::Object.const_defined?(:Date) && Date.respond_to?(:civil)
69
+ assert(/Tue Jun 7 16:17:36 \+09:?00 2011$/ =~ When.when?("2011-06-07T16:17:36+09:00").to_date_time.strftime('%+'))
70
+ end
71
+ end
72
+ end
73
+
74
+ class Coordinate < Test::Unit::TestCase
75
+ def test_nothing
76
+ end
77
+ end
78
+
79
+ class JulianDate < Test::Unit::TestCase
80
+ def test_nothing
81
+ end
82
+ end
83
+
84
+ class OrdinalPosition < Test::Unit::TestCase
85
+ def test_nothing
86
+ end
87
+ end
88
+
89
+ class ClockTime < Test::Unit::TestCase
90
+ def test_nothing
91
+ end
92
+ end
93
+
94
+ class CalDate < Test::Unit::TestCase
95
+ def test__floor
96
+ date4 = When.when?("19820606^^Julian")
97
+ [[-2, "1982"],
98
+ [-1, "1982-06"],
99
+ [ 0, "1982-06-06"]].each do |sample|
100
+ assert_equal(sample[1], date4.floor(sample[0]).to_s)
101
+ end
102
+ end
103
+
104
+ def test__week
105
+ date = When.when?('20110517')
106
+ assert_equal("2011-05-16...2011-05-23", date.week_included.to_s)
107
+ [
108
+ ['MO', "2011-05-16...2011-05-23"],
109
+ ['TU', "2011-05-17...2011-05-24"],
110
+ ['WE', "2011-05-11...2011-05-18"],
111
+ ['TH', "2011-05-12...2011-05-19"],
112
+ ['FR', "2011-05-13...2011-05-20"],
113
+ ['SA', "2011-05-14...2011-05-21"],
114
+ ['SU', "2011-05-15...2011-05-22"]
115
+ ].each do |sample|
116
+ assert_equal(sample[1], date.week_included(sample[0]).to_s)
117
+ end
118
+ [
119
+ [-1, "2011-05-09...2011-05-16"],
120
+ [ 0, "2011-05-16...2011-05-23"],
121
+ [+1, "2011-05-23...2011-05-30"],
122
+ ].each do |sample|
123
+ assert_equal(sample[1], date.week_included(sample[0]).to_s)
124
+ end
125
+ end
126
+ end
127
+
128
+ class DateAndTime < Test::Unit::TestCase
129
+ def test__caret
130
+ week = When.Resource("_co:Residue?divisor=7")
131
+ date = When.TemporalPosition(2010,11,30, 6, 30)
132
+ assert_equal("2010-11-30T06:30Z", date.to_s)
133
+ it = date ^ week
134
+ assert_equal("2010-12-06T06:30Z", it.next.to_s)
135
+ assert_equal("2010-12-13T06:30Z", it.next.to_s)
136
+ assert_equal("2010-12-20T06:30Z", it.next.to_s)
137
+ it = date ^ When.Duration(2 * When::TM::Duration::DAY)
138
+ assert_equal("2010-11-30T06:30Z", it.next.to_s)
139
+ assert_equal("2010-12-02T06:30Z", it.next.to_s)
140
+ assert_equal("2010-12-04T06:30Z", it.next.to_s)
141
+ end
142
+
143
+ def test__modulo
144
+ week = When.Resource("_co:Residue?divisor=7")
145
+ weekName = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
146
+ obj1 = When.when?("20100928T234512.33+0900^^Gregorian")
147
+ assert_equal("Tue", weekName[obj1 % week])
148
+ obj2 = When.when?("20100928T234512.33-0600^^Gregorian")
149
+ assert_equal("Tue", weekName[obj2 % week])
150
+ end
151
+
152
+ def test__minus
153
+ obj1 = When.when?("20100928T234512.33+0900^^Gregorian")
154
+ obj2 = When.when?("20100928T234512.33-0600^^Gregorian")
155
+ assert_equal("2010-08-28T23:45:12.33+09:00", (obj1 - When::Duration("P1M")).to_s)
156
+ assert_equal(0.625 * When::TM::Duration::DAY, (obj2 - obj1).duration)
157
+ assert_equal("2010-09-13T23:45:12.33-06:00", (obj2 - 15).to_s)
158
+ end
159
+
160
+ def test__plus
161
+ obj1 = When.when?("20100928T234512.33+0900^^Gregorian")
162
+ [["P3D", "2010-10-01T23:45:12.33+09:00"],
163
+ ["P1Y", "2011-09-28T23:45:12.33+09:00"],
164
+ ["P1M", "2010-10-28T23:45:12.33+09:00"],
165
+ ["PT3H", "2010-09-29T02:45:12.33+09:00"],
166
+ ["P3W", "2010-10-19T23:45:12.33+09:00"]].each do |sample|
167
+ assert_equal(sample[1], (obj1 + When::Duration(sample[0])).to_s)
168
+ end
169
+
170
+ obj2 = When.when?("19820606T1234^^Julian")
171
+ [["PT2H15M", "1982-06-06T14:49Z"],
172
+ ["PT3H", "1982-06-06T15:34Z"]].each do |sample|
173
+ assert_equal(sample[1], (obj2 + When::Duration(sample[0])).to_s)
174
+ end
175
+
176
+ ic = When.Resource("examples/NewYork.ics")
177
+ tz1 = When::V::Timezone["America/New_York"]
178
+
179
+ [tz1].each do |tz|
180
+ When::TM::Clock.local_time = tz
181
+ obj3 = When.when?("1997-04-06T00:00:00", {:clock=>tz})
182
+ [["PT1H", "1997-04-06T01:00:00-05:00"],
183
+ ["PT2H", "1997-04-06T02:00:00-04:00"],
184
+ ["PT3H", "1997-04-06T03:00:00-04:00"],
185
+ [1 * When::TM::Duration::HOUR, "1997-04-06T01:00:00-05:00"],
186
+ [2 * When::TM::Duration::HOUR, "1997-04-06T03:00:00-04:00"],
187
+ [3 * When::TM::Duration::HOUR, "1997-04-06T04:00:00-04:00"]].each do |sample|
188
+ assert_equal(sample[1], (obj3 + When::Duration(sample[0])).to_s)
189
+ end
190
+
191
+ obj4 = When.when?("1997-10-26T00:00:00", {:clock=>tz})
192
+ [["PT1H", "1997-10-26T01:00:00-04:00"],
193
+ ["PT2H", "1997-10-26T02:00:00-04:00"],
194
+ ["PT3H", "1997-10-26T03:00:00-05:00"],
195
+ [1 * When::TM::Duration::HOUR, "1997-10-26T01:00:00-04:00"],
196
+ [2 * When::TM::Duration::HOUR, "1997-10-26T02:00:00-04:00"],
197
+ [3 * When::TM::Duration::HOUR, "1997-10-26T02:00:00-05:00"]].each do |sample|
198
+ assert_equal(sample[1], (obj4 + When::Duration(sample[0])).to_s)
199
+ end
200
+ end
201
+ end
202
+
203
+ if Object.const_defined?(:TZInfo)
204
+ def test__plus_tzinfo
205
+ obj4 = When.when?("1997-10-26T00:00:00", {:clock=>When::Parts::Timezone["America/New_York"]})
206
+ [["PT59M","1997-10-26T00:59:00-04:00"],
207
+ ["PT1H", "1997-10-26T01:00:00-04:00"],
208
+ ["PT2H", "1997-10-26T02:00:00-05:00"], # "1997-10-26T02:00:00-04:00" - TODO !!
209
+ ["PT3H", "1997-10-26T03:00:00-05:00"],
210
+ [1 * When::TM::Duration::HOUR, "1997-10-26T01:00:00-04:00"],
211
+ [2 * When::TM::Duration::HOUR, "1997-10-26T02:00:00-04:00"],
212
+ [3 * When::TM::Duration::HOUR, "1997-10-26T02:00:00-05:00"]].each do |sample|
213
+ assert_equal(sample[1], (obj4 + When::Duration(sample[0])).to_s)
214
+ end
215
+ end
216
+ else
217
+ puts "Tests for TZInfo have been skipped at line #{__LINE__} of #{__FILE__.split(/\//)[-1]}."
218
+ end
219
+
220
+ def test__floor_date_and_time
221
+ date5 = When.when?("1982-06-06T12:34:56.78^^Julian")
222
+ sample = [
223
+ "1982TZ",
224
+ "1982-06TZ",
225
+ "1982-06-06TZ",
226
+ "1982-06-06T12Z",
227
+ "1982-06-06T12:34Z",
228
+ "1982-06-06T12:34:56Z",
229
+ "1982-06-06T12:34:56.7Z",
230
+ "1982-06-06T12:34:56.78Z"
231
+ ]
232
+ (-2..5).each do |i|
233
+ assert_equal(sample.shift, date5.floor(i).to_s)
234
+ end
235
+ end
236
+ end
237
+ end