when_exe 0.4.2 → 0.5.0

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 (144) hide show
  1. checksums.yaml +5 -5
  2. data/LICENSE.ja.txt +8 -21
  3. data/LICENSE.txt +5 -27
  4. data/README.md +25 -79
  5. data/bin/.pryrc +9 -0
  6. data/bin/make_ttl.rb +3 -2
  7. data/bin/make_ttl.rb.config +3 -3
  8. data/lib/when_exe.rb +101 -5
  9. data/lib/when_exe/basictypes.rb +47 -16
  10. data/lib/when_exe/calendarnote.rb +27 -18
  11. data/lib/when_exe/calendartypes.rb +12 -50
  12. data/lib/when_exe/coordinates.rb +37 -391
  13. data/lib/when_exe/ephemeris.rb +53 -14
  14. data/lib/when_exe/ephemeris/eclipse.rb +8 -8
  15. data/lib/when_exe/ephemeris/moon.rb +333 -333
  16. data/lib/when_exe/ephemeris/notes.rb +29 -17
  17. data/lib/when_exe/ephemeris/phase_table.rb +825 -0
  18. data/lib/when_exe/ephemeris/term_table.rb +603 -0
  19. data/lib/when_exe/events.rb +1888 -0
  20. data/lib/when_exe/google_api.rb +26 -31
  21. data/lib/when_exe/icalendar.rb +129 -12
  22. data/lib/when_exe/inspect.rb +5 -5
  23. data/lib/when_exe/linkeddata.rb +43 -23
  24. data/lib/when_exe/locales/akt.rb +63 -0
  25. data/lib/when_exe/locales/encoding_conversion.rb +134 -134
  26. data/lib/when_exe/locales/iast.rb +90 -90
  27. data/lib/when_exe/locales/locale.rb +88 -18
  28. data/lib/when_exe/locales/transliteration_table.rb +62 -62
  29. data/lib/when_exe/mini_application.rb +14 -8
  30. data/lib/when_exe/namespace.rb +42 -0
  31. data/lib/when_exe/parts/enumerator.rb +16 -5
  32. data/lib/when_exe/parts/geometric_complex.rb +52 -2
  33. data/lib/when_exe/parts/method_cash.rb +229 -224
  34. data/lib/when_exe/parts/resource.rb +65 -35
  35. data/lib/when_exe/parts/timezone.rb +25 -34
  36. data/lib/when_exe/region/balinese.rb +5 -3
  37. data/lib/when_exe/region/chinese.rb +39 -11
  38. data/lib/when_exe/region/chinese/calendars.rb +1016 -1016
  39. data/lib/when_exe/region/chinese/epochs.rb +7 -7
  40. data/lib/when_exe/region/chinese/notes.rb +3 -3
  41. data/lib/when_exe/region/chinese/twins.rb +134 -11
  42. data/lib/when_exe/region/dee.rb +4 -4
  43. data/lib/when_exe/region/discordian.rb +1 -1
  44. data/lib/when_exe/region/geologicalage.rb +139 -128
  45. data/lib/when_exe/region/hanke_henry.rb +4 -4
  46. data/lib/when_exe/region/indian.rb +77 -8
  47. data/lib/when_exe/region/international_fixed.rb +3 -3
  48. data/lib/when_exe/region/islamic.rb +1 -1
  49. data/lib/when_exe/region/japanese.rb +12 -8
  50. data/lib/when_exe/region/japanese/calendars.rb +397 -397
  51. data/lib/when_exe/region/japanese/eclipses.rb +1194 -1194
  52. data/lib/when_exe/region/japanese/epochs.rb +8 -4
  53. data/lib/when_exe/region/japanese/location.rb +93 -0
  54. data/lib/when_exe/region/japanese/nihon_shoki.rb +70 -70
  55. data/lib/when_exe/region/japanese/notes.rb +57 -18
  56. data/lib/when_exe/region/japanese/residues.rb +33 -11
  57. data/lib/when_exe/region/japanese/twins.rb +27 -14
  58. data/lib/when_exe/region/japanese/weeks.rb +7 -7
  59. data/lib/when_exe/region/korean.rb +384 -384
  60. data/lib/when_exe/region/location.rb +40 -0
  61. data/lib/when_exe/region/martian.rb +1 -1
  62. data/lib/when_exe/region/mayan.rb +2 -2
  63. data/lib/when_exe/region/roman.rb +2 -2
  64. data/lib/when_exe/region/ryukyu.rb +101 -101
  65. data/lib/when_exe/region/saudi_arabian.rb +57 -0
  66. data/lib/when_exe/region/shire.rb +1 -1
  67. data/lib/when_exe/region/world.rb +3 -3
  68. data/lib/when_exe/region/zoroastrian.rb +1 -1
  69. data/lib/when_exe/spatial.rb +611 -0
  70. data/lib/when_exe/timestandard.rb +9 -7
  71. data/lib/when_exe/tmobjects.rb +34 -2
  72. data/lib/when_exe/tmposition.rb +225 -1322
  73. data/lib/when_exe/tmptypes.rb +1279 -0
  74. data/lib/when_exe/tmreference.rb +42 -7
  75. data/lib/when_exe/version.rb +3 -3
  76. data/test/events/example-datasets +6 -0
  77. data/test/events/history-dataset.csv +22 -0
  78. data/test/events/japanese-holiday-index.csv +28 -0
  79. data/test/events/japanese-holiday.csv +94 -0
  80. data/test/events/japanese-holiday.ttl +948 -0
  81. data/test/events/make_events_ttl.rb +18 -0
  82. data/test/events/mori_wikichoshi.csv +14 -0
  83. data/test/events/ndl_koyomi.csv +220 -0
  84. data/test/events/ndl_koyomi_index.csv +44 -0
  85. data/test/events/primeminister-dataset.csv +19 -0
  86. data/test/events/shogun-dataset.csv +22 -0
  87. data/test/events/test-history-dataset-edge-sparql.csv +26 -0
  88. data/test/events/test-history-dataset-edge.csv +27 -0
  89. data/test/events/test-history-dataset-sparql.csv +22 -0
  90. data/test/events/test-history-dataset.csv +23 -0
  91. data/test/events/test-history-events-edge.ttl +89 -0
  92. data/test/events/test-history-events.csv +6 -0
  93. data/test/examples/JapanHolidays.ics +2 -2
  94. data/test/examples/JapanHolidaysRFC6350.ics +3 -3
  95. data/test/examples/Residue.m17n +2 -2
  96. data/test/examples/Spatial.m17n +3 -3
  97. data/test/examples/Terms.m17n +3 -3
  98. data/test/scripts/8.ext.rb +6 -6
  99. data/test/scripts/8.rb +6 -6
  100. data/test/scripts/geometric_complex.rb +41 -41
  101. data/test/scripts/korea.rb +59 -59
  102. data/test/scripts/thai.rb +36 -36
  103. data/test/test.rb +6 -0
  104. data/test/test/basictypes.rb +431 -431
  105. data/test/test/calendarnote.rb +86 -86
  106. data/test/test/calendartypes.rb +97 -97
  107. data/test/test/coordinates.rb +399 -397
  108. data/test/test/ephemeris.rb +115 -115
  109. data/test/test/ephemeris/moon.rb +14 -14
  110. data/test/test/ephemeris/planets.rb +14 -14
  111. data/test/test/ephemeris/sun.rb +14 -14
  112. data/test/test/events.rb +32 -0
  113. data/test/test/google_api.rb +45 -32
  114. data/test/test/inspect.rb +153 -153
  115. data/test/test/parts.rb +488 -488
  116. data/test/test/region/armenian.rb +20 -20
  117. data/test/test/region/bahai.rb +58 -58
  118. data/test/test/region/balinese.rb +34 -34
  119. data/test/test/region/chinese.rb +229 -229
  120. data/test/test/region/christian.rb +226 -226
  121. data/test/test/region/coptic.rb +27 -27
  122. data/test/test/region/discordian.rb +20 -20
  123. data/test/test/region/french.rb +33 -33
  124. data/test/test/region/geologicalage.rb +17 -17
  125. data/test/test/region/indian.rb +14 -1
  126. data/test/test/region/iran.rb +54 -54
  127. data/test/test/region/islamic.rb +64 -54
  128. data/test/test/region/japanese.rb +281 -261
  129. data/test/test/region/jewish.rb +63 -63
  130. data/test/test/region/m17n.rb +21 -21
  131. data/test/test/region/mayan.rb +17 -16
  132. data/test/test/region/reforms.rb +2 -2
  133. data/test/test/region/residue.rb +7 -7
  134. data/test/test/region/shire.rb +58 -58
  135. data/test/test/region/swedish.rb +45 -45
  136. data/test/test/region/thai.rb +116 -116
  137. data/test/test/region/tibetan.rb +30 -30
  138. data/test/test/region/vietnamese.rb +102 -102
  139. data/test/test/region/zoroastrian.rb +58 -58
  140. data/test/test/timestandard.rb +81 -81
  141. data/test/test/tmobjects.rb +402 -402
  142. data/test/test/tmposition.rb +66 -4
  143. data/test/test/tmreference.rb +157 -157
  144. metadata +36 -93
