when_exe 0.3.7 → 0.3.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +210 -171
- data/bin/irb.rc +1 -0
- data/lib/when_exe.rb +78 -53
- data/lib/when_exe/basictypes.rb +27 -8
- data/lib/when_exe/calendarnote.rb +848 -805
- data/lib/when_exe/calendartypes.rb +110 -240
- data/lib/when_exe/coordinates.rb +2440 -2175
- data/lib/when_exe/core/compatibility.rb +1 -1
- data/lib/when_exe/core/duration.rb +13 -11
- data/lib/when_exe/core/extension.rb +38 -45
- data/lib/when_exe/ephemeris.rb +43 -14
- data/lib/when_exe/ephemeris/eclipse.rb +149 -0
- data/lib/when_exe/ephemeris/notes.rb +39 -7
- data/lib/when_exe/icalendar.rb +2 -6
- data/lib/when_exe/inspect.rb +1408 -1399
- data/lib/when_exe/parts/enumerator.rb +486 -477
- data/lib/when_exe/parts/resource.rb +1101 -1069
- data/lib/when_exe/parts/timezone.rb +6 -5
- data/lib/when_exe/region/babylonian.rb +405 -405
- data/lib/when_exe/region/bahai.rb +21 -61
- data/lib/when_exe/region/chinese/epochs.rb +81 -81
- data/lib/when_exe/region/chinese/twins.rb +51 -51
- data/lib/when_exe/region/christian.rb +7 -2
- data/lib/when_exe/region/coptic.rb +1 -1
- data/lib/when_exe/region/discordian.rb +9 -16
- data/lib/when_exe/region/french.rb +1 -1
- data/lib/when_exe/region/hanke_henry.rb +57 -0
- data/lib/when_exe/region/indian.rb +41 -73
- data/lib/when_exe/region/international_fixed.rb +97 -0
- data/lib/when_exe/region/iranian.rb +203 -203
- data/lib/when_exe/region/japanese.rb +13 -13
- data/lib/when_exe/region/japanese/eclipses.rb +1194 -0
- data/lib/when_exe/region/japanese/notes.rb +1482 -1383
- data/lib/when_exe/region/japanese/residues.rb +726 -721
- data/lib/when_exe/region/japanese/twins.rb +37 -37
- data/lib/when_exe/region/jewish.rb +2 -2
- data/lib/when_exe/region/pax.rb +60 -0
- data/lib/when_exe/region/positivist.rb +100 -0
- data/lib/when_exe/region/roman.rb +333 -334
- data/lib/when_exe/region/shire.rb +3 -20
- data/lib/when_exe/region/thai.rb +2 -2
- data/lib/when_exe/region/tibetan.rb +3 -3
- data/lib/when_exe/region/tranquility.rb +208 -0
- data/lib/when_exe/region/vanishing_leprechaun.rb +53 -0
- data/lib/when_exe/region/vietnamese.rb +4 -4
- data/lib/when_exe/region/world.rb +9 -13
- data/lib/when_exe/region/world_season.rb +89 -0
- data/lib/when_exe/region/zoroastrian.rb +4 -2
- data/lib/when_exe/tmobjects.rb +14 -4
- data/lib/when_exe/tmposition.rb +239 -81
- data/lib/when_exe/tmreference.rb +57 -28
- data/lib/when_exe/version.rb +1 -1
- data/link_to_online_documents +6 -3
- data/test/examples/today.rb +1 -1
- data/test/scripts.rb +23 -0
- data/test/scripts/2.ext.rb +169 -0
- data/test/scripts/2.rb +169 -0
- data/test/scripts/3.ext.rb +133 -0
- data/test/scripts/3.rb +134 -0
- data/test/scripts/4.ext.rb +112 -0
- data/test/scripts/4.min.rb +65 -0
- data/test/scripts/4.rb +136 -0
- data/test/scripts/5.ext.rb +78 -0
- data/test/scripts/5.rb +81 -0
- data/test/scripts/6.gcal.rb +131 -0
- data/test/scripts/6.rb +205 -0
- data/test/scripts/6.tz.rb +105 -0
- data/test/scripts/7.phase.rb +109 -0
- data/test/scripts/7.rb +95 -0
- data/test/scripts/7.term.rb +128 -0
- data/test/scripts/7.week.rb +84 -0
- data/test/scripts/8.ext.rb +61 -0
- data/test/scripts/8.rb +62 -0
- data/test/scripts/9.ext.rb +131 -0
- data/test/scripts/9.rb +130 -0
- data/test/scripts/chinese-luni-solar.rb +52 -0
- data/test/{examples → scripts}/geometric_complex.rb +41 -41
- data/test/scripts/geometric_complex.txt +18 -0
- data/test/scripts/korea.rb +59 -0
- data/test/scripts/thai-reviewed.txt +211 -0
- data/test/scripts/thai.rb +36 -0
- data/test/scripts/thai.txt +210 -0
- data/test/test.rb +7 -0
- data/test/test/basictypes.rb +22 -0
- data/test/test/coordinates.rb +2 -1
- data/test/test/ephemeris.rb +34 -2
- data/test/test/icalendar.rb +12 -0
- data/test/test/inspect.rb +37 -1
- data/test/test/parts.rb +4 -3
- data/test/test/region/armenian.rb +20 -0
- data/test/test/region/bahai.rb +58 -0
- data/test/test/region/chinese.rb +14 -3
- data/test/test/region/christian.rb +16 -35
- data/test/test/region/discordian.rb +20 -0
- data/test/test/region/indian.rb +30 -2
- data/test/test/region/japanese.rb +24 -0
- data/test/test/region/jewish.rb +2 -0
- data/test/test/region/m17n.rb +9 -0
- data/test/test/region/reforms.rb +121 -0
- data/test/test/region/residue.rb +17 -11
- data/test/test/region/shire.rb +58 -0
- data/test/test/region/swedish.rb +45 -0
- data/test/test/region/zoroastrian.rb +58 -0
- data/test/test/tmobjects.rb +74 -0
- data/test/test/tmposition.rb +468 -397
- data/when_exe.gemspec +2 -2
- metadata +49 -6
data/test/test/region/jewish.rb
CHANGED
data/test/test/region/m17n.rb
CHANGED
@@ -179,6 +179,15 @@ module MiniTest
|
|
179
179
|
end
|
180
180
|
end
|
181
181
|
end
|
182
|
+
|
183
|
+
assert_equal({:Frame=>"http://hosi.org/When/CalendarTypes/Gregorian",
|
184
|
+
:Precision=>0,
|
185
|
+
:Sdn=>2456388,
|
186
|
+
:Calendar=>["http://hosi.org/When/CalendarTypes/Gregorian"],
|
187
|
+
:Notes=>[[{:Note=>"Month", :Value=>"April"}],
|
188
|
+
[{:Note=>"Week", :Value=>"Friday(4)"}]],
|
189
|
+
:CalDate=>[2013, 4, 5]},
|
190
|
+
When.when?('2013-4-5').to_h(:method=>:to_m17n, :locale=>'en', :camel=>true))
|
182
191
|
end
|
183
192
|
end
|
184
193
|
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
=begin
|
3
|
+
Copyright (C) 2014 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 MiniTest
|
10
|
+
|
11
|
+
class World < MiniTest::TestCase
|
12
|
+
def test_world
|
13
|
+
date = When.when? '2001.1.1'
|
14
|
+
400.times do
|
15
|
+
assert_equal(date.cal_date, (When::World ^ date).cal_date)
|
16
|
+
date += When::P1Y
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class Positivist < MiniTest::TestCase
|
22
|
+
def test_positivist
|
23
|
+
date = When.when? '2001.1.1'
|
24
|
+
400.times do |i|
|
25
|
+
assert_equal([2001+i-1788,1,1], (When::Positivist ^ date).cal_date)
|
26
|
+
date += When::P1Y
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
class InternationalFixed < MiniTest::TestCase
|
32
|
+
def test_international_fixed
|
33
|
+
date = When.when? '2001.1.1'
|
34
|
+
400.times do |i|
|
35
|
+
assert_equal([2001+i,1,1], (When::InternationalFixed ^ date).cal_date)
|
36
|
+
date += When::P1Y
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
class Tranquility < MiniTest::TestCase
|
42
|
+
def test_tranquility
|
43
|
+
date = When.when? '1969.7.21'
|
44
|
+
400.times do |i|
|
45
|
+
assert_equal([1+i,1,1], (When::Tranquility ^ date).cal_date)
|
46
|
+
date += When::P1Y
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
class WorldSeason < MiniTest::TestCase
|
52
|
+
def test_world_season
|
53
|
+
date = When.when? '2000.12.21'
|
54
|
+
400.times do |i|
|
55
|
+
assert_equal([2001+i,1,1], (When::WorldSeason ^ date).cal_date)
|
56
|
+
date += When::P1Y
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
class Pax < MiniTest::TestCase
|
62
|
+
def test_pax
|
63
|
+
|
64
|
+
samples = [
|
65
|
+
%w(2014-01-01 2013-12-29),
|
66
|
+
%w(2015-01-01 2014-12-28),
|
67
|
+
%w(2016-01-01 2015-12-27),
|
68
|
+
%w(2017-01-01 2016-12-25),
|
69
|
+
%w(2018-01-01 2017-12-24),
|
70
|
+
%w(2019-01-01 2018-12-30),
|
71
|
+
%w(2020-01-01 2019-12-29),
|
72
|
+
%w(2021-01-01 2020-12-27),
|
73
|
+
%w(2022-01-01 2021-12-26),
|
74
|
+
%w(2023-01-01 2022-12-25),
|
75
|
+
|
76
|
+
%w(2018-02-01 2018-01-21),
|
77
|
+
%w(2018-03-01 2018-02-18),
|
78
|
+
%w(2018-04-01 2018-03-18),
|
79
|
+
%w(2018-05-01 2018-04-15),
|
80
|
+
%w(2018-06-01 2018-05-13),
|
81
|
+
%w(2018-07-01 2018-06-10),
|
82
|
+
%w(2018-08-01 2018-07-08),
|
83
|
+
%w(2018-09-01 2018-08-05),
|
84
|
+
%w(2018-10-01 2018-09-02),
|
85
|
+
%w(2018-11-01 2018-09-30),
|
86
|
+
%w(2018-12-01 2018-10-28),
|
87
|
+
%w(2018-12=01 2018-11-25),
|
88
|
+
%w(2018-13-01 2018-12-02)]
|
89
|
+
|
90
|
+
date = When.when? '2014.1.1^^Pax'
|
91
|
+
10.times do
|
92
|
+
assert_equal(samples.shift, [date.to_s, (When::Gregorian ^ date).to_s])
|
93
|
+
date += When::P1Y
|
94
|
+
end
|
95
|
+
|
96
|
+
date = When.when? '2018.1.1^^Pax'
|
97
|
+
13.times do
|
98
|
+
date += When::P1M
|
99
|
+
assert_equal(samples.shift, [date.to_s, (When::Gregorian ^ date).to_s])
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
class HankeHenry < MiniTest::TestCase
|
105
|
+
def test_hanke_henry
|
106
|
+
assert_equal(When.when?('2012.1.1').to_i, When.when?('2012.1.1^^HankeHenry').to_i)
|
107
|
+
count = 0
|
108
|
+
(2000...2400).each do |year|
|
109
|
+
first = When.tm_pos(year, 1, 1)
|
110
|
+
last = When.tm_pos(year,12,31)
|
111
|
+
if (first.to_i % 7) == 3 || (last.to_i % 7) == 3
|
112
|
+
assert_equal(371, When.tm_pos(year, :frame=>When::HankeHenry).length(When::YEAR))
|
113
|
+
count += 1
|
114
|
+
else
|
115
|
+
assert_equal(364, When.tm_pos(year, :frame=>When::HankeHenry).length(When::YEAR))
|
116
|
+
end
|
117
|
+
end
|
118
|
+
assert_equal(71, count)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
data/test/test/region/residue.rb
CHANGED
@@ -92,6 +92,7 @@ module MiniTest
|
|
92
92
|
def test__epoch_in_CE
|
93
93
|
cals = [
|
94
94
|
'Gregorian',
|
95
|
+
'Gregorian?border=1959-2-23',
|
95
96
|
'Dee',
|
96
97
|
'DeeCecil',
|
97
98
|
'Coptic?Epoch=284Y',
|
@@ -105,6 +106,7 @@ module MiniTest
|
|
105
106
|
'IndianNationalSolar',
|
106
107
|
'Nanakshahi',
|
107
108
|
'RevisedBengali',
|
109
|
+
'Fasli',
|
108
110
|
'HinduSolar?type=SBV',
|
109
111
|
'HinduSolar?type=SBVZ',
|
110
112
|
'HinduSolar?type=SBS',
|
@@ -113,14 +115,14 @@ module MiniTest
|
|
113
115
|
'HinduSolar?type=SBBZ',
|
114
116
|
'HinduSolar?type=SBH',
|
115
117
|
'HinduSolar?type=SBHZ',
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
118
|
+
'HinduLuniSolar?type=SBVA',
|
119
|
+
# 'HinduLuniSolar?type=SBVZA',
|
120
|
+
# 'HinduLuniSolar?type=SBSA',
|
121
|
+
# 'HinduLuniSolar?type=SBSZA',
|
122
|
+
# 'HinduLuniSolar?type=SBBA',
|
123
|
+
# 'HinduLuniSolar?type=SBBZA',
|
124
|
+
# 'HinduLuniSolar?type=SBHA',
|
125
|
+
# 'HinduLuniSolar?type=SBHZA',
|
124
126
|
'FrenchRepublican',
|
125
127
|
'Jalali',
|
126
128
|
'SolarHijri',
|
@@ -128,17 +130,21 @@ module MiniTest
|
|
128
130
|
'Borji',
|
129
131
|
'Jewish',
|
130
132
|
'Thai',
|
131
|
-
|
133
|
+
'ThaiT',
|
132
134
|
'Tibetan',
|
135
|
+
'Discordian',
|
136
|
+
'Positivist',
|
137
|
+
'InternationalFixed',
|
138
|
+
'VanishingLeprechaun'
|
133
139
|
]
|
134
140
|
eto = When.Resource('_co:Common::干支').to('year')
|
135
|
-
today = When.when?('2012-06-
|
141
|
+
today = When.when?('2012-06-15')
|
136
142
|
assert_equal([[28, 246778, 246778]],
|
137
143
|
cals.map { |list|
|
138
144
|
cal, shift = list
|
139
145
|
shift ||= 0
|
140
146
|
date = When.Calendar(cal) ^ today
|
141
|
-
[date % eto - shift, ((eto & date).to_i/10).to_i + 37*shift, ((date & eto).to_i/10).to_i + 37*shift]
|
147
|
+
[+(date % eto - shift), ((eto & date).to_i/10).to_i + 37*shift, ((date & eto).to_i/10).to_i + 37*shift]
|
142
148
|
}.uniq
|
143
149
|
)
|
144
150
|
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
=begin
|
3
|
+
Copyright (C) 2014 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 MiniTest
|
10
|
+
|
11
|
+
class Shire < MiniTest::TestCase
|
12
|
+
def test_shire
|
13
|
+
date = When.when? '2001.1.1^^Shire?time_basis=+09:00'
|
14
|
+
[["2001-01-01", 2451901],
|
15
|
+
["2002-01-01", 2452266],
|
16
|
+
["2003-01-01", 2452632],
|
17
|
+
["2004-01-01", 2452997],
|
18
|
+
["2005-01-01", 2453362],
|
19
|
+
["2006-01-01", 2453727],
|
20
|
+
["2007-01-01", 2454093],
|
21
|
+
["2008-01-01", 2454458],
|
22
|
+
["2009-01-01", 2454823],
|
23
|
+
["2010-01-01", 2455188],
|
24
|
+
["2011-01-01", 2455554],
|
25
|
+
["2012-01-01", 2455919],
|
26
|
+
["2013-01-01", 2456284],
|
27
|
+
["2014-01-01", 2456649],
|
28
|
+
["2015-01-01", 2457015],
|
29
|
+
["2016-01-01", 2457380],
|
30
|
+
["2017-01-01", 2457745],
|
31
|
+
["2018-01-01", 2458110],
|
32
|
+
["2019-01-01", 2458476],
|
33
|
+
["2020-01-01", 2458841],
|
34
|
+
["2021-01-01", 2459206],
|
35
|
+
["2022-01-01", 2459571],
|
36
|
+
["2023-01-01", 2459936],
|
37
|
+
["2024-01-01", 2460302],
|
38
|
+
["2025-01-01", 2460667],
|
39
|
+
["2026-01-01", 2461032],
|
40
|
+
["2027-01-01", 2461397],
|
41
|
+
["2028-01-01", 2461763],
|
42
|
+
["2029-01-01", 2462128],
|
43
|
+
["2030-01-01", 2462493],
|
44
|
+
["2031-01-01", 2462858],
|
45
|
+
["2032-01-01", 2463224],
|
46
|
+
["2033-01-01", 2463589]].each do |sample|
|
47
|
+
assert_equal(sample, [date.to_s, date.to_i])
|
48
|
+
date += When::P1Y
|
49
|
+
end
|
50
|
+
|
51
|
+
date = When.when? '2001.1.1'
|
52
|
+
400.times do
|
53
|
+
assert_equal([1,9], (When.Calendar('Shire') ^ date).cal_date[1..2])
|
54
|
+
date += When::P1Y
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
=begin
|
3
|
+
Copyright (C) 2014 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 MiniTest
|
10
|
+
|
11
|
+
class Swedish < MiniTest::TestCase
|
12
|
+
def test__swedish_date
|
13
|
+
|
14
|
+
dates = []
|
15
|
+
jdns = []
|
16
|
+
[2342042, 2346424].each do |base|
|
17
|
+
(-3..+3).each do |diff|
|
18
|
+
jdn = base + diff
|
19
|
+
jdate = When::Julian ^ jdn
|
20
|
+
s1date = When::Swedish ^ jdn
|
21
|
+
s2date = When.tm_pos(*(s1date.cal_date + [{:frame=>When::Swedish}]))
|
22
|
+
dates << s1date.to_s
|
23
|
+
jdns << [s1date.to_s == s2date.to_s, s1date.to_i == jdn, s2date.to_i == jdn].uniq
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
assert_equal(%w(1700-02-26 1700-02-27 1700-02-28 1700-03-01 1700-03-02 1700-03-03 1700-03-04
|
28
|
+
1712-02-26 1712-02-27 1712-02-28 1712-02-29 1712-02-30 1712-03-01 1712-03-02), dates)
|
29
|
+
assert_equal([[true]], jdns.uniq)
|
30
|
+
end
|
31
|
+
|
32
|
+
def test__swedish_easter
|
33
|
+
|
34
|
+
dates = []
|
35
|
+
civil = When.Calendar('Civil?old=Swedish&reform_date=1753-03-01')
|
36
|
+
((1700..1711).to_a + (1740..1752).to_a+[1802,1805,1818]).each do |year|
|
37
|
+
dates << When.tm_pos(year, {:frame=>civil}).easter.to_s
|
38
|
+
end
|
39
|
+
assert_equal(%w(1700-04-01 1701-04-21 1702-04-06 1703-03-29 1704-04-17 1705-04-02 1706-03-25
|
40
|
+
1707-04-14 1708-04-05 1709-04-18 1710-04-10 1711-03-26 1740-04-06 1741-03-22
|
41
|
+
1742-03-14 1743-04-03 1744-03-18 1745-04-07 1746-03-30 1747-03-22 1748-04-03
|
42
|
+
1749-03-26 1750-03-18 1751-03-31 1752-03-22 1802-04-25 1805-04-21 1818-03-29), dates)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
=begin
|
3
|
+
Copyright (C) 2014 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 MiniTest
|
10
|
+
|
11
|
+
class Zoroastrian < MiniTest::TestCase
|
12
|
+
def test_fasli
|
13
|
+
date = When.when? '1366.1.1^^Fasli?location=(_co:Iranian::Tehran)'
|
14
|
+
[["1366-01-01", "1996-03-20", 2450163],
|
15
|
+
["1367-01-01", "1997-03-20", 2450528],
|
16
|
+
["1368-01-01", "1998-03-21", 2450894],
|
17
|
+
["1369-01-01", "1999-03-21", 2451259],
|
18
|
+
["1370-01-01", "2000-03-20", 2451624],
|
19
|
+
["1371-01-01", "2001-03-20", 2451989],
|
20
|
+
["1372-01-01", "2002-03-21", 2452355],
|
21
|
+
["1373-01-01", "2003-03-21", 2452720],
|
22
|
+
["1374-01-01", "2004-03-20", 2453085],
|
23
|
+
["1375-01-01", "2005-03-20", 2453450],
|
24
|
+
["1376-01-01", "2006-03-21", 2453816],
|
25
|
+
["1377-01-01", "2007-03-21", 2454181],
|
26
|
+
["1378-01-01", "2008-03-20", 2454546],
|
27
|
+
["1379-01-01", "2009-03-20", 2454911],
|
28
|
+
["1380-01-01", "2010-03-21", 2455277],
|
29
|
+
["1381-01-01", "2011-03-21", 2455642],
|
30
|
+
["1382-01-01", "2012-03-20", 2456007],
|
31
|
+
["1383-01-01", "2013-03-20", 2456372],
|
32
|
+
["1384-01-01", "2014-03-21", 2456738],
|
33
|
+
["1385-01-01", "2015-03-21", 2457103],
|
34
|
+
["1386-01-01", "2016-03-20", 2457468],
|
35
|
+
["1387-01-01", "2017-03-20", 2457833],
|
36
|
+
["1388-01-01", "2018-03-21", 2458199],
|
37
|
+
["1389-01-01", "2019-03-21", 2458564],
|
38
|
+
["1390-01-01", "2020-03-20", 2458929],
|
39
|
+
["1391-01-01", "2021-03-20", 2459294],
|
40
|
+
["1392-01-01", "2022-03-21", 2459660],
|
41
|
+
["1393-01-01", "2023-03-21", 2460025],
|
42
|
+
["1394-01-01", "2024-03-20", 2460390],
|
43
|
+
["1395-01-01", "2025-03-20", 2460755],
|
44
|
+
["1396-01-01", "2026-03-20", 2461120],
|
45
|
+
["1397-01-01", "2027-03-21", 2461486],
|
46
|
+
["1398-01-01", "2028-03-20", 2461851]].each do |sample|
|
47
|
+
assert_equal(sample, [date.to_s, (When::Gregorian ^ date).to_s, date.to_i])
|
48
|
+
date += When::P1Y
|
49
|
+
end
|
50
|
+
|
51
|
+
date = When.when? '2001.3.21'
|
52
|
+
400.times do
|
53
|
+
assert_equal([1,1], (When.Calendar('Fasli') ^ date).cal_date[-2..-1])
|
54
|
+
date += When::P1Y
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
data/test/test/tmobjects.rb
CHANGED
@@ -310,6 +310,60 @@ module MiniTest::TM
|
|
310
310
|
assert_equal(sample[1], period[sample[0]])
|
311
311
|
end
|
312
312
|
end
|
313
|
+
|
314
|
+
def test__period_duration_diff
|
315
|
+
date1 = When.when?('2012-07-01')
|
316
|
+
date2 = When.when?('2012-07-02')
|
317
|
+
duration = date2 - date1
|
318
|
+
assert_equal('P1D', duration.to_s)
|
319
|
+
assert_equal(When::TM::PeriodDuration, duration.class)
|
320
|
+
|
321
|
+
if Object.const_defined?(:TZInfo)
|
322
|
+
time = When.when?('2013-03-10T01:00:00', :tz=>'America/New_York')
|
323
|
+
assert_equal('2013-03-10T02:30:00-04:00', (time + When.Duration('PT1.5H')).to_s) # ��ʂ�1.5����
|
324
|
+
else
|
325
|
+
puts
|
326
|
+
puts "Tests for TZInfo have been skipped at line #{__LINE__} of #{__FILE__.split(/\//)[-1]}."
|
327
|
+
end
|
328
|
+
|
329
|
+
vcal = When.Resource("examples/USA-DST.ics?C=New_York&Z=E&D=04&DZ=06&S=05&SZ=07")
|
330
|
+
time = When.when?('2013-03-10T01:00:00', :clock=>vcal['America/New_York'])
|
331
|
+
assert_equal('2013-03-10T02:30:00-04:00', (time + When.Duration('PT1.5H')).to_s) # ��ʂ�1.5����
|
332
|
+
end
|
333
|
+
|
334
|
+
Sample10 = %w(2013-01-31 2013-02-28 2013-03-31 2013-04-30 2013-05-31
|
335
|
+
2013-06-30 2013-07-31 2013-08-31 2013-09-30 2013-10-31)
|
336
|
+
|
337
|
+
Sample12 = %w(2013-01-31 2013-02-28 2013-03-31 2013-04-30 2013-05-31 2013-06-30
|
338
|
+
2013-07-31 2013-08-31 2013-09-30 2013-10-31 2013-11-30 2013-12-31)
|
339
|
+
|
340
|
+
def test__duration_each
|
341
|
+
sample = Sample10.dup
|
342
|
+
When::P1M.enum_for(When.when?('2013-01-31'), :forward, 10).each do |date|
|
343
|
+
assert_equal(sample.shift, date.to_s)
|
344
|
+
end
|
345
|
+
|
346
|
+
count = 0
|
347
|
+
(When.when?('2013-01-31') ^ When::P1M).each({:count_limit=>0}) do |date|
|
348
|
+
count += 1
|
349
|
+
end
|
350
|
+
assert_equal(0, count)
|
351
|
+
|
352
|
+
sample = Sample10.dup
|
353
|
+
(When.when?('2013-01-31') ^ When::P1M).each({:count_limit=>10}) do |date|
|
354
|
+
assert_equal(sample.shift, date.to_s)
|
355
|
+
end
|
356
|
+
|
357
|
+
sample = Sample12.dup
|
358
|
+
(When.when?('2013-01-31') ^ When::P1M).each({:until=>When.when?('2013-12-31')}) do |date|
|
359
|
+
assert_equal(sample.shift, date.to_s)
|
360
|
+
end
|
361
|
+
|
362
|
+
sample = Sample12.reverse
|
363
|
+
(When.when?('2013-12-31') ^ -When::P1M).each({:until=>When.when?('2013-01-31')}) do |date|
|
364
|
+
assert_equal(sample.shift, date.to_s)
|
365
|
+
end
|
366
|
+
end
|
313
367
|
end
|
314
368
|
|
315
369
|
class IntervalLength < MiniTest::TestCase
|
@@ -324,5 +378,25 @@ module MiniTest::TM
|
|
324
378
|
assert_equal(sample[1..5], [interval.value, interval.factor, interval.radix, interval.unit, interval.to_s])
|
325
379
|
end
|
326
380
|
end
|
381
|
+
|
382
|
+
def test__interval_length_diff
|
383
|
+
time1 = When.when?('2012-07-01T01:23:45+09:00')
|
384
|
+
time2 = When.when?('2012-07-02T01:23:45+09:00')
|
385
|
+
duration = time2 - time1
|
386
|
+
assert_equal('86401.0s', duration.to_s)
|
387
|
+
assert_equal(When::TM::IntervalLength, duration.class)
|
388
|
+
|
389
|
+
if Object.const_defined?(:TZInfo)
|
390
|
+
time = When.when?('2013-03-10T01:00:00', :tz=>'America/New_York')
|
391
|
+
assert_equal('2013-03-10T03:30:00-04:00', (time + When.Duration('1.5h')).to_s) # �����I��1.5����
|
392
|
+
else
|
393
|
+
puts
|
394
|
+
puts "Tests for TZInfo have been skipped at line #{__LINE__} of #{__FILE__.split(/\//)[-1]}."
|
395
|
+
end
|
396
|
+
|
397
|
+
vcal = When.Resource("examples/USA-DST.ics?C=New_York&Z=E&D=04&DZ=06&S=05&SZ=07")
|
398
|
+
time = When.when?('2013-03-10T01:00:00', :clock=>vcal['America/New_York'])
|
399
|
+
assert_equal('2013-03-10T03:30:00-04:00', (time + When.Duration('1.5h')).to_s) # �����I��1.5����
|
400
|
+
end
|
327
401
|
end
|
328
402
|
end
|