when_exe 0.3.6 → 0.3.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (117) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +171 -0
  3. data/lib/when_exe.rb +78 -47
  4. data/lib/when_exe/basictypes.rb +752 -747
  5. data/lib/when_exe/calendarnote.rb +805 -801
  6. data/lib/when_exe/calendartypes.rb +1583 -1531
  7. data/lib/when_exe/coordinates.rb +16 -15
  8. data/lib/when_exe/core/duration.rb +114 -110
  9. data/lib/when_exe/core/extension.rb +504 -504
  10. data/lib/when_exe/ephemeris.rb +1917 -1913
  11. data/lib/when_exe/ephemeris/moon.rb +333 -333
  12. data/lib/when_exe/ephemeris/notes.rb +389 -387
  13. data/lib/when_exe/ephemeris/planets.rb +585 -585
  14. data/lib/when_exe/ephemeris/sun.rb +214 -214
  15. data/lib/when_exe/googlecalendar.rb +144 -140
  16. data/lib/when_exe/icalendar.rb +1636 -1636
  17. data/lib/when_exe/inspect.rb +46 -22
  18. data/lib/when_exe/locales/akt.rb +176 -176
  19. data/lib/when_exe/locales/encoding_conversion.rb +134 -126
  20. data/lib/when_exe/locales/iast.rb +90 -90
  21. data/lib/when_exe/locales/locale.rb +750 -746
  22. data/lib/when_exe/locales/transliteration_table.rb +62 -62
  23. data/lib/when_exe/mini_application.rb +307 -305
  24. data/lib/when_exe/parts/enumerator.rb +2 -2
  25. data/lib/when_exe/parts/geometric_complex.rb +397 -397
  26. data/lib/when_exe/parts/method_cash.rb +224 -224
  27. data/lib/when_exe/parts/resource.rb +1069 -1071
  28. data/lib/when_exe/parts/timezone.rb +240 -230
  29. data/lib/when_exe/region/armenian.rb +56 -56
  30. data/lib/when_exe/region/babylonian.rb +405 -0
  31. data/lib/when_exe/region/bahai.rb +146 -146
  32. data/lib/when_exe/region/balinese.rb +622 -622
  33. data/lib/when_exe/region/chinese.rb +95 -25
  34. data/lib/when_exe/region/chinese/calendars.rb +1016 -1016
  35. data/lib/when_exe/region/chinese/epochs.rb +1 -1
  36. data/lib/when_exe/region/chinese/twins.rb +803 -795
  37. data/lib/when_exe/region/christian.rb +824 -824
  38. data/lib/when_exe/region/coptic.rb +106 -87
  39. data/lib/when_exe/region/discordian.rb +225 -225
  40. data/lib/when_exe/region/far_east.rb +188 -188
  41. data/lib/when_exe/region/french.rb +56 -56
  42. data/lib/when_exe/region/geologicalage.rb +639 -639
  43. data/lib/when_exe/region/goddess.rb +58 -58
  44. data/lib/when_exe/region/indian.rb +1254 -1251
  45. data/lib/when_exe/region/iranian.rb +8 -8
  46. data/lib/when_exe/region/islamic.rb +3 -3
  47. data/lib/when_exe/region/japanese.rb +93 -99
  48. data/lib/when_exe/region/japanese/calendars.rb +396 -397
  49. data/lib/when_exe/region/japanese/epochs.rb +26 -26
  50. data/lib/when_exe/region/japanese/nihon_shoki.rb +71 -71
  51. data/lib/when_exe/region/japanese/notes.rb +1383 -1386
  52. data/lib/when_exe/region/japanese/residues.rb +1306 -1306
  53. data/lib/when_exe/region/japanese/twins.rb +225 -225
  54. data/lib/when_exe/region/japanese/weeks.rb +112 -0
  55. data/lib/when_exe/region/javanese.rb +230 -230
  56. data/lib/when_exe/region/jewish.rb +126 -126
  57. data/lib/when_exe/region/korean.rb +378 -378
  58. data/lib/when_exe/region/m17n.rb +114 -113
  59. data/lib/when_exe/region/martian.rb +258 -255
  60. data/lib/when_exe/region/mayan.rb +32 -32
  61. data/lib/when_exe/region/residue.rb +89 -89
  62. data/lib/when_exe/region/roman.rb +36 -24
  63. data/lib/when_exe/region/ryukyu.rb +97 -97
  64. data/lib/when_exe/region/shire.rb +240 -240
  65. data/lib/when_exe/region/soviet.rb +209 -0
  66. data/lib/when_exe/region/symmetry.rb +50 -50
  67. data/lib/when_exe/region/thai.rb +336 -335
  68. data/lib/when_exe/region/tibetan.rb +316 -315
  69. data/lib/when_exe/region/vietnamese.rb +440 -439
  70. data/lib/when_exe/region/weekdate.rb +80 -80
  71. data/lib/when_exe/region/world.rb +175 -175
  72. data/lib/when_exe/region/yerm.rb +14 -14
  73. data/lib/when_exe/region/zoroastrian.rb +203 -203
  74. data/lib/when_exe/timestandard.rb +707 -681
  75. data/lib/when_exe/tmduration.rb +338 -330
  76. data/lib/when_exe/tmobjects.rb +1346 -1325
  77. data/lib/when_exe/tmposition.rb +2115 -2072
  78. data/lib/when_exe/tmreference.rb +1693 -1669
  79. data/lib/when_exe/version.rb +1 -1
  80. data/link_to_online_documents +1 -1
  81. data/test/examples/JapanHolidaysRFC6350.ics +1 -1
  82. data/test/test.rb +67 -61
  83. data/test/test/basictypes.rb +409 -409
  84. data/test/test/calendarnote.rb +86 -69
  85. data/test/test/calendartypes.rb +97 -97
  86. data/test/test/coordinates.rb +396 -396
  87. data/test/test/ephemeris.rb +83 -74
  88. data/test/test/ephemeris/moon.rb +14 -14
  89. data/test/test/ephemeris/planets.rb +14 -14
  90. data/test/test/ephemeris/sun.rb +14 -14
  91. data/test/test/googlecalendar.rb +194 -176
  92. data/test/test/icalendar.rb +867 -858
  93. data/test/test/inspect.rb +117 -117
  94. data/test/test/parts.rb +487 -487
  95. data/test/test/region/balinese.rb +34 -0
  96. data/test/test/region/chinese.rb +218 -206
  97. data/test/test/region/christian.rb +245 -245
  98. data/test/test/region/coptic.rb +27 -27
  99. data/test/test/region/french.rb +33 -33
  100. data/test/test/region/geologicalage.rb +17 -17
  101. data/test/test/region/indian.rb +57 -57
  102. data/test/test/region/iran.rb +54 -54
  103. data/test/test/region/islamic.rb +18 -18
  104. data/test/test/region/japanese.rb +237 -219
  105. data/test/test/region/jewish.rb +61 -61
  106. data/test/test/region/m17n.rb +184 -184
  107. data/test/test/region/mayan.rb +195 -195
  108. data/test/test/region/residue.rb +147 -139
  109. data/test/test/region/thai.rb +116 -116
  110. data/test/test/region/tibetan.rb +30 -30
  111. data/test/test/region/vietnamese.rb +102 -102
  112. data/test/test/region/yerm.rb +146 -146
  113. data/test/test/timestandard.rb +81 -81
  114. data/test/test/tmobjects.rb +328 -328
  115. data/test/test/tmposition.rb +397 -284
  116. data/test/test/tmreference.rb +157 -157
  117. metadata +13 -10
