when_exe 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +333 -212
- data/bin/make_ttl.rb +37 -0
- data/bin/make_ttl.rb.config +9 -0
- data/lib/when_exe.rb +923 -925
- data/lib/when_exe/calendarnote.rb +9 -5
- data/lib/when_exe/coordinates.rb +2437 -2446
- data/lib/when_exe/inspect.rb +1480 -1408
- data/lib/when_exe/linkeddata.rb +574 -0
- data/lib/when_exe/locales/akt.rb +177 -176
- data/lib/when_exe/locales/locale.rb +751 -751
- data/lib/when_exe/mini_application.rb +307 -307
- data/lib/when_exe/parts/resource.rb +1115 -1103
- data/lib/when_exe/region/chinese/epochs.rb +6 -5
- data/lib/when_exe/region/christian.rb +831 -829
- data/lib/when_exe/region/japanese.rb +93 -93
- data/lib/when_exe/region/japanese/notes.rb +1510 -1495
- data/lib/when_exe/region/japanese/residues.rb +13 -13
- data/lib/when_exe/tmposition.rb +2307 -2273
- data/lib/when_exe/tmreference.rb +1744 -1734
- data/lib/when_exe/version.rb +2 -2
- data/link_to_online_documents +1 -1
- data/test/scripts/3.ext.rb +6 -6
- data/test/scripts/3.rb +6 -6
- data/test/test.rb +76 -75
- data/test/test/icalendar.rb +883 -879
- data/test/test/linkeddata.rb +224 -0
- data/test/test/region/m17n.rb +193 -193
- data/when_exe.gemspec +3 -2
- metadata +13 -6
data/lib/when_exe/version.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
=begin
|
3
|
-
Copyright (C) 2013-
|
3
|
+
Copyright (C) 2013-2015 Takashi SUGA
|
4
4
|
|
5
5
|
You may use and/or modify this file according to the license described in the LICENSE.txt file included in this archive.
|
6
6
|
=end
|
7
7
|
|
8
8
|
module When
|
9
|
-
VERSION = "0.4.
|
9
|
+
VERSION = "0.4.1"
|
10
10
|
end
|
data/link_to_online_documents
CHANGED
@@ -2,7 +2,7 @@ See online documents.
|
|
2
2
|
code: <https://github.com/suchowan/when_exe> (Please see README.md)
|
3
3
|
demo: <http://hosi.org> (Preferences - <http://hosi.org/cookies>)
|
4
4
|
gems: <https://rubygems.org/gems/when_exe>
|
5
|
-
yard: <http://rubydoc.info/gems/when_exe/frames>
|
5
|
+
yard: <http://rubydoc.info/gems/when_exe/frames> or <http://www2u.biglobe.ne.jp/~suchowan/when_exe/frames.html>
|
6
6
|
wiki: <http://www2u.biglobe.ne.jp/~suchowan/when_exe_wiki.html>(Japanese and machine translated English)
|
7
7
|
blog: <http://suchowan.at.webry.info/theme/a543700674.html> (Japanese)
|
8
8
|
dict: <http://www2u.biglobe.ne.jp/~suchowan/ResourceDictionary.html> (Japanese)
|
data/test/scripts/3.ext.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
=begin
|
3
|
-
Copyright (C) 2014 Takashi SUGA
|
3
|
+
Copyright (C) 2014-2015 Takashi SUGA
|
4
4
|
|
5
5
|
You may use and/or modify this file according to the license described in the LICENSE.txt file included in this archive.
|
6
6
|
=end
|
@@ -103,14 +103,14 @@ date = '1868-10-22'.when?
|
|
103
103
|
p date #=> 1868-10-22
|
104
104
|
list = date ^ 'Japanese'.calendar_era
|
105
105
|
p list #=> [慶応04(1868).09.07, 明治01(1868).09.07]
|
106
|
-
p list[0].
|
107
|
-
p list[1].
|
106
|
+
p list[0].calendar_era_go_back #=> nil
|
107
|
+
p list[1].calendar_era_go_back #=> true (改元前)
|
108
108
|
# **改元後
|
109
109
|
date = '1868-10-23'.when?
|
110
110
|
p date #=> 1868-10-23
|
111
111
|
list = date ^ 'Japanese'.calendar_era
|
112
112
|
p list #=> [明治01(1868).09.08]
|
113
|
-
p list[0].
|
113
|
+
p list[0].calendar_era_go_back #=> nil
|
114
114
|
p list[0].calendar_era.reference_date #=> 01(1868)
|
115
115
|
|
116
116
|
# 年号の reference_date の“精度”が“年”なら、年初に遡って検索をヒットさせる
|
@@ -121,13 +121,13 @@ date = '1912-7-29'.when?
|
|
121
121
|
p date #=> 1912-07-29
|
122
122
|
list = date ^ 'Japanese'.calendar_era
|
123
123
|
p list #=> [明治45(1912).07.29]
|
124
|
-
p list[0].
|
124
|
+
p list[0].calendar_era_go_back #=> nil
|
125
125
|
# **改元後
|
126
126
|
date = '1912-7-30'.when?
|
127
127
|
p date #=> 1912-07-30
|
128
128
|
list = date ^ 'Japanese'.calendar_era
|
129
129
|
p list #=> [大正01(1912).07.30]
|
130
|
-
p list[0].
|
130
|
+
p list[0].calendar_era_go_back #=> nil
|
131
131
|
p list[0].calendar_era.reference_date #=> 01(1912).07.30
|
132
132
|
|
133
133
|
# 年号の reference_date の“精度”が“日”なら、年初に遡って検索をヒットさせない
|
data/test/scripts/3.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
=begin
|
3
|
-
Copyright (C) 2014 Takashi SUGA
|
3
|
+
Copyright (C) 2014-2015 Takashi SUGA
|
4
4
|
|
5
5
|
You may use and/or modify this file according to the license described in the LICENSE.txt file included in this archive.
|
6
6
|
=end
|
@@ -104,14 +104,14 @@ date = when?('1868-10-22')
|
|
104
104
|
p date #=> 1868-10-22
|
105
105
|
list = date ^ CalendarEra('Japanese')
|
106
106
|
p list #=> [慶応04(1868).09.07, 明治01(1868).09.07]
|
107
|
-
p list[0].
|
108
|
-
p list[1].
|
107
|
+
p list[0].calendar_era_go_back #=> nil
|
108
|
+
p list[1].calendar_era_go_back #=> true (改元前)
|
109
109
|
# **改元後
|
110
110
|
date = when?('1868-10-23')
|
111
111
|
p date #=> 1868-10-23
|
112
112
|
list = date ^ CalendarEra('Japanese')
|
113
113
|
p list #=> [明治01(1868).09.08]
|
114
|
-
p list[0].
|
114
|
+
p list[0].calendar_era_go_back #=> nil
|
115
115
|
p list[0].calendar_era.reference_date #=> 01(1868)
|
116
116
|
|
117
117
|
# 年号の reference_date の“精度”が“年”なら、年初に遡って検索をヒットさせる
|
@@ -122,13 +122,13 @@ date = when?('1912-7-29')
|
|
122
122
|
p date #=> 1912-07-29
|
123
123
|
list = date ^ CalendarEra('Japanese')
|
124
124
|
p list #=> [明治45(1912).07.29]
|
125
|
-
p list[0].
|
125
|
+
p list[0].calendar_era_go_back #=> nil
|
126
126
|
# **改元後
|
127
127
|
date = when?('1912-7-30')
|
128
128
|
p date #=> 1912-07-30
|
129
129
|
list = date ^ CalendarEra('Japanese')
|
130
130
|
p list #=> [大正01(1912).07.30]
|
131
|
-
p list[0].
|
131
|
+
p list[0].calendar_era_go_back #=> nil
|
132
132
|
p list[0].calendar_era.reference_date #=> 01(1912).07.30
|
133
133
|
|
134
134
|
# 年号の reference_date の“精度”が“日”なら、年初に遡って検索をヒットさせない
|
data/test/test.rb
CHANGED
@@ -1,75 +1,76 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# -*- coding: utf-8 -*-
|
3
|
-
=begin
|
4
|
-
Copyright (C) 2011-2014 Takashi SUGA
|
5
|
-
|
6
|
-
You may use and/or modify this file according to the license
|
7
|
-
described in the LICENSE.txt file included in this archive.
|
8
|
-
=end
|
9
|
-
|
10
|
-
require 'pp'
|
11
|
-
require 'date'
|
12
|
-
begin
|
13
|
-
require 'minitest/autorun'
|
14
|
-
module MiniTest
|
15
|
-
TestCase = MiniTest.const_defined?(:Test) ? Test : Unit::TestCase
|
16
|
-
end
|
17
|
-
rescue LoadError
|
18
|
-
require 'test/unit'
|
19
|
-
MiniTest = Test
|
20
|
-
module Test
|
21
|
-
TestCase = Unit::TestCase
|
22
|
-
class Unit::TestCase
|
23
|
-
alias :assert_raises :assert_raise
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
class MiniTest::TestCase
|
29
|
-
def setup
|
30
|
-
When._setup_({:multi_thread=>true})
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
require 'when_exe'
|
35
|
-
require 'when_exe/mini_application'
|
36
|
-
#include When
|
37
|
-
|
38
|
-
require './test/parts'
|
39
|
-
require './test/basictypes'
|
40
|
-
require './test/ephemeris'
|
41
|
-
require './test/timestandard'
|
42
|
-
require './test/coordinates'
|
43
|
-
require './test/icalendar'
|
44
|
-
require './test/tmobjects'
|
45
|
-
require './test/tmreference'
|
46
|
-
require './test/tmposition'
|
47
|
-
require './test/calendartypes'
|
48
|
-
require './test/calendarnote'
|
49
|
-
require './test/inspect'
|
50
|
-
require './test/
|
51
|
-
require './test/
|
52
|
-
require './test/region/
|
53
|
-
require './test/region/
|
54
|
-
require './test/region/
|
55
|
-
require './test/region/
|
56
|
-
require './test/region/
|
57
|
-
require './test/region/
|
58
|
-
require './test/region/
|
59
|
-
require './test/region/
|
60
|
-
require './test/region/
|
61
|
-
require './test/region/
|
62
|
-
require './test/region/
|
63
|
-
require './test/region/
|
64
|
-
require './test/region/
|
65
|
-
require './test/region/
|
66
|
-
require './test/region/
|
67
|
-
require './test/region/
|
68
|
-
require './test/region/
|
69
|
-
require './test/region/
|
70
|
-
require './test/region/
|
71
|
-
require './test/region/
|
72
|
-
require './test/region/
|
73
|
-
require './test/region/
|
74
|
-
require './test/region/
|
75
|
-
require './test/region/
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
=begin
|
4
|
+
Copyright (C) 2011-2014 Takashi SUGA
|
5
|
+
|
6
|
+
You may use and/or modify this file according to the license
|
7
|
+
described in the LICENSE.txt file included in this archive.
|
8
|
+
=end
|
9
|
+
|
10
|
+
require 'pp'
|
11
|
+
require 'date'
|
12
|
+
begin
|
13
|
+
require 'minitest/autorun'
|
14
|
+
module MiniTest
|
15
|
+
TestCase = MiniTest.const_defined?(:Test) ? Test : Unit::TestCase
|
16
|
+
end
|
17
|
+
rescue LoadError
|
18
|
+
require 'test/unit'
|
19
|
+
MiniTest = Test
|
20
|
+
module Test
|
21
|
+
TestCase = Unit::TestCase
|
22
|
+
class Unit::TestCase
|
23
|
+
alias :assert_raises :assert_raise
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
class MiniTest::TestCase
|
29
|
+
def setup
|
30
|
+
When._setup_({:multi_thread=>true})
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
require 'when_exe'
|
35
|
+
require 'when_exe/mini_application'
|
36
|
+
#include When
|
37
|
+
|
38
|
+
require './test/parts'
|
39
|
+
require './test/basictypes'
|
40
|
+
require './test/ephemeris'
|
41
|
+
require './test/timestandard'
|
42
|
+
require './test/coordinates'
|
43
|
+
require './test/icalendar'
|
44
|
+
require './test/tmobjects'
|
45
|
+
require './test/tmreference'
|
46
|
+
require './test/tmposition'
|
47
|
+
require './test/calendartypes'
|
48
|
+
require './test/calendarnote'
|
49
|
+
require './test/inspect'
|
50
|
+
require './test/linkeddata'
|
51
|
+
require './test/googlecalendar'
|
52
|
+
require './test/region/m17n'
|
53
|
+
require './test/region/residue'
|
54
|
+
require './test/region/christian'
|
55
|
+
require './test/region/swedish'
|
56
|
+
require './test/region/armenian'
|
57
|
+
require './test/region/japanese'
|
58
|
+
require './test/region/chinese'
|
59
|
+
require './test/region/vietnamese'
|
60
|
+
require './test/region/tibetan'
|
61
|
+
require './test/region/balinese'
|
62
|
+
require './test/region/thai'
|
63
|
+
require './test/region/indian'
|
64
|
+
require './test/region/iran'
|
65
|
+
require './test/region/islamic'
|
66
|
+
require './test/region/jewish'
|
67
|
+
require './test/region/french'
|
68
|
+
require './test/region/coptic'
|
69
|
+
require './test/region/bahai'
|
70
|
+
require './test/region/mayan'
|
71
|
+
require './test/region/discordian'
|
72
|
+
require './test/region/zoroastrian'
|
73
|
+
require './test/region/yerm'
|
74
|
+
require './test/region/reforms'
|
75
|
+
require './test/region/shire'
|
76
|
+
require './test/region/geologicalage'
|
data/test/test/icalendar.rb
CHANGED
@@ -1,879 +1,883 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
=begin
|
3
|
-
Copyright (C) 2011-
|
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:V
|
10
|
-
|
11
|
-
class Root < MiniTest::TestCase
|
12
|
-
def test_nothing
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
class Calendar < MiniTest::TestCase
|
17
|
-
def test__each
|
18
|
-
When::TM::Clock.local_time = When.Clock("+0900")
|
19
|
-
cal = When.Resource("examples/JapanHolidays.ics")
|
20
|
-
sample = [
|
21
|
-
"2010-01-01T+09:00",
|
22
|
-
"2010-01-11T+09:00",
|
23
|
-
"2010-02-11T+09:00",
|
24
|
-
"2010-03-21T+09:00",
|
25
|
-
"2010-03-22T+09:00",
|
26
|
-
"2010-04-29T+09:00",
|
27
|
-
"2010-05-03T+09:00",
|
28
|
-
"2010-05-04T+09:00",
|
29
|
-
"2010-05-05T+09:00",
|
30
|
-
"2010-07-19T+09:00",
|
31
|
-
"2010-09-20T+09:00",
|
32
|
-
"2010-09-23T+09:00",
|
33
|
-
"2010-10-11T+09:00",
|
34
|
-
"2010-11-03T+09:00",
|
35
|
-
"2010-11-23T+09:00",
|
36
|
-
"2010-12-23T+09:00",
|
37
|
-
]
|
38
|
-
cal.each(When.when?('20100101')...When.when?('20110101')) do |date|
|
39
|
-
assert_equal(sample.shift, date.to_s)
|
40
|
-
end
|
41
|
-
assert_equal([], sample)
|
42
|
-
|
43
|
-
cal = cal.intersection({'summary'=>'成人の日'})
|
44
|
-
sample = [
|
45
|
-
"2010-01-11T+09:00",
|
46
|
-
]
|
47
|
-
cal.each(When.when?('20100101')...When.when?('20110101')) do |date|
|
48
|
-
assert_equal(sample.shift, date.to_s)
|
49
|
-
end
|
50
|
-
assert_equal([], sample)
|
51
|
-
end
|
52
|
-
|
53
|
-
def test__byweekno
|
54
|
-
sample = [
|
55
|
-
"1997-05-12",
|
56
|
-
"1998-05-11",
|
57
|
-
"1999-05-17"
|
58
|
-
]
|
59
|
-
event = When::V::Event.new({
|
60
|
-
'rrule' => 'FREQ=YEARLY;BYDAY=MO;BYWEEKNO=20',
|
61
|
-
'dtstart' => 'VALUE=DATE:19970512'
|
62
|
-
})
|
63
|
-
event.enum_for(When.when?('19970512'), :forward, 3, {'1st'=>"don't care"}).each do |date|
|
64
|
-
assert_equal(sample.shift, date.to_s)
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
def test__include_event
|
69
|
-
d0504 = When.when?('20100504')
|
70
|
-
d0505 = When.when?('20100505')
|
71
|
-
|
72
|
-
cal = When.Resource("examples/JapanHolidays.ics")
|
73
|
-
it = cal.enum_for(When.when?('20100501'))
|
74
|
-
date = it.next
|
75
|
-
assert_equal(["2010-05-03T+09:00", 0], [date.to_s, date.precision])
|
76
|
-
assert_equal([true,true], [d0504,d0505].map {|v| cal.include?(v)})
|
77
|
-
|
78
|
-
event = When::Parts::Resource["examples/JapanHolidays.ics::Midori_no_hi_2"] # みどりの日
|
79
|
-
it = event.enum_for(When.when?('20100501'))
|
80
|
-
date = it.next
|
81
|
-
assert_equal(["2010-05-04T+09:00", 0], [date.to_s, date.precision])
|
82
|
-
assert_equal([true,false], [d0504,d0505].map {|v| event.include?(v)})
|
83
|
-
end
|
84
|
-
|
85
|
-
def test__rfc_update
|
86
|
-
sample = ["Children's_Day_(Japan)", 'Children"s_Day_(Japan)', "Children's_Day_(Japan)"]
|
87
|
-
When::TM::Clock.local_time = When.Clock("+0900")
|
88
|
-
["JapanHolidays.ics", "JapanHolidays.ics?Escape=^'", "JapanHolidaysRFC6350.ics"].each do |ics|
|
89
|
-
cal = When.Resource('examples/' + ics)
|
90
|
-
cal = cal.intersection({'summary'=>/Children['"]s_Day_\(Japan\)/})
|
91
|
-
cal.each(When.when?('20100101')...When.when?('20110101')) do |date|
|
92
|
-
assert_equal(sample.shift, date.events[0].summary / 'en')
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
class Event < MiniTest::TestCase
|
99
|
-
def test__event
|
100
|
-
When::TM::Clock.local_time = When.Clock("+0900")
|
101
|
-
event = When::V::Event.new({
|
102
|
-
'rrule' => {'FREQ'=>'MONTHLY', 'INTERVAL'=>12, 'BYDAY'=>{''=>'2MO'}},
|
103
|
-
'dtstart' => 'VALUE=DATE:20070108'
|
104
|
-
})
|
105
|
-
sample = [
|
106
|
-
"2007-01-08",
|
107
|
-
"2008-01-14",
|
108
|
-
"2009-01-12",
|
109
|
-
"2010-01-11",
|
110
|
-
"2011-01-10",
|
111
|
-
"2012-01-09",
|
112
|
-
"2013-01-14",
|
113
|
-
"2014-01-13",
|
114
|
-
"2015-01-12",
|
115
|
-
"2016-01-11"
|
116
|
-
]
|
117
|
-
event.enum_for(When.when?('20070101'), :forward, 10).each do |date|
|
118
|
-
assert_equal(sample.shift, date.to_s)
|
119
|
-
end
|
120
|
-
assert_equal([], sample)
|
121
|
-
|
122
|
-
sample = [
|
123
|
-
"2007-01-08",
|
124
|
-
"2007-01-15",
|
125
|
-
"2007-01-22",
|
126
|
-
"2007-01-29",
|
127
|
-
"2007-02-05",
|
128
|
-
"2007-02-12",
|
129
|
-
"2007-02-19",
|
130
|
-
"2007-02-26",
|
131
|
-
"2007-03-05",
|
132
|
-
"2007-03-12"
|
133
|
-
]
|
134
|
-
event = When::V::Event.new({
|
135
|
-
'rrule' => {'FREQ'=>'P1W'},
|
136
|
-
'dtstart' => 'VALUE=DATE:20070108'
|
137
|
-
})
|
138
|
-
event.enum_for(When.when?('20070101'), :forward, 10).each do |date|
|
139
|
-
assert_equal(sample.shift, date.to_s)
|
140
|
-
end
|
141
|
-
assert_equal([], sample)
|
142
|
-
end
|
143
|
-
|
144
|
-
def test__last_work_days # See RFC 5545 [Page 43]
|
145
|
-
sample = [
|
146
|
-
"2011-01-28",
|
147
|
-
"2011-01-31",
|
148
|
-
"2011-02-25",
|
149
|
-
"2011-02-28",
|
150
|
-
"2011-03-30",
|
151
|
-
"2011-03-31",
|
152
|
-
]
|
153
|
-
event = When::V::Event.new({
|
154
|
-
'rrule' => 'FREQ=MONTHLY;BYDAY=MO,TU,WE,TH,FR;BYSETPOS=-1,-2',
|
155
|
-
'dtstart' => 'VALUE=DATE:20010101'
|
156
|
-
})
|
157
|
-
event.enum_for(When.when?('20110101'), :forward, 6).each do |date|
|
158
|
-
assert_equal(sample.shift, date.to_s)
|
159
|
-
end
|
160
|
-
assert_equal([], sample)
|
161
|
-
end
|
162
|
-
|
163
|
-
def test__ignored_invalid_date
|
164
|
-
When.Resource("examples/USA-DST.ics?C=New_York&Z=E&D=04&DZ=06&S=05&SZ=07")
|
165
|
-
assert_equal("2007-03-30T09:00:00-04:00", When.when?('TZID=America/New_York:2007-03-30T09:00:00').to_s)
|
166
|
-
sample = [
|
167
|
-
"2007-01-15T09:00:00-05:00",
|
168
|
-
"2007-01-30T09:00:00-05:00",
|
169
|
-
"2007-02-15T09:00:00-05:00",
|
170
|
-
"2007-03-15T09:00:00-04:00",
|
171
|
-
"2007-03-30T09:00:00-04:00",
|
172
|
-
]
|
173
|
-
When::V::Event.new({
|
174
|
-
'rrule' => 'FREQ=MONTHLY;BYMONTHDAY=15,30;COUNT=5',
|
175
|
-
'dtstart' => 'TZID=America/New_York:20070115T090000'
|
176
|
-
}).each do |date|
|
177
|
-
assert_equal(sample.shift, date.to_s)
|
178
|
-
break if sample == []
|
179
|
-
end
|
180
|
-
end
|
181
|
-
|
182
|
-
if Object.const_defined?(:TZInfo)
|
183
|
-
def test__ignored_invalid_date_chicago
|
184
|
-
assert_equal("2007-03-30T09:00:00-05:00", When.when?('TZID=America/Chicago:2007-03-30T09:00:00').to_s)
|
185
|
-
sample = [
|
186
|
-
"2007-01-15T09:00:00-06:00",
|
187
|
-
"2007-01-30T09:00:00-06:00",
|
188
|
-
"2007-02-15T09:00:00-06:00",
|
189
|
-
"2007-03-15T09:00:00-05:00",
|
190
|
-
"2007-03-30T09:00:00-05:00",
|
191
|
-
]
|
192
|
-
When::V::Event.new({
|
193
|
-
'rrule' => 'FREQ=MONTHLY;BYMONTHDAY=15,30;COUNT=5',
|
194
|
-
'dtstart' => 'TZID=America/Chicago:20070115T090000'
|
195
|
-
}).each do |date|
|
196
|
-
assert_equal(sample.shift, date.to_s)
|
197
|
-
break if sample == []
|
198
|
-
end
|
199
|
-
end
|
200
|
-
else
|
201
|
-
puts "Tests for TZInfo have been skipped at line #{__LINE__} of #{__FILE__.split(/\//)[-1]}."
|
202
|
-
end
|
203
|
-
|
204
|
-
def test__multiple_BYxxx_rule # See RFC 5545 [Page 45]
|
205
|
-
When.Resource("examples/USA-DST.ics?C=New_York&Z=E&D=04&DZ=06&S=05&SZ=07")
|
206
|
-
|
207
|
-
sample = [
|
208
|
-
"1997-04-13T01:30:00-04:00",
|
209
|
-
"1997-04-13T02:30:00-04:00",
|
210
|
-
"1997-04-13T03:30:00-04:00",
|
211
|
-
"1998-04-12T01:30:00-04:00",
|
212
|
-
]
|
213
|
-
When::V::Event.new({
|
214
|
-
'rrule' => 'FREQ=YEARLY;BYMONTH=4;BYDAY=2SU;BYHOUR=1,2,3;BYMINUTE=30',
|
215
|
-
'dtstart' => 'TZID=America/New_York:19970413T013000'
|
216
|
-
}).each do |date|
|
217
|
-
assert_equal(sample.shift, date.to_s)
|
218
|
-
break if sample == []
|
219
|
-
end
|
220
|
-
|
221
|
-
sample = [
|
222
|
-
"1997-04-06T01:30:00-05:00",
|
223
|
-
"1997-04-06T03:30:00-04:00",
|
224
|
-
"1997-04-06T04:30:00-04:00",
|
225
|
-
"1998-04-05T01:30:00-05:00",
|
226
|
-
]
|
227
|
-
When::V::Event.new({
|
228
|
-
'rrule' => 'FREQ=YEARLY;BYMONTH=4;BYDAY=1SU;BYHOUR=1,2,3,4;BYMINUTE=30',
|
229
|
-
'dtstart' => 'TZID=America/New_York:19970406T013000'
|
230
|
-
}).each do |date|
|
231
|
-
assert_equal(sample.shift, date.to_s)
|
232
|
-
break if sample == []
|
233
|
-
end
|
234
|
-
|
235
|
-
sample = [
|
236
|
-
"1997-10-26T01:30:00-04:00",
|
237
|
-
"1997-10-26T01:30:00-05:00", # * 02:30:00-04:00
|
238
|
-
"1997-10-26T02:30:00-05:00",
|
239
|
-
"1997-10-26T03:30:00-05:00",
|
240
|
-
"1998-10-25T01:30:00-04:00",
|
241
|
-
]
|
242
|
-
When::V::Event.new({
|
243
|
-
'rrule' => 'FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU;BYHOUR=1,1=,2,3;BYMINUTE=30', # *
|
244
|
-
'dtstart' => 'TZID=America/New_York:19971026T013000'
|
245
|
-
}).each do |date|
|
246
|
-
assert_equal(sample.shift, date.to_s)
|
247
|
-
break if sample == []
|
248
|
-
end
|
249
|
-
|
250
|
-
sample = [
|
251
|
-
"1997-10-19T01:30:00-04:00",
|
252
|
-
"1997-10-19T02:30:00-04:00",
|
253
|
-
"1998-10-18T01:30:00-04:00",
|
254
|
-
]
|
255
|
-
When::V::Event.new({
|
256
|
-
'rrule' => 'FREQ=YEARLY;BYMONTH=10;BYDAY=-2SU;BYHOUR=1,1=,2;BYMINUTE=30', # *
|
257
|
-
'dtstart' => 'TZID=America/New_York:19971019T013000'
|
258
|
-
}).each do |date|
|
259
|
-
assert_equal(sample.shift, date.to_s)
|
260
|
-
break if sample == []
|
261
|
-
end
|
262
|
-
end
|
263
|
-
|
264
|
-
if Object.const_defined?(:TZInfo)
|
265
|
-
def test__multiple_BYxxx_rule_chicago # See RFC 5545 [Page 45]
|
266
|
-
sample = [
|
267
|
-
"1997-04-13T01:30:00-05:00",
|
268
|
-
"1997-04-13T02:30:00-05:00",
|
269
|
-
"1997-04-13T03:30:00-05:00",
|
270
|
-
"1998-04-12T01:30:00-05:00",
|
271
|
-
]
|
272
|
-
When::V::Event.new({
|
273
|
-
'rrule' => 'FREQ=YEARLY;BYMONTH=4;BYDAY=2SU;BYHOUR=1,2,3;BYMINUTE=30',
|
274
|
-
'dtstart' => 'TZID=America/Chicago:19970413T013000'
|
275
|
-
}).each do |date|
|
276
|
-
assert_equal(sample.shift, date.to_s)
|
277
|
-
break if sample == []
|
278
|
-
end
|
279
|
-
|
280
|
-
sample = [
|
281
|
-
"1997-04-06T01:30:00-06:00",
|
282
|
-
"1997-04-06T03:30:00-05:00", # TODO !!
|
283
|
-
"1997-04-06T04:30:00-05:00",
|
284
|
-
"1998-04-05T01:30:00-06:00",
|
285
|
-
]
|
286
|
-
When::V::Event.new({
|
287
|
-
'rrule' => 'FREQ=YEARLY;BYMONTH=4;BYDAY=1SU;BYHOUR=1,2,3,4;BYMINUTE=30',
|
288
|
-
'dtstart' => 'TZID=America/Chicago:19970406T013000'
|
289
|
-
}).each do |date|
|
290
|
-
assert_equal(sample.shift, date.to_s)
|
291
|
-
break if sample == []
|
292
|
-
end
|
293
|
-
|
294
|
-
sample = [
|
295
|
-
"1997-10-26T01:30:00-05:00",
|
296
|
-
"1997-10-26T01:30:00-06:00", # * - TODO !!
|
297
|
-
"1997-10-26T02:30:00-06:00",
|
298
|
-
"1997-10-26T03:30:00-06:00",
|
299
|
-
"1998-10-25T01:30:00-05:00",
|
300
|
-
]
|
301
|
-
When::V::Event.new({
|
302
|
-
'rrule' => 'FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU;BYHOUR=1,1=,2,3;BYMINUTE=30', # *
|
303
|
-
'dtstart' => 'TZID=America/Chicago:19971026T013000'
|
304
|
-
}).each do |date|
|
305
|
-
assert_equal(sample.shift, date.to_s)
|
306
|
-
break if sample == []
|
307
|
-
end
|
308
|
-
sample = [
|
309
|
-
"1997-10-19T01:30:00-05:00",
|
310
|
-
"1997-10-19T02:30:00-05:00",
|
311
|
-
"1998-10-18T01:30:00-05:00",
|
312
|
-
]
|
313
|
-
When::V::Event.new({
|
314
|
-
'rrule' => 'FREQ=YEARLY;BYMONTH=10;BYDAY=-2SU;BYHOUR=1,1=,2;BYMINUTE=30', # *
|
315
|
-
'dtstart' => 'TZID=America/Chicago:19971019T013000'
|
316
|
-
}).each do |date|
|
317
|
-
assert_equal(sample.shift, date.to_s)
|
318
|
-
break if sample == []
|
319
|
-
end
|
320
|
-
end
|
321
|
-
else
|
322
|
-
puts "Tests for TZInfo have been skipped at line #{__LINE__} of #{__FILE__.split(/\//)[-1]}."
|
323
|
-
end
|
324
|
-
|
325
|
-
def julian_easter(yy)
|
326
|
-
a = yy % 4
|
327
|
-
b = yy % 7
|
328
|
-
c = yy % 19
|
329
|
-
d = (19 * c + 15) % 30
|
330
|
-
e = (2 * a + 4 * b - d + 34) % 7
|
331
|
-
mm = (d + e + 114) / 31
|
332
|
-
dd = ((d + e + 114) % 31) + 1
|
333
|
-
[yy, mm, dd]
|
334
|
-
end
|
335
|
-
|
336
|
-
def gregorian_easter(yy)
|
337
|
-
a = yy % 19
|
338
|
-
b = yy / 100
|
339
|
-
c = yy % 100
|
340
|
-
d = b / 4
|
341
|
-
e = b % 4
|
342
|
-
f = (b + 8) / 25
|
343
|
-
g = (b - f + 1) / 3
|
344
|
-
h = (19 * a + b - d - g + 15) % 30
|
345
|
-
i = c / 4
|
346
|
-
k = c % 4
|
347
|
-
l = (32 + 2 * e + 2 * i - h - k) % 7
|
348
|
-
m = (a + 11 * h + 22 * l) / 451
|
349
|
-
mm = (h + l - 7 * m + 114) / 31
|
350
|
-
dd = ((h + l - 7 * m + 114) % 31) + 1
|
351
|
-
[yy, mm, dd]
|
352
|
-
end
|
353
|
-
|
354
|
-
def test__easter
|
355
|
-
jc = When.Resource('_c:Julian')
|
356
|
-
other = []
|
357
|
-
myself = []
|
358
|
-
532.times do |yy|
|
359
|
-
y,m,d = julian_easter(yy+325)
|
360
|
-
other << jc._coordinates_to_number(y,m-1,d-1)
|
361
|
-
myself << jc.easter(yy+325)
|
362
|
-
end
|
363
|
-
assert_equal(other, myself)
|
364
|
-
|
365
|
-
gc = When.Resource('_c:Gregorian')
|
366
|
-
other = []
|
367
|
-
myself = []
|
368
|
-
5700.times do |yy| # Should be 5_700_000
|
369
|
-
y,m,d = gregorian_easter(yy+1582)
|
370
|
-
other << gc._coordinates_to_number(y,m-1,d-1)
|
371
|
-
myself << gc.easter(yy+1582)
|
372
|
-
end
|
373
|
-
assert_equal(other, myself)
|
374
|
-
|
375
|
-
date = When.when?('2011').easter
|
376
|
-
assert_equal("2011-04-24", date.to_s)
|
377
|
-
|
378
|
-
sample = [
|
379
|
-
"2009-04-12",
|
380
|
-
# "2010-04-02",
|
381
|
-
"2011-04-22",
|
382
|
-
]
|
383
|
-
event = When::V::Event.new({
|
384
|
-
'rrule' => 'FREQ=YEARLY;INTERVAL=2;BYDAY/Christian=easter-2',
|
385
|
-
'dtstart' => '20090412'
|
386
|
-
})
|
387
|
-
event.each do |date|
|
388
|
-
assert_equal(sample.shift, date.to_s)
|
389
|
-
break if sample == []
|
390
|
-
end
|
391
|
-
|
392
|
-
sample = [
|
393
|
-
"2011-04-22",
|
394
|
-
]
|
395
|
-
event.enum_for(When.when?('20100101')).each do |date|
|
396
|
-
assert_equal(sample.shift, date.to_s)
|
397
|
-
break if sample == []
|
398
|
-
end
|
399
|
-
|
400
|
-
sample = [
|
401
|
-
"2009-04-12",
|
402
|
-
"2010-03-30",
|
403
|
-
"2011-04-17",
|
404
|
-
"2012-04-07"
|
405
|
-
]
|
406
|
-
event = When::V::Event.new({
|
407
|
-
'rrule' => 'FREQ=YEARLY;BYDAY/Christian?w=7=easter',
|
408
|
-
'dtstart' => '20090412'
|
409
|
-
})
|
410
|
-
event.each do |date|
|
411
|
-
assert_equal(sample.shift, date.to_s)
|
412
|
-
break if sample == []
|
413
|
-
end
|
414
|
-
|
415
|
-
sample = [
|
416
|
-
"2009-12-25",
|
417
|
-
"2010-12-25",
|
418
|
-
"2011-12-25",
|
419
|
-
]
|
420
|
-
When::V::Event.new({
|
421
|
-
'rrule' => 'FREQ=YEARLY;BYDAY/Christian=christmas',
|
422
|
-
'dtstart' => '20091225'
|
423
|
-
}).each do |date|
|
424
|
-
assert_equal(sample.shift, date.to_s)
|
425
|
-
break if sample == []
|
426
|
-
end
|
427
|
-
end
|
428
|
-
|
429
|
-
def test__terms
|
430
|
-
|
431
|
-
event = When::V::Event.new({
|
432
|
-
'rrule' => 'FREQ=YEARLY;INTERVAL=2;BYDAY/SolarTerms=term180',
|
433
|
-
'dtstart' => '20090922'
|
434
|
-
})
|
435
|
-
sample = [
|
436
|
-
"2011-09-23",
|
437
|
-
]
|
438
|
-
event.enum_for(When.when?('20100101')).each do |date|
|
439
|
-
assert_equal(sample.shift, date.to_s)
|
440
|
-
break if sample == []
|
441
|
-
end
|
442
|
-
|
443
|
-
sample = [
|
444
|
-
"2009-09-22",
|
445
|
-
# "2010-09-22",
|
446
|
-
"2011-09-23",
|
447
|
-
]
|
448
|
-
event.each do |date|
|
449
|
-
assert_equal(sample.shift, date.to_s)
|
450
|
-
break if sample == []
|
451
|
-
end
|
452
|
-
end
|
453
|
-
end
|
454
|
-
|
455
|
-
class Alarm < MiniTest::TestCase
|
456
|
-
def test_nothing
|
457
|
-
end
|
458
|
-
end
|
459
|
-
|
460
|
-
class Todo < MiniTest::TestCase
|
461
|
-
def test__todo
|
462
|
-
When::TM::Clock.local_time = When.Clock("+0900")
|
463
|
-
event = When::V::Todo.new({
|
464
|
-
'rrule' => {'FREQ'=>'YEARLY', 'BYMONTH'=>1, 'BYDAY'=>{''=>'2MO'}},
|
465
|
-
'due' => 'VALUE=DATE:
|
466
|
-
})
|
467
|
-
sample = [
|
468
|
-
"2011-01-10",
|
469
|
-
"2012-01-09",
|
470
|
-
"2013-01-14",
|
471
|
-
"2014-01-13",
|
472
|
-
"2015-01-12",
|
473
|
-
"2016-01-11"
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
["1997-
|
513
|
-
["1997-
|
514
|
-
["1997-
|
515
|
-
["1997-10-
|
516
|
-
["1997-10-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
["
|
527
|
-
["
|
528
|
-
["
|
529
|
-
["
|
530
|
-
["
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
["
|
548
|
-
["
|
549
|
-
["
|
550
|
-
["
|
551
|
-
["
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
["1997-
|
564
|
-
["1997-
|
565
|
-
["1997-
|
566
|
-
["1997-10-
|
567
|
-
["1997-10-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
assert_equal("1997-
|
642
|
-
assert_equal("
|
643
|
-
assert_equal("
|
644
|
-
|
645
|
-
|
646
|
-
assert_equal(
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
"
|
666
|
-
"
|
667
|
-
"
|
668
|
-
"
|
669
|
-
"
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
"
|
699
|
-
"
|
700
|
-
"
|
701
|
-
"
|
702
|
-
"
|
703
|
-
"
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
|
714
|
-
|
715
|
-
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
|
720
|
-
|
721
|
-
"1997-09-
|
722
|
-
"1997-09-
|
723
|
-
"1997-09-
|
724
|
-
"1997-09-
|
725
|
-
"1997-09-
|
726
|
-
"1997-09-
|
727
|
-
"1997-09-
|
728
|
-
"1997-09-
|
729
|
-
"1997-09-
|
730
|
-
"1997-09-
|
731
|
-
"1997-09-
|
732
|
-
"1997-09-
|
733
|
-
"1997-09-
|
734
|
-
"1997-09-
|
735
|
-
"1997-09-
|
736
|
-
"1997-09-
|
737
|
-
"1997-09-
|
738
|
-
"1997-09-
|
739
|
-
"1997-09-
|
740
|
-
"1997-09-
|
741
|
-
"1997-09-
|
742
|
-
"1997-09-
|
743
|
-
"1997-09-
|
744
|
-
"1997-09-
|
745
|
-
"1997-09-
|
746
|
-
"1997-09-
|
747
|
-
|
748
|
-
|
749
|
-
|
750
|
-
|
751
|
-
|
752
|
-
|
753
|
-
|
754
|
-
|
755
|
-
|
756
|
-
|
757
|
-
|
758
|
-
"1997-09-
|
759
|
-
"1997-09-
|
760
|
-
"1997-09-
|
761
|
-
"1997-09-
|
762
|
-
"1997-09-
|
763
|
-
"1997-09-
|
764
|
-
|
765
|
-
|
766
|
-
|
767
|
-
|
768
|
-
|
769
|
-
|
770
|
-
|
771
|
-
|
772
|
-
|
773
|
-
|
774
|
-
|
775
|
-
|
776
|
-
|
777
|
-
|
778
|
-
|
779
|
-
|
780
|
-
|
781
|
-
|
782
|
-
|
783
|
-
|
784
|
-
|
785
|
-
|
786
|
-
|
787
|
-
|
788
|
-
|
789
|
-
|
790
|
-
|
791
|
-
"1997-09-
|
792
|
-
"1997-09-
|
793
|
-
"1997-09-
|
794
|
-
"1997-09-
|
795
|
-
"1997-09-
|
796
|
-
"1997-09-
|
797
|
-
"1997-09-
|
798
|
-
|
799
|
-
|
800
|
-
|
801
|
-
|
802
|
-
|
803
|
-
|
804
|
-
|
805
|
-
|
806
|
-
|
807
|
-
|
808
|
-
|
809
|
-
|
810
|
-
|
811
|
-
|
812
|
-
|
813
|
-
|
814
|
-
|
815
|
-
|
816
|
-
|
817
|
-
|
818
|
-
|
819
|
-
|
820
|
-
|
821
|
-
|
822
|
-
|
823
|
-
|
824
|
-
|
825
|
-
|
826
|
-
|
827
|
-
|
828
|
-
|
829
|
-
|
830
|
-
|
831
|
-
|
832
|
-
|
833
|
-
|
834
|
-
|
835
|
-
|
836
|
-
|
837
|
-
|
838
|
-
|
839
|
-
|
840
|
-
|
841
|
-
|
842
|
-
|
843
|
-
|
844
|
-
|
845
|
-
|
846
|
-
|
847
|
-
|
848
|
-
|
849
|
-
|
850
|
-
|
851
|
-
|
852
|
-
|
853
|
-
|
854
|
-
|
855
|
-
|
856
|
-
|
857
|
-
|
858
|
-
|
859
|
-
|
860
|
-
|
861
|
-
|
862
|
-
|
863
|
-
|
864
|
-
|
865
|
-
|
866
|
-
|
867
|
-
|
868
|
-
|
869
|
-
|
870
|
-
|
871
|
-
|
872
|
-
|
873
|
-
|
874
|
-
|
875
|
-
|
876
|
-
|
877
|
-
|
878
|
-
|
879
|
-
end
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
=begin
|
3
|
+
Copyright (C) 2011-2015 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:V
|
10
|
+
|
11
|
+
class Root < MiniTest::TestCase
|
12
|
+
def test_nothing
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class Calendar < MiniTest::TestCase
|
17
|
+
def test__each
|
18
|
+
When::TM::Clock.local_time = When.Clock("+0900")
|
19
|
+
cal = When.Resource("examples/JapanHolidays.ics")
|
20
|
+
sample = [
|
21
|
+
"2010-01-01T+09:00",
|
22
|
+
"2010-01-11T+09:00",
|
23
|
+
"2010-02-11T+09:00",
|
24
|
+
"2010-03-21T+09:00",
|
25
|
+
"2010-03-22T+09:00",
|
26
|
+
"2010-04-29T+09:00",
|
27
|
+
"2010-05-03T+09:00",
|
28
|
+
"2010-05-04T+09:00",
|
29
|
+
"2010-05-05T+09:00",
|
30
|
+
"2010-07-19T+09:00",
|
31
|
+
"2010-09-20T+09:00",
|
32
|
+
"2010-09-23T+09:00",
|
33
|
+
"2010-10-11T+09:00",
|
34
|
+
"2010-11-03T+09:00",
|
35
|
+
"2010-11-23T+09:00",
|
36
|
+
"2010-12-23T+09:00",
|
37
|
+
]
|
38
|
+
cal.each(When.when?('20100101')...When.when?('20110101')) do |date|
|
39
|
+
assert_equal(sample.shift, date.to_s)
|
40
|
+
end
|
41
|
+
assert_equal([], sample)
|
42
|
+
|
43
|
+
cal = cal.intersection({'summary'=>'成人の日'})
|
44
|
+
sample = [
|
45
|
+
"2010-01-11T+09:00",
|
46
|
+
]
|
47
|
+
cal.each(When.when?('20100101')...When.when?('20110101')) do |date|
|
48
|
+
assert_equal(sample.shift, date.to_s)
|
49
|
+
end
|
50
|
+
assert_equal([], sample)
|
51
|
+
end
|
52
|
+
|
53
|
+
def test__byweekno
|
54
|
+
sample = [
|
55
|
+
"1997-05-12",
|
56
|
+
"1998-05-11",
|
57
|
+
"1999-05-17"
|
58
|
+
]
|
59
|
+
event = When::V::Event.new({
|
60
|
+
'rrule' => 'FREQ=YEARLY;BYDAY=MO;BYWEEKNO=20',
|
61
|
+
'dtstart' => 'VALUE=DATE:19970512'
|
62
|
+
})
|
63
|
+
event.enum_for(When.when?('19970512'), :forward, 3, {'1st'=>"don't care"}).each do |date|
|
64
|
+
assert_equal(sample.shift, date.to_s)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def test__include_event
|
69
|
+
d0504 = When.when?('20100504')
|
70
|
+
d0505 = When.when?('20100505')
|
71
|
+
|
72
|
+
cal = When.Resource("examples/JapanHolidays.ics")
|
73
|
+
it = cal.enum_for(When.when?('20100501'))
|
74
|
+
date = it.next
|
75
|
+
assert_equal(["2010-05-03T+09:00", 0], [date.to_s, date.precision])
|
76
|
+
assert_equal([true,true], [d0504,d0505].map {|v| cal.include?(v)})
|
77
|
+
|
78
|
+
event = When::Parts::Resource["examples/JapanHolidays.ics::Midori_no_hi_2"] # みどりの日
|
79
|
+
it = event.enum_for(When.when?('20100501'))
|
80
|
+
date = it.next
|
81
|
+
assert_equal(["2010-05-04T+09:00", 0], [date.to_s, date.precision])
|
82
|
+
assert_equal([true,false], [d0504,d0505].map {|v| event.include?(v)})
|
83
|
+
end
|
84
|
+
|
85
|
+
def test__rfc_update
|
86
|
+
sample = ["Children's_Day_(Japan)", 'Children"s_Day_(Japan)', "Children's_Day_(Japan)"]
|
87
|
+
When::TM::Clock.local_time = When.Clock("+0900")
|
88
|
+
["JapanHolidays.ics", "JapanHolidays.ics?Escape=^'", "JapanHolidaysRFC6350.ics"].each do |ics|
|
89
|
+
cal = When.Resource('examples/' + ics)
|
90
|
+
cal = cal.intersection({'summary'=>/Children['"]s_Day_\(Japan\)/})
|
91
|
+
cal.each(When.when?('20100101')...When.when?('20110101')) do |date|
|
92
|
+
assert_equal(sample.shift, date.events[0].summary / 'en')
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
class Event < MiniTest::TestCase
|
99
|
+
def test__event
|
100
|
+
When::TM::Clock.local_time = When.Clock("+0900")
|
101
|
+
event = When::V::Event.new({
|
102
|
+
'rrule' => {'FREQ'=>'MONTHLY', 'INTERVAL'=>12, 'BYDAY'=>{''=>'2MO'}},
|
103
|
+
'dtstart' => 'VALUE=DATE:20070108'
|
104
|
+
})
|
105
|
+
sample = [
|
106
|
+
"2007-01-08",
|
107
|
+
"2008-01-14",
|
108
|
+
"2009-01-12",
|
109
|
+
"2010-01-11",
|
110
|
+
"2011-01-10",
|
111
|
+
"2012-01-09",
|
112
|
+
"2013-01-14",
|
113
|
+
"2014-01-13",
|
114
|
+
"2015-01-12",
|
115
|
+
"2016-01-11"
|
116
|
+
]
|
117
|
+
event.enum_for(When.when?('20070101'), :forward, 10).each do |date|
|
118
|
+
assert_equal(sample.shift, date.to_s)
|
119
|
+
end
|
120
|
+
assert_equal([], sample)
|
121
|
+
|
122
|
+
sample = [
|
123
|
+
"2007-01-08",
|
124
|
+
"2007-01-15",
|
125
|
+
"2007-01-22",
|
126
|
+
"2007-01-29",
|
127
|
+
"2007-02-05",
|
128
|
+
"2007-02-12",
|
129
|
+
"2007-02-19",
|
130
|
+
"2007-02-26",
|
131
|
+
"2007-03-05",
|
132
|
+
"2007-03-12"
|
133
|
+
]
|
134
|
+
event = When::V::Event.new({
|
135
|
+
'rrule' => {'FREQ'=>'P1W'},
|
136
|
+
'dtstart' => 'VALUE=DATE:20070108'
|
137
|
+
})
|
138
|
+
event.enum_for(When.when?('20070101'), :forward, 10).each do |date|
|
139
|
+
assert_equal(sample.shift, date.to_s)
|
140
|
+
end
|
141
|
+
assert_equal([], sample)
|
142
|
+
end
|
143
|
+
|
144
|
+
def test__last_work_days # See RFC 5545 [Page 43]
|
145
|
+
sample = [
|
146
|
+
"2011-01-28",
|
147
|
+
"2011-01-31",
|
148
|
+
"2011-02-25",
|
149
|
+
"2011-02-28",
|
150
|
+
"2011-03-30",
|
151
|
+
"2011-03-31",
|
152
|
+
]
|
153
|
+
event = When::V::Event.new({
|
154
|
+
'rrule' => 'FREQ=MONTHLY;BYDAY=MO,TU,WE,TH,FR;BYSETPOS=-1,-2',
|
155
|
+
'dtstart' => 'VALUE=DATE:20010101'
|
156
|
+
})
|
157
|
+
event.enum_for(When.when?('20110101'), :forward, 6).each do |date|
|
158
|
+
assert_equal(sample.shift, date.to_s)
|
159
|
+
end
|
160
|
+
assert_equal([], sample)
|
161
|
+
end
|
162
|
+
|
163
|
+
def test__ignored_invalid_date
|
164
|
+
When.Resource("examples/USA-DST.ics?C=New_York&Z=E&D=04&DZ=06&S=05&SZ=07")
|
165
|
+
assert_equal("2007-03-30T09:00:00-04:00", When.when?('TZID=America/New_York:2007-03-30T09:00:00').to_s)
|
166
|
+
sample = [
|
167
|
+
"2007-01-15T09:00:00-05:00",
|
168
|
+
"2007-01-30T09:00:00-05:00",
|
169
|
+
"2007-02-15T09:00:00-05:00",
|
170
|
+
"2007-03-15T09:00:00-04:00",
|
171
|
+
"2007-03-30T09:00:00-04:00",
|
172
|
+
]
|
173
|
+
When::V::Event.new({
|
174
|
+
'rrule' => 'FREQ=MONTHLY;BYMONTHDAY=15,30;COUNT=5',
|
175
|
+
'dtstart' => 'TZID=America/New_York:20070115T090000'
|
176
|
+
}).each do |date|
|
177
|
+
assert_equal(sample.shift, date.to_s)
|
178
|
+
break if sample == []
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
if Object.const_defined?(:TZInfo)
|
183
|
+
def test__ignored_invalid_date_chicago
|
184
|
+
assert_equal("2007-03-30T09:00:00-05:00", When.when?('TZID=America/Chicago:2007-03-30T09:00:00').to_s)
|
185
|
+
sample = [
|
186
|
+
"2007-01-15T09:00:00-06:00",
|
187
|
+
"2007-01-30T09:00:00-06:00",
|
188
|
+
"2007-02-15T09:00:00-06:00",
|
189
|
+
"2007-03-15T09:00:00-05:00",
|
190
|
+
"2007-03-30T09:00:00-05:00",
|
191
|
+
]
|
192
|
+
When::V::Event.new({
|
193
|
+
'rrule' => 'FREQ=MONTHLY;BYMONTHDAY=15,30;COUNT=5',
|
194
|
+
'dtstart' => 'TZID=America/Chicago:20070115T090000'
|
195
|
+
}).each do |date|
|
196
|
+
assert_equal(sample.shift, date.to_s)
|
197
|
+
break if sample == []
|
198
|
+
end
|
199
|
+
end
|
200
|
+
else
|
201
|
+
puts "Tests for TZInfo have been skipped at line #{__LINE__} of #{__FILE__.split(/\//)[-1]}."
|
202
|
+
end
|
203
|
+
|
204
|
+
def test__multiple_BYxxx_rule # See RFC 5545 [Page 45]
|
205
|
+
When.Resource("examples/USA-DST.ics?C=New_York&Z=E&D=04&DZ=06&S=05&SZ=07")
|
206
|
+
|
207
|
+
sample = [
|
208
|
+
"1997-04-13T01:30:00-04:00",
|
209
|
+
"1997-04-13T02:30:00-04:00",
|
210
|
+
"1997-04-13T03:30:00-04:00",
|
211
|
+
"1998-04-12T01:30:00-04:00",
|
212
|
+
]
|
213
|
+
When::V::Event.new({
|
214
|
+
'rrule' => 'FREQ=YEARLY;BYMONTH=4;BYDAY=2SU;BYHOUR=1,2,3;BYMINUTE=30',
|
215
|
+
'dtstart' => 'TZID=America/New_York:19970413T013000'
|
216
|
+
}).each do |date|
|
217
|
+
assert_equal(sample.shift, date.to_s)
|
218
|
+
break if sample == []
|
219
|
+
end
|
220
|
+
|
221
|
+
sample = [
|
222
|
+
"1997-04-06T01:30:00-05:00",
|
223
|
+
"1997-04-06T03:30:00-04:00",
|
224
|
+
"1997-04-06T04:30:00-04:00",
|
225
|
+
"1998-04-05T01:30:00-05:00",
|
226
|
+
]
|
227
|
+
When::V::Event.new({
|
228
|
+
'rrule' => 'FREQ=YEARLY;BYMONTH=4;BYDAY=1SU;BYHOUR=1,2,3,4;BYMINUTE=30',
|
229
|
+
'dtstart' => 'TZID=America/New_York:19970406T013000'
|
230
|
+
}).each do |date|
|
231
|
+
assert_equal(sample.shift, date.to_s)
|
232
|
+
break if sample == []
|
233
|
+
end
|
234
|
+
|
235
|
+
sample = [
|
236
|
+
"1997-10-26T01:30:00-04:00",
|
237
|
+
"1997-10-26T01:30:00-05:00", # * 02:30:00-04:00
|
238
|
+
"1997-10-26T02:30:00-05:00",
|
239
|
+
"1997-10-26T03:30:00-05:00",
|
240
|
+
"1998-10-25T01:30:00-04:00",
|
241
|
+
]
|
242
|
+
When::V::Event.new({
|
243
|
+
'rrule' => 'FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU;BYHOUR=1,1=,2,3;BYMINUTE=30', # *
|
244
|
+
'dtstart' => 'TZID=America/New_York:19971026T013000'
|
245
|
+
}).each do |date|
|
246
|
+
assert_equal(sample.shift, date.to_s)
|
247
|
+
break if sample == []
|
248
|
+
end
|
249
|
+
|
250
|
+
sample = [
|
251
|
+
"1997-10-19T01:30:00-04:00",
|
252
|
+
"1997-10-19T02:30:00-04:00",
|
253
|
+
"1998-10-18T01:30:00-04:00",
|
254
|
+
]
|
255
|
+
When::V::Event.new({
|
256
|
+
'rrule' => 'FREQ=YEARLY;BYMONTH=10;BYDAY=-2SU;BYHOUR=1,1=,2;BYMINUTE=30', # *
|
257
|
+
'dtstart' => 'TZID=America/New_York:19971019T013000'
|
258
|
+
}).each do |date|
|
259
|
+
assert_equal(sample.shift, date.to_s)
|
260
|
+
break if sample == []
|
261
|
+
end
|
262
|
+
end
|
263
|
+
|
264
|
+
if Object.const_defined?(:TZInfo)
|
265
|
+
def test__multiple_BYxxx_rule_chicago # See RFC 5545 [Page 45]
|
266
|
+
sample = [
|
267
|
+
"1997-04-13T01:30:00-05:00",
|
268
|
+
"1997-04-13T02:30:00-05:00",
|
269
|
+
"1997-04-13T03:30:00-05:00",
|
270
|
+
"1998-04-12T01:30:00-05:00",
|
271
|
+
]
|
272
|
+
When::V::Event.new({
|
273
|
+
'rrule' => 'FREQ=YEARLY;BYMONTH=4;BYDAY=2SU;BYHOUR=1,2,3;BYMINUTE=30',
|
274
|
+
'dtstart' => 'TZID=America/Chicago:19970413T013000'
|
275
|
+
}).each do |date|
|
276
|
+
assert_equal(sample.shift, date.to_s)
|
277
|
+
break if sample == []
|
278
|
+
end
|
279
|
+
|
280
|
+
sample = [
|
281
|
+
"1997-04-06T01:30:00-06:00",
|
282
|
+
"1997-04-06T03:30:00-05:00", # TODO !!
|
283
|
+
"1997-04-06T04:30:00-05:00",
|
284
|
+
"1998-04-05T01:30:00-06:00",
|
285
|
+
]
|
286
|
+
When::V::Event.new({
|
287
|
+
'rrule' => 'FREQ=YEARLY;BYMONTH=4;BYDAY=1SU;BYHOUR=1,2,3,4;BYMINUTE=30',
|
288
|
+
'dtstart' => 'TZID=America/Chicago:19970406T013000'
|
289
|
+
}).each do |date|
|
290
|
+
assert_equal(sample.shift, date.to_s)
|
291
|
+
break if sample == []
|
292
|
+
end
|
293
|
+
|
294
|
+
sample = [
|
295
|
+
"1997-10-26T01:30:00-05:00",
|
296
|
+
"1997-10-26T01:30:00-06:00", # * - TODO !!
|
297
|
+
"1997-10-26T02:30:00-06:00",
|
298
|
+
"1997-10-26T03:30:00-06:00",
|
299
|
+
"1998-10-25T01:30:00-05:00",
|
300
|
+
]
|
301
|
+
When::V::Event.new({
|
302
|
+
'rrule' => 'FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU;BYHOUR=1,1=,2,3;BYMINUTE=30', # *
|
303
|
+
'dtstart' => 'TZID=America/Chicago:19971026T013000'
|
304
|
+
}).each do |date|
|
305
|
+
assert_equal(sample.shift, date.to_s)
|
306
|
+
break if sample == []
|
307
|
+
end
|
308
|
+
sample = [
|
309
|
+
"1997-10-19T01:30:00-05:00",
|
310
|
+
"1997-10-19T02:30:00-05:00",
|
311
|
+
"1998-10-18T01:30:00-05:00",
|
312
|
+
]
|
313
|
+
When::V::Event.new({
|
314
|
+
'rrule' => 'FREQ=YEARLY;BYMONTH=10;BYDAY=-2SU;BYHOUR=1,1=,2;BYMINUTE=30', # *
|
315
|
+
'dtstart' => 'TZID=America/Chicago:19971019T013000'
|
316
|
+
}).each do |date|
|
317
|
+
assert_equal(sample.shift, date.to_s)
|
318
|
+
break if sample == []
|
319
|
+
end
|
320
|
+
end
|
321
|
+
else
|
322
|
+
puts "Tests for TZInfo have been skipped at line #{__LINE__} of #{__FILE__.split(/\//)[-1]}."
|
323
|
+
end
|
324
|
+
|
325
|
+
def julian_easter(yy)
|
326
|
+
a = yy % 4
|
327
|
+
b = yy % 7
|
328
|
+
c = yy % 19
|
329
|
+
d = (19 * c + 15) % 30
|
330
|
+
e = (2 * a + 4 * b - d + 34) % 7
|
331
|
+
mm = (d + e + 114) / 31
|
332
|
+
dd = ((d + e + 114) % 31) + 1
|
333
|
+
[yy, mm, dd]
|
334
|
+
end
|
335
|
+
|
336
|
+
def gregorian_easter(yy)
|
337
|
+
a = yy % 19
|
338
|
+
b = yy / 100
|
339
|
+
c = yy % 100
|
340
|
+
d = b / 4
|
341
|
+
e = b % 4
|
342
|
+
f = (b + 8) / 25
|
343
|
+
g = (b - f + 1) / 3
|
344
|
+
h = (19 * a + b - d - g + 15) % 30
|
345
|
+
i = c / 4
|
346
|
+
k = c % 4
|
347
|
+
l = (32 + 2 * e + 2 * i - h - k) % 7
|
348
|
+
m = (a + 11 * h + 22 * l) / 451
|
349
|
+
mm = (h + l - 7 * m + 114) / 31
|
350
|
+
dd = ((h + l - 7 * m + 114) % 31) + 1
|
351
|
+
[yy, mm, dd]
|
352
|
+
end
|
353
|
+
|
354
|
+
def test__easter
|
355
|
+
jc = When.Resource('_c:Julian')
|
356
|
+
other = []
|
357
|
+
myself = []
|
358
|
+
532.times do |yy|
|
359
|
+
y,m,d = julian_easter(yy+325)
|
360
|
+
other << jc._coordinates_to_number(y,m-1,d-1)
|
361
|
+
myself << jc.easter(yy+325)
|
362
|
+
end
|
363
|
+
assert_equal(other, myself)
|
364
|
+
|
365
|
+
gc = When.Resource('_c:Gregorian')
|
366
|
+
other = []
|
367
|
+
myself = []
|
368
|
+
5700.times do |yy| # Should be 5_700_000
|
369
|
+
y,m,d = gregorian_easter(yy+1582)
|
370
|
+
other << gc._coordinates_to_number(y,m-1,d-1)
|
371
|
+
myself << gc.easter(yy+1582)
|
372
|
+
end
|
373
|
+
assert_equal(other, myself)
|
374
|
+
|
375
|
+
date = When.when?('2011').easter
|
376
|
+
assert_equal("2011-04-24", date.to_s)
|
377
|
+
|
378
|
+
sample = [
|
379
|
+
"2009-04-12",
|
380
|
+
# "2010-04-02",
|
381
|
+
"2011-04-22",
|
382
|
+
]
|
383
|
+
event = When::V::Event.new({
|
384
|
+
'rrule' => 'FREQ=YEARLY;INTERVAL=2;BYDAY/Christian=easter-2',
|
385
|
+
'dtstart' => '20090412'
|
386
|
+
})
|
387
|
+
event.each do |date|
|
388
|
+
assert_equal(sample.shift, date.to_s)
|
389
|
+
break if sample == []
|
390
|
+
end
|
391
|
+
|
392
|
+
sample = [
|
393
|
+
"2011-04-22",
|
394
|
+
]
|
395
|
+
event.enum_for(When.when?('20100101')).each do |date|
|
396
|
+
assert_equal(sample.shift, date.to_s)
|
397
|
+
break if sample == []
|
398
|
+
end
|
399
|
+
|
400
|
+
sample = [
|
401
|
+
"2009-04-12",
|
402
|
+
"2010-03-30",
|
403
|
+
"2011-04-17",
|
404
|
+
"2012-04-07"
|
405
|
+
]
|
406
|
+
event = When::V::Event.new({
|
407
|
+
'rrule' => 'FREQ=YEARLY;BYDAY/Christian?w=7=easter',
|
408
|
+
'dtstart' => '20090412'
|
409
|
+
})
|
410
|
+
event.each do |date|
|
411
|
+
assert_equal(sample.shift, date.to_s)
|
412
|
+
break if sample == []
|
413
|
+
end
|
414
|
+
|
415
|
+
sample = [
|
416
|
+
"2009-12-25",
|
417
|
+
"2010-12-25",
|
418
|
+
"2011-12-25",
|
419
|
+
]
|
420
|
+
When::V::Event.new({
|
421
|
+
'rrule' => 'FREQ=YEARLY;BYDAY/Christian=christmas',
|
422
|
+
'dtstart' => '20091225'
|
423
|
+
}).each do |date|
|
424
|
+
assert_equal(sample.shift, date.to_s)
|
425
|
+
break if sample == []
|
426
|
+
end
|
427
|
+
end
|
428
|
+
|
429
|
+
def test__terms
|
430
|
+
|
431
|
+
event = When::V::Event.new({
|
432
|
+
'rrule' => 'FREQ=YEARLY;INTERVAL=2;BYDAY/SolarTerms=term180',
|
433
|
+
'dtstart' => '20090922'
|
434
|
+
})
|
435
|
+
sample = [
|
436
|
+
"2011-09-23",
|
437
|
+
]
|
438
|
+
event.enum_for(When.when?('20100101')).each do |date|
|
439
|
+
assert_equal(sample.shift, date.to_s)
|
440
|
+
break if sample == []
|
441
|
+
end
|
442
|
+
|
443
|
+
sample = [
|
444
|
+
"2009-09-22",
|
445
|
+
# "2010-09-22",
|
446
|
+
"2011-09-23",
|
447
|
+
]
|
448
|
+
event.each do |date|
|
449
|
+
assert_equal(sample.shift, date.to_s)
|
450
|
+
break if sample == []
|
451
|
+
end
|
452
|
+
end
|
453
|
+
end
|
454
|
+
|
455
|
+
class Alarm < MiniTest::TestCase
|
456
|
+
def test_nothing
|
457
|
+
end
|
458
|
+
end
|
459
|
+
|
460
|
+
class Todo < MiniTest::TestCase
|
461
|
+
def test__todo
|
462
|
+
When::TM::Clock.local_time = When.Clock("+0900")
|
463
|
+
event = When::V::Todo.new({
|
464
|
+
'rrule' => {'FREQ'=>'YEARLY', 'BYMONTH'=>1, 'BYDAY'=>{''=>'2MO'}},
|
465
|
+
'due' => 'VALUE=DATE:20200113'
|
466
|
+
})
|
467
|
+
sample = [
|
468
|
+
"2011-01-10",
|
469
|
+
"2012-01-09",
|
470
|
+
"2013-01-14",
|
471
|
+
"2014-01-13",
|
472
|
+
"2015-01-12",
|
473
|
+
"2016-01-11",
|
474
|
+
"2017-01-09",
|
475
|
+
"2018-01-08",
|
476
|
+
"2019-01-14",
|
477
|
+
"2020-01-13"
|
478
|
+
]
|
479
|
+
this_time = When.now.to_s
|
480
|
+
sample.shift while (sample[0] && sample[0] <= this_time)
|
481
|
+
event.enum_for(When.when?('20070101'), :forward, 9).each do |date|
|
482
|
+
assert_equal(sample.shift, date.to_s)
|
483
|
+
end
|
484
|
+
assert_equal([], sample)
|
485
|
+
end
|
486
|
+
end
|
487
|
+
|
488
|
+
class Journal < MiniTest::TestCase
|
489
|
+
def test_nothing
|
490
|
+
end
|
491
|
+
end
|
492
|
+
|
493
|
+
class Freebusy < MiniTest::TestCase
|
494
|
+
def test__freebusy # RFC 5545 [Page 101]
|
495
|
+
sample = [
|
496
|
+
"1997-03-08T16:00:00Z...1997-03-08T19:00:00Z",
|
497
|
+
"1997-03-08T20:00:00Z...1997-03-08T21:00:00Z"
|
498
|
+
]
|
499
|
+
When::V::Freebusy.new({'freebusy'=>'FBTYPE=FREE:19970308T160000Z/PT3H,19970308T200000Z/PT1H'}).each do |period|
|
500
|
+
assert_equal([sample.shift, 'FREE'], [period.to_s, period.query['FBTYPE']])
|
501
|
+
end
|
502
|
+
assert_equal([], sample)
|
503
|
+
end
|
504
|
+
end
|
505
|
+
|
506
|
+
class TimezoneProperty < MiniTest::TestCase
|
507
|
+
def test__tz_change
|
508
|
+
ic = When.Resource("examples/USA-DST.ics?C=New_York&Z=E&D=04&DZ=06&S=05&SZ=07")
|
509
|
+
tz = When::V::Timezone["America/New_York"]
|
510
|
+
gc = When.Resource('_c:Gregorian')
|
511
|
+
[
|
512
|
+
["1997-04-06T01:59:59", "1997-04-06T01:59:59-05:00"],
|
513
|
+
["1997-04-06T02:00:00", "1997-04-06T02:00:00-04:00"],
|
514
|
+
["1997-04-06T03:00:00", "1997-04-06T03:00:00-04:00"],
|
515
|
+
["1997-10-26T00:59:00", "1997-10-26T00:59:00-04:00"], # *
|
516
|
+
["1997-10-26T01:00:00", "1997-10-26T01:00:00-04:00"], # *
|
517
|
+
["1997-10-26T01:59:59", "1997-10-26T01:59:59-04:00"], # *
|
518
|
+
["1997-10-26T01=00:00", "1997-10-26T01:00:00-05:00"], # *
|
519
|
+
["1997-10-26T01=59:59", "1997-10-26T01:59:59-05:00"], # *
|
520
|
+
["1997-10-26T02:00:00", "1997-10-26T02:00:00-05:00"] # *
|
521
|
+
].each do |sample|
|
522
|
+
assert_equal(sample[1], When.when?(sample[0], {:clock=>tz}).to_s)
|
523
|
+
end
|
524
|
+
|
525
|
+
[
|
526
|
+
["19970406T010000-0500", "1997-04-06T01:00:00-05:00"],
|
527
|
+
["19970406T015959-0500", "1997-04-06T01:59:59-05:00"],
|
528
|
+
["19970406T020000-0500", "1997-04-06T03:00:00-04:00"],
|
529
|
+
["19970406T030000-0500", "1997-04-06T04:00:00-04:00"],
|
530
|
+
["19971026T005959-0400", "1997-10-26T00:59:59-04:00"], # *
|
531
|
+
["19971026T010000-0400", "1997-10-26T01:00:00-04:00"], # *
|
532
|
+
["19971026T015959-0400", "1997-10-26T01:59:59-04:00"], # *
|
533
|
+
["19971026T020000-0400", "1997-10-26T01:00:00-05:00"], # *
|
534
|
+
["19971026T030000-0400", "1997-10-26T02:00:00-05:00"] # *
|
535
|
+
].each do |sample|
|
536
|
+
sdate = When.when?(sample[0])
|
537
|
+
ddate = gc.jul_trans(sdate, {:clock=>tz})
|
538
|
+
assert_equal(sample[1], ddate.to_s)
|
539
|
+
end
|
540
|
+
end
|
541
|
+
|
542
|
+
if Object.const_defined?(:TZInfo)
|
543
|
+
def test__tz_change_chicago
|
544
|
+
tz = When::Parts::Timezone["America/Chicago"]
|
545
|
+
gc = When.Resource('_c:Gregorian')
|
546
|
+
[
|
547
|
+
["19970406T010000-0600", "1997-04-06T01:00:00-06:00"],
|
548
|
+
["19970406T015959-0600", "1997-04-06T01:59:59-06:00"],
|
549
|
+
["19970406T020000-0600", "1997-04-06T03:00:00-05:00"],
|
550
|
+
["19970406T030000-0600", "1997-04-06T04:00:00-05:00"],
|
551
|
+
["19971026T005959-0500", "1997-10-26T00:59:59-05:00"], # *
|
552
|
+
["19971026T010000-0500", "1997-10-26T01:00:00-05:00"], # *
|
553
|
+
["19971026T015959-0500", "1997-10-26T01:59:59-05:00"], # *
|
554
|
+
["19971026T020000-0500", "1997-10-26T01:00:00-06:00"], # *
|
555
|
+
["19971026T030000-0500", "1997-10-26T02:00:00-06:00"], # *
|
556
|
+
].each do |sample|
|
557
|
+
sdate = When.when?(sample[0])
|
558
|
+
ddate = gc.jul_trans(sdate, {:clock=>tz})
|
559
|
+
assert_equal(sample[1], ddate.to_s)
|
560
|
+
end
|
561
|
+
|
562
|
+
[
|
563
|
+
["1997-04-06T01:59:59", "1997-04-06T01:59:59-06:00"],
|
564
|
+
["1997-04-06T02:00:00", "1997-04-06T02:00:00-05:00"],
|
565
|
+
["1997-04-06T03:00:00", "1997-04-06T03:00:00-05:00"],
|
566
|
+
["1997-10-26T00:59:00", "1997-10-26T00:59:00-05:00"], # *
|
567
|
+
["1997-10-26T01:00:00", "1997-10-26T01:00:00-05:00"], # * # "1997-10-26T02:00:00-05:00" - TODO !!
|
568
|
+
["1997-10-26T01:59:59", "1997-10-26T01:59:59-05:00"], # * # "1997-10-26T02:59:59-05:00" - TODO !!
|
569
|
+
["1997-10-26T01=00:00", "1997-10-26T01:00:00-06:00"], # *
|
570
|
+
["1997-10-26T01=59:59", "1997-10-26T01:59:59-06:00"], # *
|
571
|
+
["1997-10-26T02:00:00", "1997-10-26T02:00:00-06:00"] # *
|
572
|
+
].each do |sample|
|
573
|
+
assert_equal(sample[1], When.when?(sample[0], {:clock=>tz}).to_s)
|
574
|
+
end
|
575
|
+
end
|
576
|
+
else
|
577
|
+
puts "Tests for TZInfo have been skipped at line #{__LINE__} of #{__FILE__.split(/\//)[-1]}."
|
578
|
+
end
|
579
|
+
|
580
|
+
def test__date_change
|
581
|
+
ic = When.Resource("examples/Millennium.ics")
|
582
|
+
tz = When::V::Timezone["Oceania/Millennium_Island"]
|
583
|
+
gc = When.Resource('_c:Gregorian')
|
584
|
+
[
|
585
|
+
["1994-12-30T23:59:59", "1994-12-30T23:59:59-10:00"],
|
586
|
+
["1995-01-01T00:00:00", "1995-01-01T00:00:00+14:00"]
|
587
|
+
].each do |sample|
|
588
|
+
assert_equal(sample[1], When.when?(sample[0], {:clock=>tz}).to_s)
|
589
|
+
end
|
590
|
+
[
|
591
|
+
["19941230T235959-1000", "1994-12-30T23:59:59-10:00"],
|
592
|
+
["19941231T000000-1000", "1995-01-01T00:00:00+14:00"],
|
593
|
+
].each do |sample|
|
594
|
+
sdate = When.when?(sample[0])
|
595
|
+
ddate = gc.jul_trans(sdate, {:clock=>tz})
|
596
|
+
assert_equal(sample[1], ddate.to_s)
|
597
|
+
end
|
598
|
+
end
|
599
|
+
|
600
|
+
def test__tzname
|
601
|
+
ic = When.Resource("examples/USA-DST.ics?C=New_York&Z=E&D=04&DZ=06&S=05&SZ=07")
|
602
|
+
date = When.when?('20110126T250000EST')
|
603
|
+
assert_equal(["2011-01-27T01:00:00-05:00", "Thu Jan 27 01:00:00 -0500 2011", "EST"],
|
604
|
+
[date.to_s, date.strftime('%+'), date.clk_time.frame.tzname[0]])
|
605
|
+
|
606
|
+
When::TM::Clock.local_time = When::V::Timezone["America/New_York"]
|
607
|
+
|
608
|
+
date = When.when?('20110526T250000')
|
609
|
+
assert_equal(["2011-05-27T01:00:00-04:00", "Fri May 27 01:00:00 -0400 2011", "EDT"],
|
610
|
+
[date.to_s, date.strftime('%+'), date.clk_time.frame.tzname[0]])
|
611
|
+
end
|
612
|
+
end
|
613
|
+
|
614
|
+
class Standard < MiniTest::TestCase
|
615
|
+
def test_nothing
|
616
|
+
end
|
617
|
+
end
|
618
|
+
|
619
|
+
class Daylight < MiniTest::TestCase
|
620
|
+
def test_nothing
|
621
|
+
end
|
622
|
+
end
|
623
|
+
|
624
|
+
class Timezone < MiniTest::TestCase
|
625
|
+
def test__neighbor_event_date
|
626
|
+
When.Resource("examples/USA-DST.ics?C=New_York&Z=E&D=04&DZ=06&S=05&SZ=07")
|
627
|
+
tz = When::V::Timezone["America/New_York"]
|
628
|
+
assert_equal("1997-04-06T02:00:00-05:00", tz.send(:_neighbor_event_date, When.when?("19970510").universal_time).to_s)
|
629
|
+
assert_equal("1997-10-26T02:00:00-04:00", tz.send(:_neighbor_event_date, When.when?("19971010").universal_time).to_s)
|
630
|
+
end
|
631
|
+
|
632
|
+
def test__current_period
|
633
|
+
When.Resource("examples/USA-DST.ics?C=New_York&Z=E&D=04&DZ=06&S=05&SZ=07")
|
634
|
+
tz = When::V::Timezone["America/New_York"]
|
635
|
+
assert_equal("1997-04-06T02:00:00-05:00...1997-10-26T02:00:00-04:00", tz.current_period(When.when?("19970510")).to_s)
|
636
|
+
assert_equal("1997-04-06T02:00:00-05:00...1997-10-26T02:00:00-04:00", tz.current_period(When.when?("19971010")).to_s)
|
637
|
+
end
|
638
|
+
|
639
|
+
if Object.const_defined?(:TZInfo)
|
640
|
+
def test__tz_info
|
641
|
+
assert_equal("1997-05-10T06:00-05:00", When.when?("TZID=America/Chicago:19970510T0600").to_s)
|
642
|
+
assert_equal("1582-10-07T11:00+09:18:59", When.when?("TZID=Asia/Tokyo:1582-10-07T11:00").to_s)
|
643
|
+
assert_equal("H24(2012).06.06T11:00+09:00", When.when?("TZID=Asia/Tokyo:H24-6-6T11:00").to_s)
|
644
|
+
assert_equal("1997-10-26T01:30:00-04:00", When.when?("TZID=America/New_York:1997-10-26T01:30:00").to_s)
|
645
|
+
assert_equal("1997-10-26T01:30:00-05:00", When.when?("TZID=America/New_York:1997-10-26T01=30:00").to_s)
|
646
|
+
assert_equal("1997-10-26T02:30:00-05:00", When.when?("TZID=America/New_York:1997-10-26T02:30:00").to_s)
|
647
|
+
assert_equal("1997-10-26T03:30:00-05:00", When.when?("TZID=America/New_York:1997-10-26T03:30:00").to_s)
|
648
|
+
|
649
|
+
location = When.Resource('_co:Spatial?tz=Asia/Tokyo')
|
650
|
+
assert_equal(['Asia/Tokyo', When::BasicTypes::M17n], [location.label.to_s, location.label.class])
|
651
|
+
end
|
652
|
+
else
|
653
|
+
puts "Tests for TZInfo have been skipped at line #{__LINE__} of #{__FILE__.split(/\//)[-1]}."
|
654
|
+
end
|
655
|
+
end
|
656
|
+
|
657
|
+
class Event
|
658
|
+
|
659
|
+
def test__each_1
|
660
|
+
When.Resource("examples/USA-DST.ics?C=New_York&Z=E&D=04&DZ=06&S=05&SZ=07")
|
661
|
+
cal = When.Resource("examples/Test.ics")
|
662
|
+
|
663
|
+
event1 = When.Resource("examples/Test.ics::event1-ID")
|
664
|
+
sample = [
|
665
|
+
"2008-09-15T+09:00",
|
666
|
+
"2009-09-21T+09:00",
|
667
|
+
"2010-09-20T+09:00",
|
668
|
+
"2011-09-19T+09:00",
|
669
|
+
"2012-09-17T+09:00",
|
670
|
+
"2013-09-16T+09:00",
|
671
|
+
"2014-09-15T+09:00",
|
672
|
+
"2015-09-21T+09:00",
|
673
|
+
"2016-09-19T+09:00",
|
674
|
+
]
|
675
|
+
event1.enum_for(When.when?('20080101'), :forward, 9).each do |date|
|
676
|
+
assert_equal(sample.shift, date.to_s)
|
677
|
+
end
|
678
|
+
assert_equal([], sample)
|
679
|
+
|
680
|
+
sample = [
|
681
|
+
"2010-09-20T+09:00",
|
682
|
+
"2011-09-19T+09:00",
|
683
|
+
"2012-09-17T+09:00",
|
684
|
+
"2013-09-16T+09:00",
|
685
|
+
]
|
686
|
+
event1.enum_for(When.when?('20100101'), :forward, 4).each do |date|
|
687
|
+
assert_equal(sample.shift, date.to_s)
|
688
|
+
end
|
689
|
+
assert_equal([], sample)
|
690
|
+
end
|
691
|
+
|
692
|
+
def test__each_2
|
693
|
+
When.Resource("examples/USA-DST.ics?C=New_York&Z=E&D=04&DZ=06&S=05&SZ=07")
|
694
|
+
cal = When.Resource("examples/Test.ics")
|
695
|
+
|
696
|
+
event2 = cal["event2-ID"]
|
697
|
+
sample = [
|
698
|
+
"2010-09-20T+09:00",
|
699
|
+
"2011-05-13T+09:00",
|
700
|
+
"2011-09-19T+09:00",
|
701
|
+
"2012-01-13T+09:00",
|
702
|
+
"2012-04-13T+09:00",
|
703
|
+
"2012-07-13T+09:00",
|
704
|
+
"2012-09-17T+09:00",
|
705
|
+
"2013-09-13T+09:00",
|
706
|
+
"2013-09-16T+09:00",
|
707
|
+
"2013-12-13T+09:00",
|
708
|
+
]
|
709
|
+
event2.enum_for(When.when?('20100101'), :forward, 10, {'1st'=>'DontCare'}).each do |date|
|
710
|
+
assert_equal(sample.shift, date.to_s)
|
711
|
+
end
|
712
|
+
assert_equal([], sample)
|
713
|
+
end
|
714
|
+
|
715
|
+
def test__each_3
|
716
|
+
When.Resource("examples/USA-DST.ics?C=New_York&Z=E&D=04&DZ=06&S=05&SZ=07")
|
717
|
+
cal = When.Resource("examples/Test.ics")
|
718
|
+
|
719
|
+
event3 = cal["event3-ID"]
|
720
|
+
sample = [
|
721
|
+
"1997-09-02T09:00:00-04:00",
|
722
|
+
"1997-09-02T09:20:00-04:00",
|
723
|
+
"1997-09-02T09:40:00-04:00",
|
724
|
+
"1997-09-02T10:00:00-04:00",
|
725
|
+
"1997-09-02T10:20:00-04:00",
|
726
|
+
"1997-09-02T10:40:00-04:00",
|
727
|
+
"1997-09-02T11:00:00-04:00",
|
728
|
+
"1997-09-02T11:20:00-04:00",
|
729
|
+
"1997-09-02T11:40:00-04:00",
|
730
|
+
"1997-09-02T12:00:00-04:00",
|
731
|
+
"1997-09-02T12:20:00-04:00",
|
732
|
+
"1997-09-02T12:40:00-04:00",
|
733
|
+
"1997-09-02T13:00:00-04:00",
|
734
|
+
"1997-09-02T13:20:00-04:00",
|
735
|
+
"1997-09-02T13:40:00-04:00",
|
736
|
+
"1997-09-02T14:00:00-04:00",
|
737
|
+
"1997-09-02T14:20:00-04:00",
|
738
|
+
"1997-09-02T14:40:00-04:00",
|
739
|
+
"1997-09-02T15:00:00-04:00",
|
740
|
+
"1997-09-02T15:20:00-04:00",
|
741
|
+
"1997-09-02T15:40:00-04:00",
|
742
|
+
"1997-09-02T16:00:00-04:00",
|
743
|
+
"1997-09-02T16:20:00-04:00",
|
744
|
+
"1997-09-02T16:40:00-04:00",
|
745
|
+
"1997-09-03T09:00:00-04:00",
|
746
|
+
"1997-09-03T09:20:00-04:00",
|
747
|
+
"1997-09-03T09:40:00-04:00",
|
748
|
+
"1997-09-03T10:00:00-04:00",
|
749
|
+
"1997-09-03T10:20:00-04:00",
|
750
|
+
"1997-09-03T10:40:00-04:00",
|
751
|
+
]
|
752
|
+
event3.enum_for(When.when?('19970902T090000'), :forward, {:count_limit=>30}).each do |date|
|
753
|
+
assert_equal(sample.shift, date.to_s)
|
754
|
+
end
|
755
|
+
assert_equal([], sample)
|
756
|
+
|
757
|
+
sample = [
|
758
|
+
"1997-09-04T13:00:00-04:00",
|
759
|
+
"1997-09-04T12:40:00-04:00",
|
760
|
+
"1997-09-04T12:20:00-04:00",
|
761
|
+
"1997-09-04T12:00:00-04:00",
|
762
|
+
"1997-09-04T11:40:00-04:00",
|
763
|
+
"1997-09-04T11:20:00-04:00",
|
764
|
+
"1997-09-04T11:00:00-04:00",
|
765
|
+
"1997-09-04T10:40:00-04:00",
|
766
|
+
"1997-09-04T10:20:00-04:00",
|
767
|
+
"1997-09-04T10:00:00-04:00",
|
768
|
+
]
|
769
|
+
event3.enum_for(When.when?('19970904T170000'), {:direction=>:reverse, :count_limit=>10, '1st'=>'DontCare'}).each do |date|
|
770
|
+
assert_equal(sample.shift, date.to_s)
|
771
|
+
end
|
772
|
+
assert_equal([], sample)
|
773
|
+
|
774
|
+
sample = [
|
775
|
+
"1997-09-04T16:40:00-04:00",
|
776
|
+
"1997-09-04T16:20:00-04:00",
|
777
|
+
"1997-09-04T16:00:00-04:00",
|
778
|
+
]
|
779
|
+
event3.enum_for(When.when?('TZID=America/New_York:19970904T170000'), :reverse, 3, {'1st'=>'Exclude'}).each do |date|
|
780
|
+
assert_equal(sample.shift, date.to_s)
|
781
|
+
end
|
782
|
+
assert_equal([], sample)
|
783
|
+
end
|
784
|
+
|
785
|
+
def test__each_4
|
786
|
+
When.Resource("examples/USA-DST.ics?C=New_York&Z=E&D=04&DZ=06&S=05&SZ=07")
|
787
|
+
cal = When.Resource("examples/Test.ics")
|
788
|
+
|
789
|
+
event4 = cal["event4-ID"]
|
790
|
+
sample = [
|
791
|
+
"1997-09-02T09:00:00-04:00",
|
792
|
+
"1997-09-02T09:00:10-04:00",
|
793
|
+
"1997-09-02T09:20:00-04:00",
|
794
|
+
"1997-09-02T09:40:00-04:00",
|
795
|
+
"1997-09-02T10:00:00-04:00",
|
796
|
+
"1997-09-02T10:20:00-04:00",
|
797
|
+
"1997-09-02T10:40:00-04:00",
|
798
|
+
"1997-09-02T11:00:00-04:00",
|
799
|
+
"1997-09-02T11:20:00-04:00",
|
800
|
+
"1997-09-02T11:40:00-04:00",
|
801
|
+
"1997-09-02T12:20:00-04:00",
|
802
|
+
]
|
803
|
+
event4.enum_for(When.when?('19970902T090000'), :forward, 11).each do |date|
|
804
|
+
assert_equal(sample.shift, date.to_s)
|
805
|
+
end
|
806
|
+
assert_equal([], sample)
|
807
|
+
end
|
808
|
+
|
809
|
+
def test__each_5
|
810
|
+
event5 = When::V::Event.new({
|
811
|
+
'rrule' => 'FREQ=MONTHLY;BYMONTHDAY=31',
|
812
|
+
'dtstart' => 'VALUE=DATE:20070131'
|
813
|
+
})
|
814
|
+
sample =%w(2007-01-31 2007-03-31 2007-05-31 2007-07-31 2007-08-31
|
815
|
+
2007-10-31 2007-12-31 2008-01-31 2008-03-31 2008-05-31)
|
816
|
+
event5.enum_for(When.when?('20070101'), :forward, 10).each do |date|
|
817
|
+
assert_equal(sample.shift, date.to_s)
|
818
|
+
end
|
819
|
+
end
|
820
|
+
|
821
|
+
class Enumerator < MiniTest::TestCase
|
822
|
+
|
823
|
+
def test_nothing
|
824
|
+
end
|
825
|
+
|
826
|
+
class Step < MiniTest::TestCase
|
827
|
+
def test_nothing
|
828
|
+
end
|
829
|
+
end
|
830
|
+
|
831
|
+
class Logic < MiniTest::TestCase
|
832
|
+
|
833
|
+
def test_nothing
|
834
|
+
end
|
835
|
+
|
836
|
+
class Enumerator < MiniTest::TestCase
|
837
|
+
def test_nothing
|
838
|
+
end
|
839
|
+
end
|
840
|
+
|
841
|
+
class Month < MiniTest::TestCase
|
842
|
+
def test_nothing
|
843
|
+
end
|
844
|
+
end
|
845
|
+
|
846
|
+
class Weekno < MiniTest::TestCase
|
847
|
+
def test_nothing
|
848
|
+
end
|
849
|
+
end
|
850
|
+
|
851
|
+
class Yearday < MiniTest::TestCase
|
852
|
+
def test_nothing
|
853
|
+
end
|
854
|
+
end
|
855
|
+
|
856
|
+
class Monthday < MiniTest::TestCase
|
857
|
+
def test_nothing
|
858
|
+
end
|
859
|
+
end
|
860
|
+
|
861
|
+
class Weekday < MiniTest::TestCase
|
862
|
+
def test_nothing
|
863
|
+
end
|
864
|
+
end
|
865
|
+
|
866
|
+
class Hour < MiniTest::TestCase
|
867
|
+
def test_nothing
|
868
|
+
end
|
869
|
+
end
|
870
|
+
|
871
|
+
class Minute < MiniTest::TestCase
|
872
|
+
def test_nothing
|
873
|
+
end
|
874
|
+
end
|
875
|
+
|
876
|
+
class Second < MiniTest::TestCase
|
877
|
+
def test_nothing
|
878
|
+
end
|
879
|
+
end
|
880
|
+
end
|
881
|
+
end
|
882
|
+
end
|
883
|
+
end
|