@@ -1,86 +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 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
+ # -*- coding: utf-8 -*-
2
+ =begin
3
+ Copyright (C) 2014-2020 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_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 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
+ # -*- 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,397 +1,399 @@
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
- nil,
201
- 23.15 + 1.0/30,
202
- 82.5],
203
- ["NorthIndia",
204
- "インド北部",
205
- nil,
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
354
- puts "Tests for JSON have been skipped at line #{__LINE__} of #{__FILE__.split(/\//)[-1]}."
355
- end
356
- end
357
-
358
- def test__reference
359
- location = When.Resource("_co:Spatial?label=Kyoto&long=136&lat=30&ref=(http://)")
360
- assert_equal("http://", location.ref)
361
- end
362
-
363
- def test__surface_radius
364
- location = When.Resource("_co:Spatial?label=Kyoto&long=136&lat=30&ref=(http://)")
365
- assert_equal(6378.14, location.surface_radius)
366
- end
367
-
368
- def test__spatial_m17n
369
- ['_co:Indian', 'examples/Spatial.m17n'].each do |iri|
370
- samples = Indian.dup
371
- assert_equal(samples.size, When.Resource(iri).child.size)
372
- When.Resource(iri).child.each do |obj|
373
- name = obj.label
374
- sample = samples.shift.dup
375
- sample << iri.sub(/_co:/, 'http://hosi.org/When/Coordinates/') + '::' + sample[0]
376
- assert_equal(sample,
377
- [name.label,
378
- name.translate('ja'),
379
- name.reference('en'),
380
- obj.lat / When::Coordinates::Spatial::DEGREE,
381
- obj.long / When::Coordinates::Spatial::DEGREE,
382
- obj.iri])
383
- end
384
- end
385
- end
386
-
387
- def test__to_dms
388
- assert_equal(+135.9, When::Coordinates.to_deg("東経135度54分", 'EW'))
389
- assert_equal(+135.9, When::Coordinates.to_deg("135度54分E", 'EW'))
390
- assert_equal(+135.9, When::Coordinates.to_deg("135.5400E", 'EW'))
391
- assert_equal(+135.9, When::Coordinates.to_deg("E135.5400", 'EW'))
392
- assert_equal("135.5400E", When::Coordinates.to_dms(+135.9, 'EW'))
393
- assert_equal( "35.3936N", When::Coordinates.to_dms(+35.66, 'NS'))
394
- end
395
- end
396
- end
397
-
1
+ # -*- coding: utf-8 -*-
2
+ =begin
3
+ Copyright (C) 2011-2019 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
+ ["明治", "https://ja.wikipedia.org/wiki/%E6%98%8E%E6%B2%BB"],
152
+ ["Meiji", "https://en.wikipedia.org/wiki/Meiji_period"],
153
+ ["M", "https://ja.wikipedia.org/wiki/%E6%98%8E%E6%B2%BB"],
154
+ ["大正", "https://ja.wikipedia.org/wiki/%E5%A4%A7%E6%AD%A3"],
155
+ ["Taishō", "https://en.wikipedia.org/wiki/Taish%C5%8D_period"],
156
+ ["T", "https://ja.wikipedia.org/wiki/%E5%A4%A7%E6%AD%A3"],
157
+ ["昭和", "https://ja.wikipedia.org/wiki/%E6%98%AD%E5%92%8C"],
158
+ ["Shōwa", "https://en.wikipedia.org/wiki/Sh%C5%8Dwa_period"],
159
+ ["S", "https://ja.wikipedia.org/wiki/%E6%98%AD%E5%92%8C"],
160
+ ["平成", "https://ja.wikipedia.org/wiki/%E5%B9%B3%E6%88%90"],
161
+ ["Heisei", "https://en.wikipedia.org/wiki/Heisei_period"],
162
+ ["H", "https://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
+ ["明治天皇", "https://ja.wikipedia.org/wiki/%E6%98%8E%E6%B2%BB%E5%A4%A9%E7%9A%87"],
173
+ ["Emperor_Meiji", "https://en.wikipedia.org/wiki/Emperor_Meiji"],
174
+ ["大正天皇", "https://ja.wikipedia.org/wiki/%E5%A4%A7%E6%AD%A3%E5%A4%A9%E7%9A%87"],
175
+ ["Emperor_Taishō", "https://en.wikipedia.org/wiki/Emperor_Taish%C5%8D"],
176
+ ["昭和天皇", "https://ja.wikipedia.org/wiki/%E6%98%AD%E5%92%8C%E5%A4%A9%E7%9A%87"],
177
+ ["Emperor_Shōwa", "https://en.wikipedia.org/wiki/Emperor_Sh%C5%8Dwa"],
178
+ ["上皇明仁", "https://ja.wikipedia.org/wiki/%E4%B8%8A%E7%9A%87%E6%98%8E%E4%BB%81"],
179
+ ["Emperor_Emeritus_of_Japan", "https://en.wikipedia.org/wiki/Akihito"],
180
+ ["今上天皇", "https://ja.wikipedia.org/wiki/%E5%BE%B3%E4%BB%81"],
181
+ ["Emperor_Kinjō", "https://en.wikipedia.org/wiki/Naruhito"]
182
+ ]
183
+ ['明治', '大正', '昭和', '平成', '令和'].each do |nengo|
184
+ name = When.when?(nengo + '06.01.01').query['name']
185
+ ['ja', 'en'].each do |lang|
186
+ assert_equal(sample.shift, [name.translate(lang), name.reference(lang)])
187
+ end
188
+ end
189
+
190
+ assert_equal("昭和02(1927).03.01", When.when?('大正16.2.29').to_s)
191
+ assert_equal({"name"=>"大正天皇", "period"=>nil, "area"=>"日本"}, When::era('大正')[0].options)
192
+ end
193
+ end
194
+
195
+ #
196
+ # 空間位置
197
+ #
198
+ class Spatial < MiniTest::TestCase
199
+ Indian = [
200
+ ["CentralIndia",
201
+ "インド中部",
202
+ nil,
203
+ 23.15 + 1.0/30,
204
+ 82.5],
205
+ ["NorthIndia",
206
+ "インド北部",
207
+ nil,
208
+ 29.0,
209
+ 82.5],
210
+ ["Agra",
211
+ "アーグラ",
212
+ "https://en.wikipedia.org/wiki/Agra",
213
+ 27.2,
214
+ 78.0],
215
+ ["Ahmedabad",
216
+ "アフマダーバード",
217
+ "https://en.wikipedia.org/wiki/Ahmedabad",
218
+ 23.0,
219
+ 72.6],
220
+ ["Ajmer",
221
+ "アジメール",
222
+ "https://en.wikipedia.org/wiki/Ajmer",
223
+ 26.5,
224
+ 74.6],
225
+ ["Aligarh",
226
+ "アリーガル",
227
+ "https://en.wikipedia.org/wiki/Aligarh",
228
+ 27.9,
229
+ 78.1],
230
+ ["Amritsar",
231
+ "アムリトサル",
232
+ "https://en.wikipedia.org/wiki/Amritsar",
233
+ 31.6,
234
+ 74.9],
235
+ ["Bangalore",
236
+ "バンガロール",
237
+ "https://en.wikipedia.org/wiki/Bangalore",
238
+ 13.0,
239
+ 77.6],
240
+ ["Bhuvaneswar",
241
+ "ブヴァネーシュヴァル",
242
+ "https://en.wikipedia.org/wiki/Bhuvaneswar",
243
+ 20.2,
244
+ 85.8],
245
+ ["Chennai",
246
+ "チェンナイ",
247
+ "https://en.wikipedia.org/wiki/Chennai",
248
+ 13.1,
249
+ 80.3],
250
+ ["Colombo",
251
+ "コロンボ",
252
+ "https://en.wikipedia.org/wiki/Colombo",
253
+ 6.9,
254
+ 79.9],
255
+ ["Dacca",
256
+ "ダッカ",
257
+ "https://en.wikipedia.org/wiki/Dacca",
258
+ 23.7,
259
+ 90.4],
260
+ ["Delhi",
261
+ "デリー",
262
+ "https://en.wikipedia.org/wiki/Delhi",
263
+ 28.6,
264
+ 77.2],
265
+ ["Hyderabad",
266
+ "ハイデラバード",
267
+ "https://en.wikipedia.org/wiki/Hyderabad",
268
+ 17.4,
269
+ 78.5],
270
+ ["Jaipur",
271
+ "ジャイプル",
272
+ "https://en.wikipedia.org/wiki/Jaipur",
273
+ 26.9,
274
+ 75.8],
275
+ ["Kathmandu",
276
+ "カトマンズ",
277
+ "https://en.wikipedia.org/wiki/Kathmandu",
278
+ 27.7,
279
+ 85.2],
280
+ ["Kochi",
281
+ "コーチ",
282
+ "https://en.wikipedia.org/wiki/Kochi",
283
+ 10.0,
284
+ 76.2],
285
+ ["Kolkata",
286
+ "コルカタ",
287
+ "https://en.wikipedia.org/wiki/Kolkata",
288
+ 22.6,
289
+ 88.4],
290
+ ["Lahor",
291
+ "ラホール",
292
+ "https://en.wikipedia.org/wiki/Lahor",
293
+ 31.6,
294
+ 74.3],
295
+ ["Mathura",
296
+ "マトゥラー",
297
+ "https://en.wikipedia.org/wiki/Mathura",
298
+ 27.5,
299
+ 77.7],
300
+ ["Mumbai",
301
+ "ムンバイ",
302
+ "https://en.wikipedia.org/wiki/Mumbai",
303
+ 19.0,
304
+ 72.8],
305
+ ["Mysore",
306
+ "マイソール",
307
+ "https://en.wikipedia.org/wiki/Mysore",
308
+ 12.3,
309
+ 76.6],
310
+ ["Patna",
311
+ "パトナ",
312
+ "https://en.wikipedia.org/wiki/Patna",
313
+ 25.6,
314
+ 85.1],
315
+ ["Pune",
316
+ "プネー",
317
+ "https://en.wikipedia.org/wiki/Pune",
318
+ 18.5,
319
+ 73.9],
320
+ ["Srinagar",
321
+ "シュリーナガル",
322
+ "https://en.wikipedia.org/wiki/Srinagar",
323
+ 34.1,
324
+ 74.8],
325
+ ["Thiruvananthapuram",
326
+ "ティルヴァナンタプラム",
327
+ "https://en.wikipedia.org/wiki/Thiruvananthapuram",
328
+ 8.5,
329
+ 77.0],
330
+ ["Varanasi",
331
+ "ワーラーナシー",
332
+ "https://en.wikipedia.org/wiki/Varanasi",
333
+ 25.3,
334
+ 83.0],
335
+ ["Ujjain",
336
+ "ウッジャイン",
337
+ "https://en.wikipedia.org/wiki/Ujjain",
338
+ 23.2,
339
+ 75.8]
340
+ ]
341
+
342
+ def test__inner_representation
343
+ location = When.Resource("examples/sample.xml?lat=35&long=135")
344
+ assert_equal( 7875.0, location.lat)
345
+ assert_equal(30375.0, location.long)
346
+ assert_equal( '35.0000N', location.lat_s)
347
+ assert_equal('135.0000E', location.long_s)
348
+ if Object.const_defined?(:JSON)
349
+ location = When.Resource("examples/sample.json?lat=40")
350
+ assert_equal( 9000.0, location.lat)
351
+ assert_equal(31433.32625, location.long)
352
+ assert_equal( '40.0000N', location.lat_s)
353
+ assert_equal('139.421322E',location.long_s)
354
+ else
355
+ puts
356
+ puts "Tests for JSON have been skipped at line #{__LINE__} of #{__FILE__.split(/\//)[-1]}."
357
+ end
358
+ end
359
+
360
+ def test__reference
361
+ location = When.Resource("_co:Spatial?label=Kyoto&long=136&lat=30&ref=(http://)")
362
+ assert_equal("http://", location.ref)
363
+ end
364
+
365
+ def test__surface_radius
366
+ location = When.Resource("_co:Spatial?label=Kyoto&long=136&lat=30&ref=(http://)")
367
+ assert_equal(6378.14, location.surface_radius)
368
+ end
369
+
370
+ def test__spatial_m17n
371
+ ['_co:Indian', 'examples/Spatial.m17n'].each do |iri|
372
+ samples = Indian.dup
373
+ assert_equal(samples.size, When.Resource(iri).child.size)
374
+ When.Resource(iri).child.each do |obj|
375
+ name = obj.label
376
+ sample = samples.shift.dup
377
+ sample << iri.sub(/_co:/, 'http://hosi.org/When/Coordinates/') + '::' + sample[0]
378
+ assert_equal(sample,
379
+ [name.label,
380
+ name.translate('ja'),
381
+ name.reference('en'),
382
+ obj.lat / obj.degree,
383
+ obj.long / obj.degree,
384
+ obj.iri])
385
+ end
386
+ end
387
+ end
388
+
389
+ def test__to_dms
390
+ assert_equal(+135.9, When::Coordinates.to_deg("東経135度54分", 'EW'))
391
+ assert_equal(+135.9, When::Coordinates.to_deg("135度54分E", 'EW'))
392
+ assert_equal(+135.9, When::Coordinates.to_deg("135.5400E", 'EW'))
393
+ assert_equal(+135.9, When::Coordinates.to_deg("E135.5400", 'EW'))
394
+ assert_equal("135.5400E", When::Coordinates.to_dms(+135.9, 'EW'))
395
+ assert_equal( "35.3936N", When::Coordinates.to_dms(+35.66, 'NS'))
396
+ end
397
+ end
398
+ end
399
+