@@ -1,74 +1,83 @@
1
- # -*- coding: utf-8 -*-
2
- =begin
3
- Copyright (C) 2011-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 Test::Ephemeris
10
-
11
- class Ephemeris < Test::Unit::TestCase
12
- def test_nothing
13
- end
14
- end
15
-
16
- class CelestialObject < Test::Unit::TestCase
17
- def test_nothing
18
- end
19
- end
20
-
21
- class Star < Test::Unit::TestCase
22
-
23
- def test_nothing
24
- end
25
-
26
- # 恒星
27
- class Fixed < Test::Unit::TestCase
28
- def test__access_hr
29
- polaris = When::Resource('_sc:HR0424')
30
- assert_equal("Alp UMi", polaris.bayer_name)
31
- end
32
- end
33
-
34
- # 春分点
35
- class Vernal < Test::Unit::TestCase
36
- def test_nothing
37
- end
38
- end
39
-
40
- # 北極
41
- class Pole < Test::Unit::TestCase
42
- def test_nothing
43
- end
44
- end
45
- end
46
-
47
- class Planet < Test::Unit::TestCase
48
- def test_nothing
49
- end
50
- end
51
-
52
- class Coords < Test::Unit::TestCase
53
- def test_nothing
54
- end
55
- end
56
-
57
- class Formula < Test::Unit::TestCase
58
- def test__sunrise
59
-
60
- today = '2014-3-4'
61
-
62
- assert_raises(NoMethodError) { When.when?(today).sunrise }
63
-
64
- location = When.Location('long=139.413012E&lat=35.412222N')
65
- assert_equal(0, /2014-03-03T21:07/ =~ When.when?(today, {:location=>location}).sunrise.to_s)
66
-
67
- When::Coordinates::Spatial.default_location = location
68
- assert_equal(0, /2014-03-03T21:07/ =~ When.when?(today).sunrise.to_s)
69
-
70
- When::TM::Clock.local_time = '+09:00'
71
- assert_equal(0, /2014-03-04T06:07/ =~ When.when?(today).sunrise.to_s)
72
- end
73
- end
74
- end
1
+ # -*- coding: utf-8 -*-
2
+ =begin
3
+ Copyright (C) 2011-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::Ephemeris
10
+
11
+ class Ephemeris < MiniTest::TestCase
12
+ def test_nothing
13
+ end
14
+ end
15
+
16
+ class CelestialObject < MiniTest::TestCase
17
+ def test_nothing
18
+ end
19
+ end
20
+
21
+ class Star < MiniTest::TestCase
22
+
23
+ def test_nothing
24
+ end
25
+
26
+ # 恒星
27
+ class Fixed < MiniTest::TestCase
28
+ def test__access_hr
29
+ polaris = When::Resource('_sc:HR0424')
30
+ assert_equal("Alp UMi", polaris.bayer_name)
31
+ end
32
+ end
33
+
34
+ # 春分点
35
+ class Vernal < MiniTest::TestCase
36
+ def test_nothing
37
+ end
38
+ end
39
+
40
+ # 北極
41
+ class Pole < MiniTest::TestCase
42
+ def test_nothing
43
+ end
44
+ end
45
+ end
46
+
47
+ class Planet < MiniTest::TestCase
48
+ def test_nothing
49
+ end
50
+ end
51
+
52
+ class Coords < MiniTest::TestCase
53
+ def test_nothing
54
+ end
55
+ end
56
+
57
+ class Formula < MiniTest::TestCase
58
+ def test__sunrise
59
+
60
+ today = '2014-3-4'
61
+
62
+ assert_raises(NoMethodError) { When.when?(today).sunrise }
63
+
64
+ location = When.Location('long=139.413012E&lat=35.412222N')
65
+ assert_equal(0, /2014-03-03T21:07/ =~ When.when?(today, {:location=>location}).sunrise.to_s)
66
+
67
+ When::Coordinates::Spatial.default_location = location
68
+ assert_equal(0, /2014-03-03T21:07/ =~ When.when?(today).sunrise.to_s)
69
+
70
+ When::TM::Clock.local_time = '+09:00'
71
+ assert_equal(0, /2014-03-04T06:07/ =~ When.when?(today).sunrise.to_s)
72
+ end
73
+
74
+ def test__lunisolar_location
75
+ formula1 = When.Resource('_ep:Formula?formula=1L')
76
+ formula2 = When.Resource('_ep:Formula?formula=12S')
77
+ date = When.when?('2014-08-01', :clock=>'+09:00')
78
+ assert_equal('2014-07-27T07:41+09:00', formula1.nearest_past(date).floor(When::MINUTE).to_s)
79
+ assert_equal('2014-07-23T06:41+09:00', formula2.nearest_past(date).floor(When::MINUTE).to_s)
80
+ assert_equal('2014-07-07T13:15+09:00', formula2.nearest_past(date, 0.5).floor(When::MINUTE).to_s)
81
+ end
82
+ end
83
+ end
@@ -1,14 +1,14 @@
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::Ephemeris
10
- class Moon < Test::Unit::TestCase
11
- def test_nothing
12
- end
13
- end
14
- end
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 MiniTest::Ephemeris
10
+ class Moon < MiniTest::TestCase
11
+ def test_nothing
12
+ end
13
+ end
14
+ end
@@ -1,14 +1,14 @@
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::Ephemeris
10
- class Planets < Test::Unit::TestCase
11
- def test_nothing
12
- end
13
- end
14
- end
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 MiniTest::Ephemeris
10
+ class Planets < MiniTest::TestCase
11
+ def test_nothing
12
+ end
13
+ end
14
+ end
@@ -1,14 +1,14 @@
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::Ephemeris
10
- class Sun < Test::Unit::TestCase
11
- def test_nothing
12
- end
13
- end
14
- end
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 MiniTest::Ephemeris
10
+ class Sun < MiniTest::TestCase
11
+ def test_nothing
12
+ end
13
+ end
14
+ end
@@ -1,176 +1,194 @@
1
- # -*- coding: utf-8 -*-
2
- =begin
3
- Copyright (C) 2012-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 Test
10
-
11
- class GoogleCalendar < Test::Unit::TestCase
12
-
13
- config = ::When.config
14
- ACCOUNT, PASSWORD = config['@'] if config.key?('@')
15
-
16
- PUBLIC_FEED = "http://www.google.com/calendar/feeds/%s__%s%%40holiday.calendar.google.com/public/full"
17
- PRIVATE_FEED = "http://www.google.com/calendar/feeds/%s%%40gmail.com/private/full"
18
- YEAR = "1949"
19
- RULE0 = <<RULE0
20
- DTSTART;VALUE=DATE:19490101
21
- DTEND;VALUE=DATE:19490102
22
- RRULE:FREQ=YEARLY
23
- RULE0
24
- RULE1 = <<RULE1
25
- RRULE:FREQ=YEARLY
26
- DTSTART;TZID=America/New_York:#{YEAR}0321T120000
27
- DTEND;TZID=America/New_York:#{YEAR}0322T130000
28
- RULE1
29
- RECURRENCE = <<RECURRENCE
30
- DTSTART;TZID=America/New_York:#{YEAR}0321T120000
31
- DTEND;TZID=America/New_York:#{YEAR}0322T130000
32
- RRULE:FREQ=YEARLY
33
- BEGIN:VTIMEZONE
34
- TZID:America/New_York
35
- X-LIC-LOCATION:America/New_York
36
- BEGIN:DAYLIGHT
37
- TZOFFSETFROM:-0500
38
- TZOFFSETTO:-0400
39
- TZNAME:EDT
40
- DTSTART:19700308T020000
41
- RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=2SU
42
- END:DAYLIGHT
43
- BEGIN:STANDARD
44
- TZOFFSETFROM:-0400
45
- TZOFFSETTO:-0500
46
- TZNAME:EST
47
- DTSTART:19701101T020000
48
- RRULE:FREQ=YEARLY;BYMONTH=11;BYDAY=1SU
49
- END:STANDARD
50
- END:VTIMEZONE
51
- RECURRENCE
52
-
53
- HOLIDAYS = [
54
- ["元日", "2012-01-01T00:00:00.00+09:00", "2012-01-02T00:00:00.00+09:00"],
55
- ["元日 振替休日", "2012-01-02T00:00:00.00+09:00", "2012-01-03T00:00:00.00+09:00"],
56
- ["銀行休業日", "2012-01-02T00:00:00.00+09:00", "2012-01-03T00:00:00.00+09:00"],
57
- ["銀行休業日", "2012-01-03T00:00:00.00+09:00", "2012-01-04T00:00:00.00+09:00"],
58
- ["成人の日", "2012-01-09T00:00:00.00+09:00", "2012-01-10T00:00:00.00+09:00"],
59
- ["建国記念の日", "2012-02-11T00:00:00.00+09:00", "2012-02-12T00:00:00.00+09:00"],
60
- ["春分の日", "2012-03-20T00:00:00.00+09:00", "2012-03-21T00:00:00.00+09:00"],
61
- ["昭和の日", "2012-04-29T00:00:00.00+09:00", "2012-04-30T00:00:00.00+09:00"],
62
- ["昭和の日 振替休日", "2012-04-30T00:00:00.00+09:00", "2012-05-01T00:00:00.00+09:00"],
63
- ["憲法記念日", "2012-05-03T00:00:00.00+09:00", "2012-05-04T00:00:00.00+09:00"],
64
- ["みどりの日", "2012-05-04T00:00:00.00+09:00", "2012-05-05T00:00:00.00+09:00"],
65
- ["こどもの日", "2012-05-05T00:00:00.00+09:00", "2012-05-06T00:00:00.00+09:00"],
66
- ["海の日", "2012-07-16T00:00:00.00+09:00", "2012-07-17T00:00:00.00+09:00"],
67
- ["敬老の日", "2012-09-17T00:00:00.00+09:00", "2012-09-18T00:00:00.00+09:00"],
68
- ["秋分の日", "2012-09-22T00:00:00.00+09:00", "2012-09-23T00:00:00.00+09:00"],
69
- ["体育の日", "2012-10-08T00:00:00.00+09:00", "2012-10-09T00:00:00.00+09:00"],
70
- ["文化の日", "2012-11-03T00:00:00.00+09:00", "2012-11-04T00:00:00.00+09:00"],
71
- ["勤労感謝の日", "2012-11-23T00:00:00.00+09:00", "2012-11-24T00:00:00.00+09:00"],
72
- ["天皇誕生日", "2012-12-23T00:00:00.00+09:00", "2012-12-24T00:00:00.00+09:00"],
73
- ["天皇誕生日 振替休日", "2012-12-24T00:00:00.00+09:00", "2012-12-25T00:00:00.00+09:00"],
74
- ["クリスマス", "2012-12-25T00:00:00.00+09:00", "2012-12-26T00:00:00.00+09:00"],
75
- ["大晦日", "2012-12-31T00:00:00.00+09:00", "2013-01-01T00:00:00.00+09:00"]
76
- ]
77
-
78
- WEEKLY_EVENTS = [
79
- "2012-03-08T08:30:00+09:00...2012-03-08T09:30:00+09:00",
80
- "2012-03-15T08:30:00+09:00...2012-03-15T09:30:00+09:00",
81
- "2012-03-22T08:30:00+09:00...2012-03-22T09:30:00+09:00",
82
- "2012-03-29T08:30:00+09:00...2012-03-29T09:30:00+09:00"
83
- ]
84
-
85
- def get_cal(feed)
86
- ::GoogleCalendar::Calendar::new(::GoogleCalendar::Service.new("#{ACCOUNT}@gmail.com", PASSWORD), feed)
87
- end
88
-
89
- def test_nothing
90
- end
91
-
92
- if const_defined?(:PASSWORD) && Object.const_defined?(:GoogleCalendar)
93
-
94
- def test__to_vevent
95
- holidays = HOLIDAYS.dup
96
- gcal = get_cal(PUBLIC_FEED % ['japanese', 'ja'])
97
- gcal.events({'start-min'=>'2012-01-01', 'start-max'=>'2013-01-01',
98
- 'orderby'=>'starttime', 'sortorder'=>'a' # a:asend, d:desend
99
- }).each do |event|
100
- vevent = event.to_vevent
101
- assert_equal(holidays.shift, [vevent.summary, vevent.dtstart.to_s, vevent.dtend.to_s])
102
- # puts event.xml
103
- end
104
- assert_equal(0, holidays.size)
105
- end
106
-
107
- def test__to_gcalevent
108
- gcal = get_cal(PRIVATE_FEED % ACCOUNT)
109
- period = {'start-min'=>'2001-01-01', 'start-max'=>'2001-01-31'}
110
- gcal.events(period).each do |event|
111
- event.destroy
112
- end
113
- event = When.Resource("examples/JapanHolidays.ics::Ganjitsu").to_gcalevent(gcal)
114
- event.save!
115
- holidays = [RULE0] * 2
116
- gcal.events(period).each do |event|
117
- assert_equal(holidays.shift, event.recurrence)
118
- end
119
- pp 'WARN: event is duplicated.' if holidays.size == 0
120
- assert_equal(true, (0..1).include?(holidays.size))
121
- end
122
-
123
- def test__enum_for
124
- holidays = HOLIDAYS.dup
125
- holidays.delete_at(2)
126
- gcal = get_cal(PUBLIC_FEED % ['japanese', 'ja'])
127
- gcal.enum_for({'start-min'=>'2012-01-01', 'start-max'=>'2013-01-01'}).each do |date|
128
- sample = holidays.shift
129
- assert_equal(sample[1] + '...' + sample[2], date.to_s)
130
- end
131
- assert_equal(0, holidays.size)
132
- end
133
-
134
- =begin
135
- def test__eprivate_events_1
136
- weekly_events = WEEKLY_EVENTS.dup
137
- gcal = get_cal(PRIVATE_FEED % ACCOUNT)
138
- period = {'start-min'=>'2012-03-01', 'start-max'=>'2012-03-31'}
139
-
140
- assert_equal(["canceled","confirmed"], gcal.events(period).map {|event| event.event_status})
141
- gcal.enum_for(period).each do |date|
142
- assert_equal(weekly_events.shift, date.to_s)
143
- end
144
- assert_equal(0, weekly_events.size)
145
- end
146
-
147
- def test__private_events_2
148
- gcal = get_cal(PRIVATE_FEED % ACCOUNT)
149
- period = {'start-min'=>YEAR + '-03-01', 'start-max'=>YEAR + '-03-31'}
150
-
151
- gcal.events(period).each do |event|
152
- event.destroy
153
- end
154
-
155
- new_event = gcal.create_event
156
- new_event.title = "Test Event"
157
- new_event.desc = "Test Event Description"
158
- new_event.where = "America/New_York"
159
- #new_event.st = Time.mktime(YEAR.to_i, 3, 21, 12, 0, 0)
160
- #new_event.en = Time.mktime(YEAR.to_i, 3, 22, 13, 0, 0)
161
- new_event.recurrence = RULE1
162
- new_event.save!
163
-
164
- gcal.events(period).each do |event|
165
- assert_equal([new_event.title, new_event.desc, new_event.where, RECURRENCE],
166
- [event.title, event.desc, event.where, event.recurrence])
167
- end
168
- new_event.destroy
169
- end
170
- =end
171
- else
172
- puts "Tests for GoogleCalendar have been skipped at line #{__LINE__} of #{__FILE__.split(/\//)[-1]}."
173
- end
174
- end
175
- end
176
-
1
+ # -*- coding: utf-8 -*-
2
+ =begin
3
+ Copyright (C) 2012-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 GoogleCalendar < MiniTest::TestCase
12
+
13
+ config = ::When.config
14
+ ACCOUNT, PASSWORD = config['@'] if config.key?('@')
15
+
16
+ PUBLIC_FEED = "http://www.google.com/calendar/feeds/%s__%s%%40holiday.calendar.google.com/public/full"
17
+ PRIVATE_FEED = "http://www.google.com/calendar/feeds/%s%%40gmail.com/private/full"
18
+ YEAR = "1949"
19
+ RULE0 = <<RULE0
20
+ DTSTART;VALUE=DATE:19490101
21
+ DTEND;VALUE=DATE:19490102
22
+ RRULE:FREQ=YEARLY
23
+ RULE0
24
+ RULE1 = <<RULE1
25
+ RRULE:FREQ=YEARLY
26
+ DTSTART;TZID=America/New_York:#{YEAR}0321T120000
27
+ DTEND;TZID=America/New_York:#{YEAR}0322T130000
28
+ RULE1
29
+ RECURRENCE = <<RECURRENCE
30
+ DTSTART;TZID=America/New_York:#{YEAR}0321T120000
31
+ DTEND;TZID=America/New_York:#{YEAR}0322T130000
32
+ RRULE:FREQ=YEARLY
33
+ BEGIN:VTIMEZONE
34
+ TZID:America/New_York
35
+ X-LIC-LOCATION:America/New_York
36
+ BEGIN:DAYLIGHT
37
+ TZOFFSETFROM:-0500
38
+ TZOFFSETTO:-0400
39
+ TZNAME:EDT
40
+ DTSTART:19700308T020000
41
+ RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=2SU
42
+ END:DAYLIGHT
43
+ BEGIN:STANDARD
44
+ TZOFFSETFROM:-0400
45
+ TZOFFSETTO:-0500
46
+ TZNAME:EST
47
+ DTSTART:19701101T020000
48
+ RRULE:FREQ=YEARLY;BYMONTH=11;BYDAY=1SU
49
+ END:STANDARD
50
+ END:VTIMEZONE
51
+ RECURRENCE
52
+
53
+ HOLIDAYS1 = [ # Public Feed
54
+ ["元日", "2013-01-01T00:00:00.00+09:00", "2013-01-02T00:00:00.00+09:00"],
55
+ ["銀行休業日", "2013-01-02T00:00:00.00+09:00", "2013-01-03T00:00:00.00+09:00"],
56
+ ["銀行休業日", "2013-01-03T00:00:00.00+09:00", "2013-01-04T00:00:00.00+09:00"],
57
+ ["成人の日", "2013-01-14T00:00:00.00+09:00", "2013-01-15T00:00:00.00+09:00"],
58
+ ["建国記念の日", "2013-02-11T00:00:00.00+09:00", "2013-02-12T00:00:00.00+09:00"],
59
+ ["春分の日", "2013-03-20T00:00:00.00+09:00", "2013-03-21T00:00:00.00+09:00"],
60
+ ["昭和の日", "2013-04-29T00:00:00.00+09:00", "2013-04-30T00:00:00.00+09:00"],
61
+ ["憲法記念日", "2013-05-03T00:00:00.00+09:00", "2013-05-04T00:00:00.00+09:00"],
62
+ ["みどりの日", "2013-05-04T00:00:00.00+09:00", "2013-05-05T00:00:00.00+09:00"],
63
+ ["こどもの日", "2013-05-05T00:00:00.00+09:00", "2013-05-06T00:00:00.00+09:00"],
64
+ ["こどもの日 振替休日", "2013-05-06T00:00:00.00+09:00", "2013-05-07T00:00:00.00+09:00"],
65
+ ["海の日", "2013-07-15T00:00:00.00+09:00", "2013-07-16T00:00:00.00+09:00"],
66
+ ["敬老の日", "2013-09-16T00:00:00.00+09:00", "2013-09-17T00:00:00.00+09:00"],
67
+ ["秋分の日", "2013-09-23T00:00:00.00+09:00", "2013-09-24T00:00:00.00+09:00"],
68
+ ["体育の日", "2013-10-14T00:00:00.00+09:00", "2013-10-15T00:00:00.00+09:00"],
69
+ ["文化の日", "2013-11-03T00:00:00.00+09:00", "2013-11-04T00:00:00.00+09:00"],
70
+ ["文化の日 振替休日", "2013-11-04T00:00:00.00+09:00", "2013-11-05T00:00:00.00+09:00"],
71
+ ["勤労感謝の日", "2013-11-23T00:00:00.00+09:00", "2013-11-24T00:00:00.00+09:00"],
72
+ ["天皇誕生日", "2013-12-23T00:00:00.00+09:00", "2013-12-24T00:00:00.00+09:00"],
73
+ ["クリスマス", "2013-12-25T00:00:00.00+09:00", "2013-12-26T00:00:00.00+09:00"],
74
+ ["大晦日", "2013-12-31T00:00:00.00+09:00", "2014-01-01T00:00:00.00+09:00"]
75
+ ]
76
+
77
+ HOLIDAYS2 = [ # Private Feed
78
+ ["元日", "2013-01-01T00:00:00.00+09:00", "2013-01-02T00:00:00.00+09:00"],
79
+ ["元日 振替休日", "2013-01-02T00:00:00.00+09:00", "2013-01-03T00:00:00.00+09:00"],
80
+ ["銀行休業日", "2013-01-03T00:00:00.00+09:00", "2013-01-04T00:00:00.00+09:00"],
81
+ ["成人の日", "2013-01-14T00:00:00.00+09:00", "2013-01-15T00:00:00.00+09:00"],
82
+ ["建国記念の日", "2013-02-11T00:00:00.00+09:00", "2013-02-12T00:00:00.00+09:00"],
83
+ ["春分の日", "2013-03-20T00:00:00.00+09:00", "2013-03-21T00:00:00.00+09:00"],
84
+ ["昭和の日", "2013-04-29T00:00:00.00+09:00", "2013-04-30T00:00:00.00+09:00"],
85
+ ["憲法記念日", "2013-05-03T00:00:00.00+09:00", "2013-05-04T00:00:00.00+09:00"],
86
+ ["みどりの日", "2013-05-04T00:00:00.00+09:00", "2013-05-05T00:00:00.00+09:00"],
87
+ ["こどもの日", "2013-05-05T00:00:00.00+09:00", "2013-05-06T00:00:00.00+09:00"],
88
+ ["みどりの日 振替休日", "2013-05-06T00:00:00.00+09:00", "2013-05-07T00:00:00.00+09:00"],
89
+ ["海の日", "2013-07-15T00:00:00.00+09:00", "2013-07-16T00:00:00.00+09:00"],
90
+ ["敬老の日", "2013-09-16T00:00:00.00+09:00", "2013-09-17T00:00:00.00+09:00"],
91
+ ["秋分の日", "2013-09-23T00:00:00.00+09:00", "2013-09-24T00:00:00.00+09:00"],
92
+ ["体育の日", "2013-10-14T00:00:00.00+09:00", "2013-10-15T00:00:00.00+09:00"],
93
+ ["文化の日", "2013-11-03T00:00:00.00+09:00", "2013-11-04T00:00:00.00+09:00"],
94
+ ["文化の日 振替休日", "2013-11-04T00:00:00.00+09:00", "2013-11-05T00:00:00.00+09:00"],
95
+ ["勤労感謝の日", "2013-11-23T00:00:00.00+09:00", "2013-11-24T00:00:00.00+09:00"],
96
+ ["天皇誕生日", "2013-12-23T00:00:00.00+09:00", "2013-12-24T00:00:00.00+09:00"],
97
+ ["クリスマス", "2013-12-25T00:00:00.00+09:00", "2013-12-26T00:00:00.00+09:00"],
98
+ ["大晦日", "2013-12-31T00:00:00.00+09:00", "2014-01-01T00:00:00.00+09:00"]
99
+ ]
100
+
101
+ WEEKLY_EVENTS = [
102
+ "2014-07-17T08:30:00+09:00...2014-07-17T09:30:00+09:00",
103
+ "2014-07-31T08:30:00+09:00...2014-07-31T09:30:00+09:00"
104
+ ]
105
+
106
+ def get_cal(feed)
107
+ ::GoogleCalendar::Calendar::new(::GoogleCalendar::Service.new("#{ACCOUNT}@gmail.com", PASSWORD), feed)
108
+ end
109
+
110
+ def test_nothing
111
+ end
112
+
113
+ if const_defined?(:PASSWORD) && Object.const_defined?(:GoogleCalendar)
114
+
115
+ def test__to_vevent
116
+ holidays = HOLIDAYS1.dup
117
+ gcal = get_cal(PUBLIC_FEED % ['japanese', 'ja'])
118
+ gcal.events({'start-min'=>'2013-01-01', 'start-max'=>'2014-01-01',
119
+ 'orderby'=>'starttime', 'sortorder'=>'a' # a:asend, d:desend
120
+ }).each do |event|
121
+ vevent = event.to_vevent
122
+ assert_equal(holidays.shift, [vevent.summary, vevent.dtstart.to_s, vevent.dtend.to_s])
123
+ # puts event.xml
124
+ end
125
+ assert_equal(0, holidays.size)
126
+ end
127
+
128
+ def test__to_gcalevent
129
+ gcal = get_cal(PRIVATE_FEED % ACCOUNT)
130
+ period = {'start-min'=>'2001-01-01', 'start-max'=>'2001-01-31'}
131
+ gcal.events(period).each do |event|
132
+ event.destroy
133
+ end
134
+ event = When.Resource("examples/JapanHolidays.ics::Ganjitsu").to_gcalevent(gcal)
135
+ event.save!
136
+ holidays = [RULE0]
137
+ gcal.events(period).each do |event|
138
+ assert_equal(holidays.shift, event.recurrence)
139
+ end
140
+ assert_equal(0, holidays.size)
141
+ end
142
+
143
+ def test__enum_for
144
+ holidays = HOLIDAYS2.dup
145
+ gcal = get_cal(PUBLIC_FEED % ['japanese', 'ja'])
146
+ gcal.enum_for({'start-min'=>'2013-01-01', 'start-max'=>'2014-01-01'}).each do |date|
147
+ sample = holidays.shift
148
+ assert_equal(sample[1] + '...' + sample[2], date.to_s)
149
+ end
150
+ assert_equal(0, holidays.size)
151
+ end
152
+ =begin
153
+ def test__private_events_1
154
+ weekly_events = WEEKLY_EVENTS.dup
155
+ gcal = get_cal(PRIVATE_FEED % ACCOUNT)
156
+ period = {'start-min'=>'2014-07-01', 'start-max'=>'2014-08-01'}
157
+
158
+ assert_equal(["canceled","confirmed"], gcal.events(period).map {|event| event.event_status})
159
+ gcal.enum_for(period).each do |date|
160
+ assert_equal(weekly_events.shift, date.to_s)
161
+ end
162
+ assert_equal(0, weekly_events.size)
163
+ end
164
+
165
+ def test__private_events_2
166
+ gcal = get_cal(PRIVATE_FEED % ACCOUNT)
167
+ period = {'start-min'=>YEAR + '-03-01', 'start-max'=>YEAR + '-03-31'}
168
+
169
+ gcal.events(period).each do |event|
170
+ event.destroy
171
+ end
172
+
173
+ new_event = gcal.create_event
174
+ new_event.title = "MiniTest Event"
175
+ new_event.desc = "MiniTest Event Description"
176
+ new_event.where = "America/New_York"
177
+ #new_event.st = Time.mktime(YEAR.to_i, 3, 21, 12, 0, 0)
178
+ #new_event.en = Time.mktime(YEAR.to_i, 3, 22, 13, 0, 0)
179
+ new_event.recurrence = RULE1
180
+ new_event.save!
181
+
182
+ gcal.events(period).each do |event|
183
+ assert_equal([new_event.title, new_event.desc, new_event.where, RECURRENCE],
184
+ [event.title, event.desc, event.where, event.recurrence])
185
+ end
186
+ new_event.destroy
187
+ end
188
+ =end
189
+ else
190
+ puts "Tests for GoogleCalendar have been skipped at line #{__LINE__} of #{__FILE__.split(/\//)[-1]}."
191
+ end
192
+ end
193
+ end
194
+