when_exe 0.3.6 → 0.3.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (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,69 +1,86 @@
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 Test::CalendarNote
10
-
11
- class NotesContainer < Test::Unit::TestCase
12
-
13
- def test__lunar_phases
14
- assert_equal([[{:note=>"月相", :value=>"朔(-233/3040)", :position=>"中段"}]],
15
- When.when?('承和2.4.2').notes(:notes=>'月相', :conditions=>{:shoyo=>true}))
16
- assert_equal([[{:note=>"月相", :value=>"望(1478.5/3040)", :position=>"中段"}]],
17
- When.when?('承和2.4.16').notes(:notes=>'月相', :conditions=>{:shoyo=>true}))
18
- all = {}
19
- assert_equal([[{:note=>"月相", :value=>"望(1478.5/3040)", :position=>"中段"}]],
20
- When.when?('承和2.4.16').notes(:notes=>'月相', :shoyo=>true, :persistence=>all))
21
- assert_equal({2026177=>[[{:note=>"月相", :value=>"望(1478.5/3040)", :position=>"中段"}]]}, all)
22
- end
23
-
24
- def test__persistence
25
- all = {}
26
- notes0 = When.when?('平成25.9.22').notes(:persistence=>all)
27
- notes1 = When.when?('平成25.9.23').notes(:persistence=>all)
28
- notes2 = When.when?('平成25.9.24').notes(:persistence=>all)
29
- notes3 = When.when?('平成25.9.23').notes(:persistence=>all)
30
-
31
- [notes1, notes3].each do |notes|
32
- assert_equal(
33
- [[{:note=>"干支", :value=>"癸巳(29)", :position=>"共通"}],
34
- [{:note=>"月名", :value=>"September", :position=>"月建"}],
35
- [{:note=>"七曜", :value=>"Monday(0)", :position=>"共通"},
36
- {:note=>"干支", :value=>"壬辰(28)", :position=>"共通"},
37
- {:note=>"六曜", :value=>"友引", :position=>"民間"},
38
- {:note=>"廿四節気", :value=>"秋分(180)", :position=>"時候"},
39
- {:note=>"祝祭日", :value=>"秋分の日", :position=>"祝祭日"}]], notes)
40
- end
41
-
42
- assert_equal([["癸巳(29)"], ["September"], ["Monday(0)", "壬辰(28)", "友引", "秋分(180)", "秋分の日"]],
43
- notes1.simplify[:value])
44
-
45
- assert_equal([[{:note=>"月名", :value=>"September", :position=>"月建"}]], notes1.subset(:note=>/Month/))
46
- assert_equal([[{:note=>"干支", :value=>"癸巳(29)", :position=>"共通"}],
47
- [{:note=>"干支", :value=>"壬辰(28)", :position=>"共通"}]], notes1.subset(:note=>'干支'))
48
- assert_equal([[{:note=>"祝祭日", :value=>"秋分の日", :position=>"祝祭日"}]], notes1.subset(:value=>'秋分の日'))
49
- assert_equal(nil, notes1.subset(:value=>'春分の日'))
50
- assert_equal([[nil], [nil], [nil, nil, nil, nil, nil]], notes1.subset({:value=>'春分の日'}, false))
51
-
52
- assert_equal([2456558, 2456559, 2456560], all.keys)
53
- assert_equal({2456559=>"秋分の日"}, all.subset(:value=>'秋分の日').simplify[:value])
54
- end
55
-
56
- def test__holiday
57
- date1 = When.when?('平成25.9.23')
58
- date2 = When.when?('平成25.9.24')
59
- notes1 = date1.notes("祝祭日")
60
- assert_equal([[{:note=>"祝祭日", :value=>"秋分の日", :position=>"祝祭日"}]], notes1)
61
- assert_equal({:note=>"祝祭日", :value=>"秋分の日", :position=>"祝祭日"}, notes1.simplify)
62
- assert_equal(true, date1.is?({:note=>"祝祭日", :value=>"秋分の日"}))
63
- assert_equal(true, date1.is?("祝祭日"))
64
- assert_equal(true, date1.is?("秋分の日"))
65
- assert_equal(false, date2.is?("秋分の日"))
66
- end
67
- end
68
- end
69
-
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::CalendarNote
10
+
11
+ class NotesContainer < MiniTest::TestCase
12
+
13
+ def test__lunar_phases
14
+ assert_equal([[{:note=>"月相", :value=>"朔(-233/3040)", :position=>"中段"}]],
15
+ When.when?('承和2.4.2').notes(:notes=>'月相', :conditions=>{:shoyo=>true}))
16
+ assert_equal([[{:note=>"月相", :value=>"望(1478.5/3040)", :position=>"中段"}]],
17
+ When.when?('承和2.4.16').notes(:notes=>'月相', :conditions=>{:shoyo=>true}))
18
+ all = {}
19
+ assert_equal([[{:note=>"月相", :value=>"望(1478.5/3040)", :position=>"中段"}]],
20
+ When.when?('承和2.4.16').notes(:notes=>'月相', :shoyo=>true, :persistence=>all))
21
+ assert_equal({2026177=>[[{:note=>"月相", :value=>"望(1478.5/3040)", :position=>"中段"}]]}, all)
22
+ end
23
+
24
+ def test__solar_terms
25
+ term = When.CalendarNote('SolarTerms').copy('term315')
26
+ assert_equal('2014-02-03', term.term(When.when?('2014-1-1')).to_s)
27
+ end
28
+
29
+ def test__persistence
30
+ all = {}
31
+ notes0 = When.when?('平成25.9.22').notes(:persistence=>all)
32
+ notes1 = When.when?('平成25.9.23').notes(:persistence=>all)
33
+ notes2 = When.when?('平成25.9.24').notes(:persistence=>all)
34
+ notes3 = When.when?('平成25.9.23').notes(:persistence=>all)
35
+
36
+ [notes1, notes3].each do |notes|
37
+ assert_equal(
38
+ [[{:note=>"干支", :value=>"癸巳(29)", :position=>"共通"}],
39
+ [{:note=>"月名", :value=>"September", :position=>"月建"}],
40
+ [{:note=>"七曜", :value=>"Monday(0)", :position=>"共通"},
41
+ {:note=>"干支", :value=>"壬辰(28)", :position=>"共通"},
42
+ {:note=>"六曜", :value=>"友引", :position=>"民間"},
43
+ {:note=>"廿四節気", :value=>"秋分(180)", :position=>"時候"},
44
+ {:note=>"祝祭日", :value=>"秋分の日", :position=>"祝祭日"}]], notes)
45
+ end
46
+
47
+ assert_equal([["癸巳(29)"], ["September"], ["Monday(0)", "壬辰(28)", "友引", "秋分(180)", "秋分の日"]],
48
+ notes1.simplify[:value])
49
+
50
+ assert_equal([[{:note=>"月名", :value=>"September", :position=>"月建"}]], notes1.subset(:note=>/Month/))
51
+ assert_equal([[{:note=>"干支", :value=>"癸巳(29)", :position=>"共通"}],
52
+ [{:note=>"干支", :value=>"壬辰(28)", :position=>"共通"}]], notes1.subset(:note=>'干支'))
53
+ assert_equal([[{:note=>"祝祭日", :value=>"秋分の日", :position=>"祝祭日"}]], notes1.subset(:value=>'秋分の日'))
54
+ assert_equal(nil, notes1.subset(:value=>'春分の日'))
55
+ assert_equal([[nil], [nil], [nil, nil, nil, nil, nil]], notes1.subset({:value=>'春分の日'}, false))
56
+
57
+ assert_equal([2456558, 2456559, 2456560], all.keys)
58
+ assert_equal({2456559=>"秋分の日"}, all.subset(:value=>'秋分の日').simplify[:value])
59
+ end
60
+
61
+ def test__holiday
62
+ date1 = When.when?('平成25.9.23')
63
+ date2 = When.when?('平成25.9.24')
64
+ notes1 = date1.notes("祝祭日")
65
+ assert_equal([[{:note=>"祝祭日", :value=>"秋分の日", :position=>"祝祭日"}]], notes1)
66
+ assert_equal({:note=>"祝祭日", :value=>"秋分の日", :position=>"祝祭日"}, notes1.simplify)
67
+ assert_equal(true, date1.is?({:note=>"祝祭日", :value=>"秋分の日"}))
68
+ assert_equal(true, date1.is?("祝祭日"))
69
+ assert_equal(true, date1.is?("秋分の日"))
70
+ assert_equal(false, date2.is?("秋分の日"))
71
+
72
+ note = When.CalendarNote('Japanese')
73
+ assert_equal(true, note.note?(When.when?('2014-9-15'), '祝祭日'))
74
+ assert_equal(true, note.note?(When.when?('2014-9-15'), {:notes=>'祝祭日', :value=>'敬老の日'}))
75
+ assert_equal(false, note.note?(When.when?('2014-9-15'), {:notes=>'祝祭日', :value=>'敬老日'}))
76
+ assert_equal('敬老の日', note.notes(When.when?('2014-9-15'), '祝祭日')[:value].simplify.to_s)
77
+
78
+ assert_equal('五黄土星(4)', note.notes(When.when?('2014-1-1'), {:notes=>[['九星'],[],[]], :indices=>-2})[:value].simplify.to_s)
79
+ assert_equal('一白水星(8)', note.notes(When.when?('2014-1-1'), {:notes=>[[],['九星'],[]], :indices=>-1})[:value].simplify.to_s)
80
+ assert_equal('九紫火星(0)', note.notes(When.when?('2014-1-1'), {:notes=>'九星', :indices=> 0})[:value].simplify.to_s)
81
+
82
+ assert_equal(true, When.CalendarNote('Christian').copy('christmas').include?(When.when?('2012-12-25')))
83
+ end
84
+ end
85
+ end
86
+
@@ -1,97 +1,97 @@
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::CalendarTypes
10
-
11
- class UTC < Test::Unit::TestCase
12
- def test__utc
13
- assert_equal("+00:00", When::UTC.tzname[0].to_s)
14
- end
15
- end
16
-
17
- class TableBased < Test::Unit::TestCase
18
- def test_nothing
19
- end
20
- end
21
-
22
- class PatternTableBasedLuniSolar < Test::Unit::TestCase
23
- def test__japanese
24
-
25
- frame = When.Resource('Japanese', '_c:')
26
- date = When.when?('16000101^Japanese')
27
- assert_equal(["1600-01-01", 2305493], [date.to_s, date.to_i])
28
- assert_equal(2305493, frame._coordinates_to_number(1600-454,0,0))
29
- assert_equal([1146, 0, 0], frame._number_to_coordinates(2305493))
30
-
31
- date = When.when?('0594-09=12^Japanese')
32
- assert_equal(["0594-09=12", 1938320], [date.to_s, date.to_i])
33
- assert_equal(594, date['YEAR'])
34
- assert_equal(When::BasicTypes::M17n, date.name('Month').class)
35
-
36
- result = []
37
- (date ^ When::TM::Calendar).each do |d|
38
- result << d.to_s
39
- end
40
- result.sort!
41
-
42
- sample = ["0594-09=12", "0594-11-02", "0594-11-02"] #TODO �Ȃ� Greg 2��?
43
- # assert_equal(sample, result)
44
- end
45
- end
46
-
47
- class CyclicTableBased < Test::Unit::TestCase
48
- def test__islamic
49
- frame = When.Resource('_c:TabularIslamic')
50
- date = When.when?('00010101^TabularIslamic')
51
- assert_equal(["0001-01-01", 1948440], [date.to_s, date.to_i])
52
- assert_equal(1959071, frame._coordinates_to_number(31,0,0))
53
- assert_equal([31, 0, 0], frame._number_to_coordinates(1948440+10631))
54
- end
55
- end
56
-
57
- class SolarTerms < Test::Unit::TestCase
58
-
59
- Sample = %w(2013-03-20 2013-06-21 2013-09-23 2013-12-22
60
- 2014-03-21 2014-06-21 2014-09-23 2014-12-22
61
- 2015-03-21 2015-06-22 2015-09-23 2015-12-22)
62
-
63
- def test__term
64
- note = When.CalendarNote('SolarTerms')
65
- assert_equal('2014-03-20', note.term(When.when?('2014-3-1'), [0,30]).to_s)
66
- When::TM::Clock.local_time = '+09:00'
67
- assert_equal('2014-03-21', note.term(When.when?('2014-3-1'), [0,30]).to_s)
68
- end
69
-
70
- def test__each
71
- When::TM::Clock.local_time = '+09:00'
72
- note = When.CalendarNote('SolarTerms')
73
- note_with_event = When.CalendarNote('SolarTerms?event=term0/90')
74
- today = When.when?('2013-03-01')
75
- last = When.when?('2016-01-01')
76
-
77
- sample = Sample.dup
78
- note_with_event.each(today) do |date|
79
- assert_equal(sample.shift, date.to_s)
80
- break if sample.empty?
81
- end
82
-
83
- sample = Sample.dup
84
- note_with_event.each(today...last) do |date|
85
- assert_equal(sample.shift, date.to_s)
86
- end
87
- assert_equal(true, sample.empty?)
88
-
89
- sample = Sample.dup
90
- note.each(today...last, {:event=>'term0/90', :count_limit=>4}) do |date|
91
- assert_equal(sample.shift, date.to_s)
92
- end
93
- assert_equal(Sample.length - 4, sample.length)
94
- end
95
- end
96
- end
97
-
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::CalendarTypes
10
+
11
+ class UTC < MiniTest::TestCase
12
+ def test__utc
13
+ assert_equal("+00:00", When::UTC.tzname[0].to_s)
14
+ end
15
+ end
16
+
17
+ class TableBased < MiniTest::TestCase
18
+ def test_nothing
19
+ end
20
+ end
21
+
22
+ class PatternTableBasedLuniSolar < MiniTest::TestCase
23
+ def test__japanese
24
+
25
+ frame = When.Resource('Japanese', '_c:')
26
+ date = When.when?('16000101^Japanese')
27
+ assert_equal(["1600-01-01", 2305493], [date.to_s, date.to_i])
28
+ assert_equal(2305493, frame._coordinates_to_number(1600-454,0,0))
29
+ assert_equal([1146, 0, 0], frame._number_to_coordinates(2305493))
30
+
31
+ date = When.when?('0594-09=12^Japanese')
32
+ assert_equal(["0594-09=12", 1938320], [date.to_s, date.to_i])
33
+ assert_equal(594, date['YEAR'])
34
+ assert_equal(When::BasicTypes::M17n, date.name('Month').class)
35
+
36
+ result = []
37
+ (date ^ When::TM::Calendar).each do |d|
38
+ result << d.to_s
39
+ end
40
+ result.sort!
41
+
42
+ sample = ["0594-09=12", "0594-11-02", "0594-11-02"] #TODO �Ȃ� Greg 2��?
43
+ # assert_equal(sample, result)
44
+ end
45
+ end
46
+
47
+ class CyclicTableBased < MiniTest::TestCase
48
+ def test__islamic
49
+ frame = When.Resource('_c:TabularIslamic')
50
+ date = When.when?('00010101^TabularIslamic')
51
+ assert_equal(["0001-01-01", 1948440], [date.to_s, date.to_i])
52
+ assert_equal(1959071, frame._coordinates_to_number(31,0,0))
53
+ assert_equal([31, 0, 0], frame._number_to_coordinates(1948440+10631))
54
+ end
55
+ end
56
+
57
+ class SolarTerms < MiniTest::TestCase
58
+
59
+ Sample = %w(2013-03-20 2013-06-21 2013-09-23 2013-12-22
60
+ 2014-03-21 2014-06-21 2014-09-23 2014-12-22
61
+ 2015-03-21 2015-06-22 2015-09-23 2015-12-22)
62
+
63
+ def test__term
64
+ note = When.CalendarNote('SolarTerms')
65
+ assert_equal('2014-03-20', note.term(When.when?('2014-3-1'), [0,30]).to_s)
66
+ When::TM::Clock.local_time = '+09:00'
67
+ assert_equal('2014-03-21', note.term(When.when?('2014-3-1'), [0,30]).to_s)
68
+ end
69
+
70
+ def test__each
71
+ When::TM::Clock.local_time = '+09:00'
72
+ note = When.CalendarNote('SolarTerms')
73
+ note_with_event = When.CalendarNote('SolarTerms?event=term0/90')
74
+ today = When.when?('2013-03-01')
75
+ last = When.when?('2016-01-01')
76
+
77
+ sample = Sample.dup
78
+ note_with_event.each(today) do |date|
79
+ assert_equal(sample.shift, date.to_s)
80
+ break if sample.empty?
81
+ end
82
+
83
+ sample = Sample.dup
84
+ note_with_event.each(today...last) do |date|
85
+ assert_equal(sample.shift, date.to_s)
86
+ end
87
+ assert_equal(true, sample.empty?)
88
+
89
+ sample = Sample.dup
90
+ note.each(today...last, {:event=>'term0/90', :count_limit=>4}) do |date|
91
+ assert_equal(sample.shift, date.to_s)
92
+ end
93
+ assert_equal(Sample.length - 4, sample.length)
94
+ end
95
+ end
96
+ end
97
+
@@ -1,396 +1,396 @@
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::Coordinates
10
-
11
- #
12
- # 剰余類
13
- #
14
- class Residue < Test::Unit::TestCase
15
-
16
- def test__intersection
17
- r1 = When::Coordinates::Residue.new(3,10)
18
- r2 = When::Coordinates::Residue.new(5,12)
19
- r3 = When::Coordinates::Residue.new(6,12)
20
- r = r1 & r2
21
- assert_equal([53,60], [r.remainder, r.divisor])
22
- assert_nil(r1 & r3)
23
-
24
- r4 = When::Coordinates::Residue.new(2,7)
25
- date1 = When.when?(2440587.5)
26
- assert_equal(2440593.5, (date1 & r4).to_f)
27
-
28
- r5 = When::Coordinates::Residue.new(3,7)
29
- date2 = When.when?("19820606^^Julian")
30
- assert_equal("1982-06-11", (date2 & r5).to_s)
31
- assert_equal("1982-06-11", (r5 & date2).to_s)
32
-
33
- assert_equal("1982-06-10T00:00:00.00Z", (r5 & Time.utc(1982,6,6)).to_s)
34
- if ::Object.const_defined?(:Date) && Date.respond_to?(:civil)
35
- assert_equal("1982-06-24", (r5 & Date.new(1982,6,6,Date::JULIAN)).to_s)
36
- end
37
-
38
- date3 = When.when?("19820606T021540+0900^^Julian")
39
- [[-5, "1979-06-06T02:15:40+09:00"],
40
- [-4, "1980-06-06T02:15:40+09:00"],
41
- [-3, "1981-06-06T02:15:40+09:00"],
42
- [-2, "1922-06-06T02:15:40+09:00"],
43
- [-1, "1923-06-06T02:15:40+09:00"],
44
- [ 0, "1984-06-06T02:15:40+09:00"],
45
- [ 1, "1985-06-06T02:15:40+09:00"],
46
- [ 2, "1986-06-06T02:15:40+09:00"],
47
- [ 3, "1987-06-06T02:15:40+09:00"],
48
- [ 4, "1988-06-06T02:15:40+09:00"],
49
- [ 5, "1989-06-06T02:15:40+09:00"]].each do |sample|
50
- r6 = When::Coordinates::Residue.new(sample[0], 60, {'year'=>4})
51
- assert_equal(sample[1], (date3 & r6).to_s)
52
- assert_equal(sample[1], (r6 & date3).to_s)
53
- end
54
-
55
- kanshi = When.Resource("_co:Residue?divisor=60&year=4&day=11")
56
- date = When.when?("19820606T021540+0900^^Julian")
57
- assert_equal("1982-07-27T02:15:40+09:00", (date & kanshi.to('day')).to_s)
58
- assert_equal("1985-06-06T02:15:40+09:00", (date & kanshi.to('year')[1]).to_s)
59
-
60
- week = When.Resource("_co:Residue?divisor=7")
61
- [[0, "1982-06-08T02:15:40+09:00"],
62
- [1, "1982-06-09T02:15:40+09:00"],
63
- [2, "1982-06-10T02:15:40+09:00"],
64
- [3, "1982-06-11T02:15:40+09:00"],
65
- [4, "1982-06-12T02:15:40+09:00"],
66
- [5, "1982-06-06T02:15:40+09:00"],
67
- [6, "1982-06-07T02:15:40+09:00"],
68
- [7, "1982-06-15T02:15:40+09:00"]].each do |sample|
69
- assert_equal(sample[1], (date & week[sample[0]]).to_s)
70
- end
71
- end
72
-
73
- class BestRationalApproximations < Test::Unit::TestCase
74
- def test__continued_fraction
75
- it = When.Resource("_co:Residue?remainder=365.2421875&divisor=1").each
76
- [[365, 1], [1461, 4], [10592, 29], [12053, 33], [46751, 128]].each do |ratio|
77
- assert_equal(ratio, it.next[0..1])
78
- end
79
- end
80
- end
81
-
82
- class Enumerator < Test::Unit::TestCase
83
- def test_nothing
84
- end
85
- end
86
- end
87
-
88
- # 暦座標番号
89
- class Index < Test::Unit::TestCase
90
- def test__trunk
91
- month = When::Coordinates::Index.new({:label=>'month', :unit=>12, :base=>1,
92
- :trunk => %w(January February March April May June July August September October November December).map {|v| When.m17n(v)}})
93
- assert_equal({
94
- 1=>"January",
95
- 2=>"February",
96
- 3=>"March",
97
- 4=>"April",
98
- 5=>"May",
99
- 6=>"June",
100
- 7=>"July",
101
- 8=>"August",
102
- 9=>"September",
103
- 10=>"October",
104
- 11=>"November",
105
- 12=>"December"
106
- }, month.trunk)
107
- end
108
- end
109
-
110
- # 暦座標要素
111
- class Pair < Test::Unit::TestCase
112
- def test_nothing
113
- end
114
- end
115
-
116
- class Temporal < Test::Unit::TestCase
117
- def test__validate
118
-
119
- midJulian = When.Resource("_c:Julian?border=[0,3,25]")
120
- # assert_equal([0, 3, 25], midJulian.border)
121
-
122
- mDate = When.when?('20100324', {:frame=>midJulian})
123
- assert_equal("2009=03-24", mDate.to_s)
124
-
125
- assert_equal("2010-05-11", When.when?('2010-05-11').to_s)
126
- assert_equal("2010=05-11", When.when?('2010=05-11').to_s)
127
-
128
- date1 =When.when?("M32.01.01")
129
- date2 =When.when?("M34.05.05")
130
- assert_equal("M34(1901).05.05", date2.to_s)
131
- assert_equal("M35(1902).05.05", (date2+When::Duration('P1Y')).to_s)
132
- assert_equal("S06(1931).05.05", (date2+When::Duration('P30Y')).to_s)
133
-
134
- assert_equal(2426467, (date2+When::Duration('P30Y')).to_i)
135
- sample = [
136
- ["ModernJapanese64(1931).05.05", false],
137
- ["S06(1931).05.05", true]
138
- ]
139
- ((date2+When::Duration('P30Y')).scan(When.Resource('ModernJapanese', '_e:'))).each do |d|
140
- assert_equal(sample.shift, [d.to_s, d.leaf?])
141
- end
142
-
143
- sample = [
144
- ["S06(1931).05.05", true]
145
- ]
146
- ((date2+When::Duration('P30Y'))^When.Resource('ModernJapanese', '_e:')).each do |d|
147
- assert_equal(sample.shift, [d.to_s, d.leaf?])
148
- end
149
-
150
- sample =[
151
- ["明治", "http://ja.wikipedia.org/wiki/%E6%98%8E%E6%B2%BB"],
152
- ["Meiji", "http://en.wikipedia.org/wiki/Meiji_period"],
153
- ["M", "http://ja.wikipedia.org/wiki/%E6%98%8E%E6%B2%BB"],
154
- ["大正", "http://ja.wikipedia.org/wiki/%E5%A4%A7%E6%AD%A3"],
155
- ["Taishō", "http://en.wikipedia.org/wiki/Taish%C5%8D_period"],
156
- ["T", "http://ja.wikipedia.org/wiki/%E5%A4%A7%E6%AD%A3"],
157
- ["昭和", "http://ja.wikipedia.org/wiki/%E6%98%AD%E5%92%8C"],
158
- ["Shōwa", "http://en.wikipedia.org/wiki/Sh%C5%8Dwa_period"],
159
- ["S", "http://ja.wikipedia.org/wiki/%E6%98%AD%E5%92%8C"],
160
- ["平成", "http://ja.wikipedia.org/wiki/%E5%B9%B3%E6%88%90"],
161
- ["Heisei", "http://en.wikipedia.org/wiki/Heisei_period"],
162
- ["H", "http://ja.wikipedia.org/wiki/%E5%B9%B3%E6%88%90"]
163
- ]
164
- ['明治', '大正', '昭和', '平成'].each do |nengo|
165
- era = When::era(nengo)
166
- ['ja', 'en', 'alias'].each do |lang|
167
- assert_equal(sample.shift, [era[0].label.translate(lang), era[0].label.reference(lang)])
168
- end
169
- end
170
-
171
- sample =[
172
- ["明治天皇", "http://ja.wikipedia.org/wiki/%E6%98%8E%E6%B2%BB%E5%A4%A9%E7%9A%87"],
173
- ["Emperor_Meiji", "http://en.wikipedia.org/wiki/Emperor_Meiji"],
174
- ["大正天皇", "http://ja.wikipedia.org/wiki/%E5%A4%A7%E6%AD%A3%E5%A4%A9%E7%9A%87"],
175
- ["Emperor_Taishō", "http://en.wikipedia.org/wiki/Emperor_Taish%C5%8D"],
176
- ["昭和天皇", "http://ja.wikipedia.org/wiki/%E6%98%AD%E5%92%8C%E5%A4%A9%E7%9A%87"],
177
- ["Emperor_Shōwa", "http://en.wikipedia.org/wiki/Emperor_Sh%C5%8Dwa"],
178
- ["今上天皇", "http://ja.wikipedia.org/wiki/%E6%98%8E%E4%BB%81"],
179
- ["Emperor_Kinjō", "http://en.wikipedia.org/wiki/Akihito"]
180
- ]
181
- ['明治', '大正', '昭和', '平成'].each do |nengo|
182
- name = When.when?(nengo + '06.01.01').query['name']
183
- ['ja', 'en'].each do |lang|
184
- assert_equal(sample.shift, [name.translate(lang), name.reference(lang)])
185
- end
186
- end
187
-
188
- assert_equal("昭和02(1927).03.01", When.when?('大正16.2.29').to_s)
189
- assert_equal({"name"=>"大正天皇", "period"=>nil, "area"=>"日本"}, When::era('大正')[0].options)
190
- end
191
- end
192
-
193
- #
194
- # 空間位置
195
- #
196
- class Spatial < Test::Unit::TestCase
197
- Indian = [
198
- ["CentralIndia",
199
- "インド中部",
200
- "http://en.wikipedia.org/wiki/CentralIndia",
201
- 23.15 + 1.0/30,
202
- 82.5],
203
- ["NorthIndia",
204
- "インド北部",
205
- "http://en.wikipedia.org/wiki/NorthIndia",
206
- 29.0,
207
- 82.5],
208
- ["Agra",
209
- "アーグラ",
210
- "http://en.wikipedia.org/wiki/Agra",
211
- 27.2,
212
- 78.0],
213
- ["Ahmedabad",
214
- "アフマダーバード",
215
- "http://en.wikipedia.org/wiki/Ahmedabad",
216
- 23.0,
217
- 72.6],
218
- ["Ajmer",
219
- "アジメール",
220
- "http://en.wikipedia.org/wiki/Ajmer",
221
- 26.5,
222
- 74.6],
223
- ["Aligarh",
224
- "アリーガル",
225
- "http://en.wikipedia.org/wiki/Aligarh",
226
- 27.9,
227
- 78.1],
228
- ["Amritsar",
229
- "アムリトサル",
230
- "http://en.wikipedia.org/wiki/Amritsar",
231
- 31.6,
232
- 74.9],
233
- ["Bangalore",
234
- "バンガロール",
235
- "http://en.wikipedia.org/wiki/Bangalore",
236
- 13.0,
237
- 77.6],
238
- ["Bhuvaneswar",
239
- "ブヴァネーシュヴァル",
240
- "http://en.wikipedia.org/wiki/Bhuvaneswar",
241
- 20.2,
242
- 85.8],
243
- ["Chennai",
244
- "チェンナイ",
245
- "http://en.wikipedia.org/wiki/Chennai",
246
- 13.1,
247
- 80.3],
248
- ["Colombo",
249
- "コロンボ",
250
- "http://en.wikipedia.org/wiki/Colombo",
251
- 6.9,
252
- 79.9],
253
- ["Dacca",
254
- "ダッカ",
255
- "http://en.wikipedia.org/wiki/Dacca",
256
- 23.7,
257
- 90.4],
258
- ["Delhi",
259
- "デリー",
260
- "http://en.wikipedia.org/wiki/Delhi",
261
- 28.6,
262
- 77.2],
263
- ["Hyderabad",
264
- "ハイデラバード",
265
- "http://en.wikipedia.org/wiki/Hyderabad",
266
- 17.4,
267
- 78.5],
268
- ["Jaipur",
269
- "ジャイプル",
270
- "http://en.wikipedia.org/wiki/Jaipur",
271
- 26.9,
272
- 75.8],
273
- ["Kathmandu",
274
- "カトマンズ",
275
- "http://en.wikipedia.org/wiki/Kathmandu",
276
- 27.7,
277
- 85.2],
278
- ["Kochi",
279
- "コーチ",
280
- "http://en.wikipedia.org/wiki/Kochi",
281
- 10.0,
282
- 76.2],
283
- ["Kolkata",
284
- "コルカタ",
285
- "http://en.wikipedia.org/wiki/Kolkata",
286
- 22.6,
287
- 88.4],
288
- ["Lahor",
289
- "ラホール",
290
- "http://en.wikipedia.org/wiki/Lahor",
291
- 31.6,
292
- 74.3],
293
- ["Mathura",
294
- "マトゥラー",
295
- "http://en.wikipedia.org/wiki/Mathura",
296
- 27.5,
297
- 77.7],
298
- ["Mumbai",
299
- "ムンバイ",
300
- "http://en.wikipedia.org/wiki/Mumbai",
301
- 19.0,
302
- 72.8],
303
- ["Mysore",
304
- "マイソール",
305
- "http://en.wikipedia.org/wiki/Mysore",
306
- 12.3,
307
- 76.6],
308
- ["Patna",
309
- "パトナ",
310
- "http://en.wikipedia.org/wiki/Patna",
311
- 25.6,
312
- 85.1],
313
- ["Pune",
314
- "プネー",
315
- "http://en.wikipedia.org/wiki/Pune",
316
- 18.5,
317
- 73.9],
318
- ["Srinagar",
319
- "シュリーナガル",
320
- "http://en.wikipedia.org/wiki/Srinagar",
321
- 34.1,
322
- 74.8],
323
- ["Thiruvananthapuram",
324
- "ティルヴァナンタプラム",
325
- "http://en.wikipedia.org/wiki/Thiruvananthapuram",
326
- 8.5,
327
- 77.0],
328
- ["Varanasi",
329
- "ワーラーナシー",
330
- "http://en.wikipedia.org/wiki/Varanasi",
331
- 25.3,
332
- 83.0],
333
- ["Ujjain",
334
- "ウッジャイン",
335
- "http://en.wikipedia.org/wiki/Ujjain",
336
- 23.2,
337
- 75.8]
338
- ]
339
-
340
- def test__inner_representation
341
- location = When.Resource("examples/sample.xml?lat=35&long=135")
342
- assert_equal( 7875.0, location.lat)
343
- assert_equal(30375.0, location.long)
344
- assert_equal( '35.0000N', location.lat_s)
345
- assert_equal('135.0000E', location.long_s)
346
- if Object.const_defined?(:JSON)
347
- location = When.Resource("examples/sample.json?lat=40")
348
- assert_equal( 9000.0, location.lat)
349
- assert_equal(31433.32625, location.long)
350
- assert_equal( '40.0000N', location.lat_s)
351
- assert_equal('139.421322E',location.long_s)
352
- else
353
- puts "\nTests for JSON have been skipped at line #{__LINE__} of #{__FILE__.split(/\//)[-1]}.\n"
354
- end
355
- end
356
-
357
- def test__reference
358
- location = When.Resource("_co:Spatial?label=Kyoto&long=136&lat=30&ref=(http://)")
359
- assert_equal("http://", location.ref)
360
- end
361
-
362
- def test__surface_radius
363
- location = When.Resource("_co:Spatial?label=Kyoto&long=136&lat=30&ref=(http://)")
364
- assert_equal(6378.14, location.surface_radius)
365
- end
366
-
367
- def test__spatial_m17n
368
- ['_co:Indian', 'examples/Spatial.m17n'].each do |iri|
369
- samples = Indian.dup
370
- assert_equal(samples.size, When.Resource(iri).child.size)
371
- When.Resource(iri).child.each do |obj|
372
- name = obj.label
373
- sample = samples.shift.dup
374
- sample << iri.sub(/_co:/, 'http://hosi.org/When/Coordinates/') + '::' + sample[0]
375
- assert_equal(sample,
376
- [name.label,
377
- name.translate('ja'),
378
- name.reference('en'),
379
- obj.lat / When::Coordinates::Spatial::DEGREE,
380
- obj.long / When::Coordinates::Spatial::DEGREE,
381
- obj.iri])
382
- end
383
- end
384
- end
385
-
386
- def test__to_dms
387
- assert_equal(+135.9, When::Coordinates.to_deg("東経135度54分", 'EW'))
388
- assert_equal(+135.9, When::Coordinates.to_deg("135度54分E", 'EW'))
389
- assert_equal(+135.9, When::Coordinates.to_deg("135.5400E", 'EW'))
390
- assert_equal(+135.9, When::Coordinates.to_deg("E135.5400", 'EW'))
391
- assert_equal("135.5400E", When::Coordinates.to_dms(+135.9, 'EW'))
392
- assert_equal( "35.3936N", When::Coordinates.to_dms(+35.66, 'NS'))
393
- end
394
- end
395
- end
396
-
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::Coordinates
10
+
11
+ #
12
+ # 剰余類
13
+ #
14
+ class Residue < MiniTest::TestCase
15
+
16
+ def test__intersection
17
+ r1 = When::Coordinates::Residue.new(3,10)
18
+ r2 = When::Coordinates::Residue.new(5,12)
19
+ r3 = When::Coordinates::Residue.new(6,12)
20
+ r = r1 & r2
21
+ assert_equal([53,60], [r.remainder, r.divisor])
22
+ assert_nil(r1 & r3)
23
+
24
+ r4 = When::Coordinates::Residue.new(2,7)
25
+ date1 = When.when?(2440587.5)
26
+ assert_equal(2440593.5, (date1 & r4).to_f)
27
+
28
+ r5 = When::Coordinates::Residue.new(3,7)
29
+ date2 = When.when?("19820606^^Julian")
30
+ assert_equal("1982-06-11", (date2 & r5).to_s)
31
+ assert_equal("1982-06-11", (r5 & date2).to_s)
32
+
33
+ assert_equal("1982-06-10T00:00:00.00Z", (r5 & Time.utc(1982,6,6)).to_s)
34
+ if ::Object.const_defined?(:Date) && Date.respond_to?(:civil)
35
+ assert_equal("1982-06-24", (r5 & Date.new(1982,6,6,Date::JULIAN)).to_s)
36
+ end
37
+
38
+ date3 = When.when?("19820606T021540+0900^^Julian")
39
+ [[-5, "1979-06-06T02:15:40+09:00"],
40
+ [-4, "1980-06-06T02:15:40+09:00"],
41
+ [-3, "1981-06-06T02:15:40+09:00"],
42
+ [-2, "1922-06-06T02:15:40+09:00"],
43
+ [-1, "1923-06-06T02:15:40+09:00"],
44
+ [ 0, "1984-06-06T02:15:40+09:00"],
45
+ [ 1, "1985-06-06T02:15:40+09:00"],
46
+ [ 2, "1986-06-06T02:15:40+09:00"],
47
+ [ 3, "1987-06-06T02:15:40+09:00"],
48
+ [ 4, "1988-06-06T02:15:40+09:00"],
49
+ [ 5, "1989-06-06T02:15:40+09:00"]].each do |sample|
50
+ r6 = When::Coordinates::Residue.new(sample[0], 60, {'year'=>4})
51
+ assert_equal(sample[1], (date3 & r6).to_s)
52
+ assert_equal(sample[1], (r6 & date3).to_s)
53
+ end
54
+
55
+ kanshi = When.Resource("_co:Residue?divisor=60&year=4&day=11")
56
+ date = When.when?("19820606T021540+0900^^Julian")
57
+ assert_equal("1982-07-27T02:15:40+09:00", (date & kanshi.to('day')).to_s)
58
+ assert_equal("1985-06-06T02:15:40+09:00", (date & kanshi.to('year')[1]).to_s)
59
+
60
+ week = When.Resource("_co:Residue?divisor=7")
61
+ [[0, "1982-06-08T02:15:40+09:00"],
62
+ [1, "1982-06-09T02:15:40+09:00"],
63
+ [2, "1982-06-10T02:15:40+09:00"],
64
+ [3, "1982-06-11T02:15:40+09:00"],
65
+ [4, "1982-06-12T02:15:40+09:00"],
66
+ [5, "1982-06-06T02:15:40+09:00"],
67
+ [6, "1982-06-07T02:15:40+09:00"],
68
+ [7, "1982-06-15T02:15:40+09:00"]].each do |sample|
69
+ assert_equal(sample[1], (date & week[sample[0]]).to_s)
70
+ end
71
+ end
72
+
73
+ class BestRationalApproximations < MiniTest::TestCase
74
+ def test__continued_fraction
75
+ it = When.Resource("_co:Residue?remainder=365.2421875&divisor=1").each
76
+ [[365, 1], [1461, 4], [10592, 29], [12053, 33], [46751, 128]].each do |ratio|
77
+ assert_equal(ratio, it.next[0..1])
78
+ end
79
+ end
80
+ end
81
+
82
+ class Enumerator < MiniTest::TestCase
83
+ def test_nothing
84
+ end
85
+ end
86
+ end
87
+
88
+ # 暦座標番号
89
+ class Index < MiniTest::TestCase
90
+ def test__trunk
91
+ month = When::Coordinates::Index.new({:label=>'month', :unit=>12, :base=>1,
92
+ :trunk => %w(January February March April May June July August September October November December).map {|v| When.m17n(v)}})
93
+ assert_equal({
94
+ 1=>"January",
95
+ 2=>"February",
96
+ 3=>"March",
97
+ 4=>"April",
98
+ 5=>"May",
99
+ 6=>"June",
100
+ 7=>"July",
101
+ 8=>"August",
102
+ 9=>"September",
103
+ 10=>"October",
104
+ 11=>"November",
105
+ 12=>"December"
106
+ }, month.trunk)
107
+ end
108
+ end
109
+
110
+ # 暦座標要素
111
+ class Pair < MiniTest::TestCase
112
+ def test_nothing
113
+ end
114
+ end
115
+
116
+ class Temporal < MiniTest::TestCase
117
+ def test__validate
118
+
119
+ midJulian = When.Resource("_c:Julian?border=[0,3,25]")
120
+ # assert_equal([0, 3, 25], midJulian.border)
121
+
122
+ mDate = When.when?('20100324', {:frame=>midJulian})
123
+ assert_equal("2009=03-24", mDate.to_s)
124
+
125
+ assert_equal("2010-05-11", When.when?('2010-05-11').to_s)
126
+ assert_equal("2010=05-11", When.when?('2010=05-11').to_s)
127
+
128
+ date1 =When.when?("M32.01.01")
129
+ date2 =When.when?("M34.05.05")
130
+ assert_equal("M34(1901).05.05", date2.to_s)
131
+ assert_equal("M35(1902).05.05", (date2+When::Duration('P1Y')).to_s)
132
+ assert_equal("S06(1931).05.05", (date2+When::Duration('P30Y')).to_s)
133
+
134
+ assert_equal(2426467, (date2+When::Duration('P30Y')).to_i)
135
+ sample = [
136
+ ["ModernJapanese1931.05.05", false],
137
+ ["S06(1931).05.05", true]
138
+ ]
139
+ ((date2+When::Duration('P30Y')).scan(When.Resource('ModernJapanese', '_e:'))).each do |d|
140
+ assert_equal(sample.shift, [d.to_s, d.leaf?])
141
+ end
142
+
143
+ sample = [
144
+ ["S06(1931).05.05", true]
145
+ ]
146
+ ((date2+When::Duration('P30Y'))^When.Resource('ModernJapanese', '_e:')).each do |d|
147
+ assert_equal(sample.shift, [d.to_s, d.leaf?])
148
+ end
149
+
150
+ sample =[
151
+ ["明治", "http://ja.wikipedia.org/wiki/%E6%98%8E%E6%B2%BB"],
152
+ ["Meiji", "http://en.wikipedia.org/wiki/Meiji_period"],
153
+ ["M", "http://ja.wikipedia.org/wiki/%E6%98%8E%E6%B2%BB"],
154
+ ["大正", "http://ja.wikipedia.org/wiki/%E5%A4%A7%E6%AD%A3"],
155
+ ["Taishō", "http://en.wikipedia.org/wiki/Taish%C5%8D_period"],
156
+ ["T", "http://ja.wikipedia.org/wiki/%E5%A4%A7%E6%AD%A3"],
157
+ ["昭和", "http://ja.wikipedia.org/wiki/%E6%98%AD%E5%92%8C"],
158
+ ["Shōwa", "http://en.wikipedia.org/wiki/Sh%C5%8Dwa_period"],
159
+ ["S", "http://ja.wikipedia.org/wiki/%E6%98%AD%E5%92%8C"],
160
+ ["平成", "http://ja.wikipedia.org/wiki/%E5%B9%B3%E6%88%90"],
161
+ ["Heisei", "http://en.wikipedia.org/wiki/Heisei_period"],
162
+ ["H", "http://ja.wikipedia.org/wiki/%E5%B9%B3%E6%88%90"]
163
+ ]
164
+ ['明治', '大正', '昭和', '平成'].each do |nengo|
165
+ era = When::era(nengo)
166
+ ['ja', 'en', 'alias'].each do |lang|
167
+ assert_equal(sample.shift, [era[0].label.translate(lang), era[0].label.reference(lang)])
168
+ end
169
+ end
170
+
171
+ sample =[
172
+ ["明治天皇", "http://ja.wikipedia.org/wiki/%E6%98%8E%E6%B2%BB%E5%A4%A9%E7%9A%87"],
173
+ ["Emperor_Meiji", "http://en.wikipedia.org/wiki/Emperor_Meiji"],
174
+ ["大正天皇", "http://ja.wikipedia.org/wiki/%E5%A4%A7%E6%AD%A3%E5%A4%A9%E7%9A%87"],
175
+ ["Emperor_Taishō", "http://en.wikipedia.org/wiki/Emperor_Taish%C5%8D"],
176
+ ["昭和天皇", "http://ja.wikipedia.org/wiki/%E6%98%AD%E5%92%8C%E5%A4%A9%E7%9A%87"],
177
+ ["Emperor_Shōwa", "http://en.wikipedia.org/wiki/Emperor_Sh%C5%8Dwa"],
178
+ ["今上天皇", "http://ja.wikipedia.org/wiki/%E6%98%8E%E4%BB%81"],
179
+ ["Emperor_Kinjō", "http://en.wikipedia.org/wiki/Akihito"]
180
+ ]
181
+ ['明治', '大正', '昭和', '平成'].each do |nengo|
182
+ name = When.when?(nengo + '06.01.01').query['name']
183
+ ['ja', 'en'].each do |lang|
184
+ assert_equal(sample.shift, [name.translate(lang), name.reference(lang)])
185
+ end
186
+ end
187
+
188
+ assert_equal("昭和02(1927).03.01", When.when?('大正16.2.29').to_s)
189
+ assert_equal({"name"=>"大正天皇", "period"=>nil, "area"=>"日本"}, When::era('大正')[0].options)
190
+ end
191
+ end
192
+
193
+ #
194
+ # 空間位置
195
+ #
196
+ class Spatial < MiniTest::TestCase
197
+ Indian = [
198
+ ["CentralIndia",
199
+ "インド中部",
200
+ "http://en.wikipedia.org/wiki/CentralIndia",
201
+ 23.15 + 1.0/30,
202
+ 82.5],
203
+ ["NorthIndia",
204
+ "インド北部",
205
+ "http://en.wikipedia.org/wiki/NorthIndia",
206
+ 29.0,
207
+ 82.5],
208
+ ["Agra",
209
+ "アーグラ",
210
+ "http://en.wikipedia.org/wiki/Agra",
211
+ 27.2,
212
+ 78.0],
213
+ ["Ahmedabad",
214
+ "アフマダーバード",
215
+ "http://en.wikipedia.org/wiki/Ahmedabad",
216
+ 23.0,
217
+ 72.6],
218
+ ["Ajmer",
219
+ "アジメール",
220
+ "http://en.wikipedia.org/wiki/Ajmer",
221
+ 26.5,
222
+ 74.6],
223
+ ["Aligarh",
224
+ "アリーガル",
225
+ "http://en.wikipedia.org/wiki/Aligarh",
226
+ 27.9,
227
+ 78.1],
228
+ ["Amritsar",
229
+ "アムリトサル",
230
+ "http://en.wikipedia.org/wiki/Amritsar",
231
+ 31.6,
232
+ 74.9],
233
+ ["Bangalore",
234
+ "バンガロール",
235
+ "http://en.wikipedia.org/wiki/Bangalore",
236
+ 13.0,
237
+ 77.6],
238
+ ["Bhuvaneswar",
239
+ "ブヴァネーシュヴァル",
240
+ "http://en.wikipedia.org/wiki/Bhuvaneswar",
241
+ 20.2,
242
+ 85.8],
243
+ ["Chennai",
244
+ "チェンナイ",
245
+ "http://en.wikipedia.org/wiki/Chennai",
246
+ 13.1,
247
+ 80.3],
248
+ ["Colombo",
249
+ "コロンボ",
250
+ "http://en.wikipedia.org/wiki/Colombo",
251
+ 6.9,
252
+ 79.9],
253
+ ["Dacca",
254
+ "ダッカ",
255
+ "http://en.wikipedia.org/wiki/Dacca",
256
+ 23.7,
257
+ 90.4],
258
+ ["Delhi",
259
+ "デリー",
260
+ "http://en.wikipedia.org/wiki/Delhi",
261
+ 28.6,
262
+ 77.2],
263
+ ["Hyderabad",
264
+ "ハイデラバード",
265
+ "http://en.wikipedia.org/wiki/Hyderabad",
266
+ 17.4,
267
+ 78.5],
268
+ ["Jaipur",
269
+ "ジャイプル",
270
+ "http://en.wikipedia.org/wiki/Jaipur",
271
+ 26.9,
272
+ 75.8],
273
+ ["Kathmandu",
274
+ "カトマンズ",
275
+ "http://en.wikipedia.org/wiki/Kathmandu",
276
+ 27.7,
277
+ 85.2],
278
+ ["Kochi",
279
+ "コーチ",
280
+ "http://en.wikipedia.org/wiki/Kochi",
281
+ 10.0,
282
+ 76.2],
283
+ ["Kolkata",
284
+ "コルカタ",
285
+ "http://en.wikipedia.org/wiki/Kolkata",
286
+ 22.6,
287
+ 88.4],
288
+ ["Lahor",
289
+ "ラホール",
290
+ "http://en.wikipedia.org/wiki/Lahor",
291
+ 31.6,
292
+ 74.3],
293
+ ["Mathura",
294
+ "マトゥラー",
295
+ "http://en.wikipedia.org/wiki/Mathura",
296
+ 27.5,
297
+ 77.7],
298
+ ["Mumbai",
299
+ "ムンバイ",
300
+ "http://en.wikipedia.org/wiki/Mumbai",
301
+ 19.0,
302
+ 72.8],
303
+ ["Mysore",
304
+ "マイソール",
305
+ "http://en.wikipedia.org/wiki/Mysore",
306
+ 12.3,
307
+ 76.6],
308
+ ["Patna",
309
+ "パトナ",
310
+ "http://en.wikipedia.org/wiki/Patna",
311
+ 25.6,
312
+ 85.1],
313
+ ["Pune",
314
+ "プネー",
315
+ "http://en.wikipedia.org/wiki/Pune",
316
+ 18.5,
317
+ 73.9],
318
+ ["Srinagar",
319
+ "シュリーナガル",
320
+ "http://en.wikipedia.org/wiki/Srinagar",
321
+ 34.1,
322
+ 74.8],
323
+ ["Thiruvananthapuram",
324
+ "ティルヴァナンタプラム",
325
+ "http://en.wikipedia.org/wiki/Thiruvananthapuram",
326
+ 8.5,
327
+ 77.0],
328
+ ["Varanasi",
329
+ "ワーラーナシー",
330
+ "http://en.wikipedia.org/wiki/Varanasi",
331
+ 25.3,
332
+ 83.0],
333
+ ["Ujjain",
334
+ "ウッジャイン",
335
+ "http://en.wikipedia.org/wiki/Ujjain",
336
+ 23.2,
337
+ 75.8]
338
+ ]
339
+
340
+ def test__inner_representation
341
+ location = When.Resource("examples/sample.xml?lat=35&long=135")
342
+ assert_equal( 7875.0, location.lat)
343
+ assert_equal(30375.0, location.long)
344
+ assert_equal( '35.0000N', location.lat_s)
345
+ assert_equal('135.0000E', location.long_s)
346
+ if Object.const_defined?(:JSON)
347
+ location = When.Resource("examples/sample.json?lat=40")
348
+ assert_equal( 9000.0, location.lat)
349
+ assert_equal(31433.32625, location.long)
350
+ assert_equal( '40.0000N', location.lat_s)
351
+ assert_equal('139.421322E',location.long_s)
352
+ else
353
+ puts "\nTests for JSON have been skipped at line #{__LINE__} of #{__FILE__.split(/\//)[-1]}.\n"
354
+ end
355
+ end
356
+
357
+ def test__reference
358
+ location = When.Resource("_co:Spatial?label=Kyoto&long=136&lat=30&ref=(http://)")
359
+ assert_equal("http://", location.ref)
360
+ end
361
+
362
+ def test__surface_radius
363
+ location = When.Resource("_co:Spatial?label=Kyoto&long=136&lat=30&ref=(http://)")
364
+ assert_equal(6378.14, location.surface_radius)
365
+ end
366
+
367
+ def test__spatial_m17n
368
+ ['_co:Indian', 'examples/Spatial.m17n'].each do |iri|
369
+ samples = Indian.dup
370
+ assert_equal(samples.size, When.Resource(iri).child.size)
371
+ When.Resource(iri).child.each do |obj|
372
+ name = obj.label
373
+ sample = samples.shift.dup
374
+ sample << iri.sub(/_co:/, 'http://hosi.org/When/Coordinates/') + '::' + sample[0]
375
+ assert_equal(sample,
376
+ [name.label,
377
+ name.translate('ja'),
378
+ name.reference('en'),
379
+ obj.lat / When::Coordinates::Spatial::DEGREE,
380
+ obj.long / When::Coordinates::Spatial::DEGREE,
381
+ obj.iri])
382
+ end
383
+ end
384
+ end
385
+
386
+ def test__to_dms
387
+ assert_equal(+135.9, When::Coordinates.to_deg("東経135度54分", 'EW'))
388
+ assert_equal(+135.9, When::Coordinates.to_deg("135度54分E", 'EW'))
389
+ assert_equal(+135.9, When::Coordinates.to_deg("135.5400E", 'EW'))
390
+ assert_equal(+135.9, When::Coordinates.to_deg("E135.5400", 'EW'))
391
+ assert_equal("135.5400E", When::Coordinates.to_dms(+135.9, 'EW'))
392
+ assert_equal( "35.3936N", When::Coordinates.to_dms(+35.66, 'NS'))
393
+ end
394
+ end
395
+ end
396
+