when_exe 0.3.4 → 0.3.5

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 (168) hide show
  1. data/bin/locales.rb +2 -2
  2. data/bin/when.rb +2 -2
  3. data/lib/when_exe.rb +161 -55
  4. data/lib/when_exe/basictypes.rb +34 -26
  5. data/lib/when_exe/calendarnote.rb +654 -0
  6. data/lib/when_exe/calendartypes.rb +49 -474
  7. data/lib/when_exe/coordinates.rb +141 -34
  8. data/lib/when_exe/core/compatibility.rb +22 -2
  9. data/lib/when_exe/core/extension.rb +47 -3
  10. data/lib/when_exe/ephemeris.rb +82 -109
  11. data/lib/when_exe/googlecalendar.rb +1 -1
  12. data/lib/when_exe/icalendar.rb +26 -14
  13. data/lib/when_exe/inspect.rb +82 -68
  14. data/lib/when_exe/locales/af.rb +1 -1
  15. data/lib/when_exe/locales/ar.rb +1 -1
  16. data/lib/when_exe/locales/az.rb +1 -1
  17. data/lib/when_exe/locales/bg.rb +1 -1
  18. data/lib/when_exe/locales/bn.rb +1 -1
  19. data/lib/when_exe/locales/bs.rb +1 -1
  20. data/lib/when_exe/locales/ca.rb +1 -1
  21. data/lib/when_exe/locales/cs.rb +1 -1
  22. data/lib/when_exe/locales/cy.rb +1 -1
  23. data/lib/when_exe/locales/da.rb +1 -1
  24. data/lib/when_exe/locales/de.rb +1 -1
  25. data/lib/when_exe/locales/de_AT.rb +1 -1
  26. data/lib/when_exe/locales/de_CH.rb +1 -1
  27. data/lib/when_exe/locales/el.rb +1 -1
  28. data/lib/when_exe/locales/en.rb +1 -1
  29. data/lib/when_exe/locales/en_AU.rb +1 -1
  30. data/lib/when_exe/locales/en_CA.rb +1 -1
  31. data/lib/when_exe/locales/en_GB.rb +1 -1
  32. data/lib/when_exe/locales/en_IE.rb +1 -1
  33. data/lib/when_exe/locales/en_IN.rb +1 -1
  34. data/lib/when_exe/locales/en_NZ.rb +1 -1
  35. data/lib/when_exe/locales/en_US.rb +1 -1
  36. data/lib/when_exe/locales/eo.rb +1 -1
  37. data/lib/when_exe/locales/es.rb +1 -1
  38. data/lib/when_exe/locales/es_419.rb +1 -1
  39. data/lib/when_exe/locales/es_AR.rb +1 -1
  40. data/lib/when_exe/locales/es_CL.rb +1 -1
  41. data/lib/when_exe/locales/es_CO.rb +1 -1
  42. data/lib/when_exe/locales/es_CR.rb +1 -1
  43. data/lib/when_exe/locales/es_EC.rb +1 -1
  44. data/lib/when_exe/locales/es_MX.rb +1 -1
  45. data/lib/when_exe/locales/es_PA.rb +1 -1
  46. data/lib/when_exe/locales/es_PE.rb +1 -1
  47. data/lib/when_exe/locales/es_VE.rb +1 -1
  48. data/lib/when_exe/locales/et.rb +1 -1
  49. data/lib/when_exe/locales/eu.rb +1 -1
  50. data/lib/when_exe/locales/fa.rb +1 -1
  51. data/lib/when_exe/locales/fi.rb +1 -1
  52. data/lib/when_exe/locales/fr.rb +1 -1
  53. data/lib/when_exe/locales/fr_CA.rb +1 -1
  54. data/lib/when_exe/locales/fr_CH.rb +1 -1
  55. data/lib/when_exe/locales/gl.rb +1 -1
  56. data/lib/when_exe/locales/he.rb +1 -1
  57. data/lib/when_exe/locales/hi.rb +1 -1
  58. data/lib/when_exe/locales/hi_IN.rb +1 -1
  59. data/lib/when_exe/locales/hr.rb +1 -1
  60. data/lib/when_exe/locales/hu.rb +1 -1
  61. data/lib/when_exe/locales/id.rb +1 -1
  62. data/lib/when_exe/locales/is.rb +1 -1
  63. data/lib/when_exe/locales/it.rb +1 -1
  64. data/lib/when_exe/locales/it_CH.rb +1 -1
  65. data/lib/when_exe/locales/ja.rb +1 -1
  66. data/lib/when_exe/locales/kn.rb +1 -1
  67. data/lib/when_exe/locales/ko.rb +1 -1
  68. data/lib/when_exe/locales/lo.rb +1 -1
  69. data/lib/when_exe/locales/locales.rb +1 -1
  70. data/lib/when_exe/locales/lt.rb +1 -1
  71. data/lib/when_exe/locales/lv.rb +1 -1
  72. data/lib/when_exe/locales/mk.rb +1 -1
  73. data/lib/when_exe/locales/mn.rb +1 -1
  74. data/lib/when_exe/locales/ms.rb +1 -1
  75. data/lib/when_exe/locales/nb.rb +1 -1
  76. data/lib/when_exe/locales/ne.rb +1 -1
  77. data/lib/when_exe/locales/nl.rb +1 -1
  78. data/lib/when_exe/locales/nn.rb +1 -1
  79. data/lib/when_exe/locales/or.rb +1 -1
  80. data/lib/when_exe/locales/pl.rb +1 -1
  81. data/lib/when_exe/locales/pt.rb +1 -1
  82. data/lib/when_exe/locales/pt_BR.rb +1 -1
  83. data/lib/when_exe/locales/rm.rb +1 -1
  84. data/lib/when_exe/locales/ro.rb +1 -1
  85. data/lib/when_exe/locales/ru.rb +1 -1
  86. data/lib/when_exe/locales/sk.rb +1 -1
  87. data/lib/when_exe/locales/sl.rb +1 -1
  88. data/lib/when_exe/locales/sr.rb +1 -1
  89. data/lib/when_exe/locales/sv.rb +1 -1
  90. data/lib/when_exe/locales/sw.rb +1 -1
  91. data/lib/when_exe/locales/th.rb +1 -1
  92. data/lib/when_exe/locales/tl.rb +1 -1
  93. data/lib/when_exe/locales/tr.rb +1 -1
  94. data/lib/when_exe/locales/uk.rb +1 -1
  95. data/lib/when_exe/locales/ur.rb +1 -1
  96. data/lib/when_exe/locales/uz.rb +1 -1
  97. data/lib/when_exe/locales/vi.rb +1 -1
  98. data/lib/when_exe/locales/wo.rb +1 -1
  99. data/lib/when_exe/locales/zh_CN.rb +1 -1
  100. data/lib/when_exe/locales/zh_HK.rb +1 -1
  101. data/lib/when_exe/locales/zh_TW.rb +1 -1
  102. data/lib/when_exe/mini_application.rb +6 -2
  103. data/lib/when_exe/parts/enumerator.rb +13 -8
  104. data/lib/when_exe/parts/geometric_complex.rb +3 -5
  105. data/lib/when_exe/parts/locale.rb +185 -28
  106. data/lib/when_exe/parts/method_cash.rb +20 -10
  107. data/lib/when_exe/parts/resource.rb +154 -76
  108. data/lib/when_exe/parts/timezone.rb +11 -6
  109. data/lib/when_exe/region/bahai.rb +2 -2
  110. data/lib/when_exe/region/balinese.rb +296 -296
  111. data/lib/when_exe/region/chinese.rb +564 -564
  112. data/lib/when_exe/region/chinese_calendar.rb +5 -1
  113. data/lib/when_exe/region/chinese_epoch.rb +47 -102
  114. data/lib/when_exe/region/chinese_twin.rb +798 -0
  115. data/lib/when_exe/region/christian.rb +314 -338
  116. data/lib/when_exe/region/coptic.rb +88 -0
  117. data/lib/when_exe/region/ephemeric_notes.rb +322 -307
  118. data/lib/when_exe/region/french.rb +2 -2
  119. data/lib/when_exe/region/indian.rb +361 -272
  120. data/lib/when_exe/region/iranian.rb +2 -2
  121. data/lib/when_exe/region/islamic.rb +3 -3
  122. data/lib/when_exe/region/japanese.rb +1 -1
  123. data/lib/when_exe/region/japanese_notes.rb +165 -103
  124. data/lib/when_exe/region/japanese_residues.rb +56 -55
  125. data/lib/when_exe/region/japanese_twin.rb +228 -0
  126. data/lib/when_exe/region/javanese.rb +2 -2
  127. data/lib/when_exe/region/jewish.rb +2 -2
  128. data/lib/when_exe/region/korean.rb +4 -4
  129. data/lib/when_exe/region/m17n.rb +19 -19
  130. data/lib/when_exe/region/martian.rb +21 -9
  131. data/lib/when_exe/region/mayan.rb +19 -11
  132. data/lib/when_exe/region/moon.rb +7 -7
  133. data/lib/when_exe/region/nihon_shoki.rb +7 -7
  134. data/lib/when_exe/region/roman.rb +100 -100
  135. data/lib/when_exe/region/shire.rb +130 -147
  136. data/lib/when_exe/region/thai.rb +2 -2
  137. data/lib/when_exe/region/tibetan.rb +2 -2
  138. data/lib/when_exe/region/vietnamese.rb +383 -114
  139. data/lib/when_exe/region/world.rb +112 -129
  140. data/lib/when_exe/timestandard.rb +12 -1
  141. data/lib/when_exe/tmposition.rb +28 -14
  142. data/lib/when_exe/tmreference.rb +96 -93
  143. data/lib/when_exe/version.rb +1 -1
  144. data/test/examples/Terms.m17n +2 -2
  145. data/test/examples/sample.json +16 -0
  146. data/test/examples/sample.xml +1 -1
  147. data/test/test.rb +4 -0
  148. data/test/test/basictypes.rb +2 -2
  149. data/test/test/calendarnote.rb +69 -0
  150. data/test/test/calendartypes.rb +41 -1
  151. data/test/test/coordinates.rb +12 -1
  152. data/test/test/ephemeris.rb +13 -66
  153. data/test/test/icalendar.rb +3 -3
  154. data/test/test/inspect.rb +1 -1
  155. data/test/test/parts.rb +7 -4
  156. data/test/test/region/chinese.rb +45 -0
  157. data/test/test/region/coptic.rb +27 -0
  158. data/test/test/region/indian.rb +1 -1
  159. data/test/test/region/japanese.rb +4 -4
  160. data/test/test/region/jewish.rb +1 -1
  161. data/test/test/region/m17n.rb +7 -5
  162. data/test/test/region/residue.rb +2 -2
  163. data/test/test/region/vietnamese.rb +102 -0
  164. data/test/test/timestandard.rb +81 -0
  165. data/test/test/tmposition.rb +1 -1
  166. data/test/test/tmreference.rb +1 -1
  167. data/when_exe.gemspec +2 -2
  168. metadata +16 -7
@@ -6,5 +6,5 @@
6
6
  =end
7
7
 
8
8
  module When
9
- VERSION = "0.3.4"
9
+ VERSION = "0.3.5"
10
10
  end
@@ -1,12 +1,12 @@
1
1
  BEGIN:B:M17n
2
- # Copyright (C) 2011 Takashi SUGA
2
+ # Copyright (C) 2011-2014 Takashi SUGA
3
3
  #
4
4
  # You may use and/or modify this file according to the license
5
5
  # described in the LICENSE.txt file included in this archive.
6
6
  NAMESPACE:[en=http://en.wikipedia.org/wiki/,
7
7
  ja=http://ja.wikipedia.org/wiki/]
8
8
  LOCALE:[=en:, ja=ja:, alias]
9
- NAMES:[CalendarTerms]
9
+ NAMES:[CalendarTerms=]
10
10
 
11
11
  [Calendars_and_Eras=, 暦法と紀元=]
12
12
 
@@ -0,0 +1,16 @@
1
+ [{},"When::Coordinates::Spatial",
2
+ {
3
+ "label" :
4
+ {
5
+ "label" : "Tokyo",
6
+ "names" :
7
+ {"" : "Tokyo",
8
+ "ja" : "東京"
9
+ }
10
+ },
11
+ "lat" : "#{lat:35.412011N}",
12
+ "long" : "#{long:139.421322E}",
13
+ "alt" : "#{alt:0}",
14
+ "datum" : "#{datum:JGD2000}"
15
+ }
16
+ ]
@@ -6,7 +6,7 @@
6
6
  xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
7
7
  xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
8
8
  type="http://hosi.org/When/Coordinates/Spatial">
9
- <rdfs:label country='Japan'>Tokyo</rdfs:label>
9
+ <rdfs:label country='Japan'>[Tokyo]</rdfs:label>
10
10
  <geo:lat>N35.412011</geo:lat>
11
11
  <geo:long>E139.421322</geo:long>
12
12
  <geo:alt>0</geo:alt>
data/test/test.rb CHANGED
@@ -33,12 +33,14 @@ require 'when_exe/mini_application'
33
33
  require './test/parts'
34
34
  require './test/basictypes'
35
35
  require './test/ephemeris'
36
+ require './test/timestandard'
36
37
  require './test/coordinates'
37
38
  require './test/icalendar'
38
39
  require './test/tmobjects'
39
40
  require './test/tmreference'
40
41
  require './test/tmposition'
41
42
  require './test/calendartypes'
43
+ require './test/calendarnote'
42
44
  require './test/inspect'
43
45
  require './test/googlecalendar'
44
46
  require './test/region/m17n'
@@ -46,6 +48,7 @@ require './test/region/residue'
46
48
  require './test/region/civil'
47
49
  require './test/region/japanese'
48
50
  require './test/region/chinese'
51
+ require './test/region/vietnamese'
49
52
  require './test/region/tibetan'
50
53
  require './test/region/thai'
51
54
  require './test/region/indian'
@@ -53,4 +56,5 @@ require './test/region/iran'
53
56
  require './test/region/mayan'
54
57
  require './test/region/jewish'
55
58
  require './test/region/french'
59
+ require './test/region/coptic'
56
60
  require './test/region/geologicalage'
@@ -1,6 +1,6 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  =begin
3
- Copyright (C) 2011-2012 Takashi SUGA
3
+ Copyright (C) 2011-2014 Takashi SUGA
4
4
 
5
5
  You may use and/or modify this file according to the license
6
6
  described in the LICENSE.txt file included in this archive.
@@ -362,7 +362,7 @@ LOCALE
362
362
 
363
363
  def test__label
364
364
  assert_equal("Getsuyou", Term2.label.to_s)
365
- assert_equal(When::BasicTypes::M17n, Term2.label.class)
365
+ assert_equal(String, Term2.label.class)
366
366
  assert_equal("Monday", Term3.label.to_s)
367
367
  end
368
368
  end
@@ -0,0 +1,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 Test::CalendarNote
10
+
11
+ class Notes < 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,6 +1,6 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  =begin
3
- Copyright (C) 2011 Takashi SUGA
3
+ Copyright (C) 2011-2014 Takashi SUGA
4
4
 
5
5
  You may use and/or modify this file according to the license
6
6
  described in the LICENSE.txt file included in this archive.
@@ -53,5 +53,45 @@ module Test::CalendarTypes
53
53
  assert_equal([31, 0, 0], frame._number_to_coordinates(1948440+10631))
54
54
  end
55
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
56
96
  end
57
97
 
@@ -341,6 +341,17 @@ module Test::Coordinates
341
341
  location = When.Resource("examples/sample.xml?lat=35&long=135")
342
342
  assert_equal( 7875.0, location.lat)
343
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
344
355
  end
345
356
 
346
357
  def test__reference
@@ -378,7 +389,7 @@ module Test::Coordinates
378
389
  assert_equal(+135.9, When::Coordinates.to_deg("135.5400E", 'EW'))
379
390
  assert_equal(+135.9, When::Coordinates.to_deg("E135.5400", 'EW'))
380
391
  assert_equal("135.5400E", When::Coordinates.to_dms(+135.9, 'EW'))
381
- assert_equal( "35.3935N", When::Coordinates.to_dms(+35.66, 'NS'))
392
+ assert_equal( "35.3936N", When::Coordinates.to_dms(+35.66, 'NS'))
382
393
  end
383
394
  end
384
395
  end
@@ -1,6 +1,6 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  =begin
3
- Copyright (C) 2011-2013 Takashi SUGA
3
+ Copyright (C) 2011-2014 Takashi SUGA
4
4
 
5
5
  You may use and/or modify this file according to the license
6
6
  described in the LICENSE.txt file included in this archive.
@@ -54,74 +54,21 @@ module Test::Ephemeris
54
54
  end
55
55
  end
56
56
 
57
- class UniversalTime < Test::Unit::TestCase
58
- def view(time)
59
- return time unless time.instance_of?(When::Coordinates::LeapSeconds)
60
- return [time.trunk, time.branch, time.second]
61
- end
57
+ class Formula < Test::Unit::TestCase
58
+ def test__sunrise
62
59
 
63
- def test__delta_t
64
- date = When.when?('2009-01-01T00:00:00Z')
65
- assert_equal("2008-12-31T23:59:01Z", (date - When::TM::IntervalLength.new(60, 'second')).to_s)
66
- assert_equal("2008-12-31T23:59:00Z", (date - When::Duration('PT60S')).to_s)
67
-
68
- date = When::TM::JulianDate.dynamical_time((2500000-(When::TM::JulianDate::JD19700101-0.5))*675)
69
- assert_equal(2500000.0, +date)
70
- assert_equal(true, +date > date.to_f)
71
-
72
- date = When::TM::JulianDate.universal_time((2500000-(When::TM::JulianDate::JD19700101-0.5))*675)
73
- assert_equal(2500000.0, date.to_f)
74
- assert_equal(true, +date > date.to_f)
75
-
76
- assert_equal((40 + 377.0/2048), When::TimeStandard.delta_t(When.when?('1970-01-01T').to_f))
77
-
78
- date = When.when?('2008-10-31T23:59:60Z')
79
- assert_equal([[2008, 11, 1], [0, 0, 0, 0]], [date.cal_date, date.clk_time.clk_time])
80
-
81
- pair = When::Coordinates::Pair.new(1,1)
82
- assert_equal([-1, -1, 1], [0.9, 1, 1.1].map {|v| v<=>pair})
83
-
84
- time = When.Resource('_t:UniversalTime')
85
- date0 = When.when?('2008-12-31T23:59:58Z') ^ When.Duration('1s') # Duration('PT1S')
86
- [
87
- "2008-12-31T23:59:58Z",
88
- "2008-12-31T23:59:59Z",
89
- "2008-12-31T23:59:60Z",
90
- "2009-01-01T00:00:00Z",
91
- "2009-01-01T00:00:01Z"
92
- ].each do |sample|
93
- date = date0.next
94
- assert_equal([sample, true], [date.to_s, date.universal_time == time.from_dynamical_time(date.dynamical_time)])
95
- end
60
+ today = '2014-3-4'
96
61
 
97
- it = When::V::Event.new({
98
- 'rrule' => 'FREQ=MINUTELY;BYSECOND=59,60',
99
- 'dtstart' => '2008-12-31T23:58:59Z'
100
- }).each
101
-
102
- [
103
- "2008-12-31T23:58:59Z",
104
- "2008-12-31T23:59:59Z",
105
- "2009-01-01T00:00:59Z",
106
- "2009-01-01T00:01:59Z"
107
- ].each do |sample|
108
- assert_equal(sample, it.next.to_s)
109
- end
62
+ assert_raises(NoMethodError) { When.when?(today).sunrise }
110
63
 
111
- it = When::V::Event.new({
112
- 'rrule' => 'FREQ=1s', #;BYSECOND=59,60',
113
- 'dtstart' => '2008-12-31T23:59:58Z'
114
- }).each
115
-
116
- [
117
- "2008-12-31T23:59:58Z",
118
- "2008-12-31T23:59:59Z",
119
- "2008-12-31T23:59:60Z",
120
- "2009-01-01T00:00:00Z",
121
- "2009-01-01T00:00:01Z"
122
- ].each do |sample|
123
- assert_equal(sample, it.next.to_s)
124
- end
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)
125
72
  end
126
73
  end
127
74
  end
@@ -1,6 +1,6 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  =begin
3
- Copyright (C) 2011-2012 Takashi SUGA
3
+ Copyright (C) 2011-2014 Takashi SUGA
4
4
 
5
5
  You may use and/or modify this file according to the license
6
6
  described in the LICENSE.txt file included in this archive.
@@ -736,7 +736,7 @@ module Test:V
736
736
  "1997-09-03T10:20:00-04:00",
737
737
  "1997-09-03T10:40:00-04:00",
738
738
  ]
739
- event3.enum_for(When.when?('19970902T090000'), :forward, 30).each do |date|
739
+ event3.enum_for(When.when?('19970902T090000'), :forward, {:count_limit=>30}).each do |date|
740
740
  assert_equal(sample.shift, date.to_s)
741
741
  end
742
742
  assert_equal([], sample)
@@ -753,7 +753,7 @@ module Test:V
753
753
  "1997-09-04T10:20:00-04:00",
754
754
  "1997-09-04T10:00:00-04:00",
755
755
  ]
756
- event3.enum_for(When.when?('19970904T170000'), :reverse, 10, {'1st'=>'DontCare'}).each do |date|
756
+ event3.enum_for(When.when?('19970904T170000'), {:direction=>:reverse, :count_limit=>10, '1st'=>'DontCare'}).each do |date|
757
757
  assert_equal(sample.shift, date.to_s)
758
758
  end
759
759
  assert_equal([], sample)
data/test/test/inspect.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  =begin
3
- Copyright (C) 2011-2013 Takashi SUGA
3
+ Copyright (C) 2011-2014 Takashi SUGA
4
4
 
5
5
  You may use and/or modify this file according to the license
6
6
  described in the LICENSE.txt file included in this archive.
data/test/test/parts.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  =begin
3
- Copyright (C) 2011-2012 Takashi SUGA
3
+ Copyright (C) 2011-2014 Takashi SUGA
4
4
 
5
5
  You may use and/or modify this file according to the license
6
6
  described in the LICENSE.txt file included in this archive.
@@ -124,8 +124,9 @@ LOCALE
124
124
 
125
125
  def test__prefix
126
126
  date = When.when?('0594-09=12^Japanese')
127
- assert_equal(["閏長月", When::BasicTypes::M17n], [date.name('Month').label.to_s, date.name('Month').label.class])
127
+ assert_equal(["閏長月", String], [date.name('Month').label.to_s, date.name('Month').label.class])
128
128
  assert_equal(["閏長月", String], [date.name('Month').to_s, date.name('Month').to_s.class])
129
+ assert_equal("http://ja.wikipedia.org/wiki/%E9%96%8F", date.name('Month').reference('ja'))
129
130
  assert_equal("閏長月", date.name('Month').translate('日本語'))
130
131
  assert_equal("Intercalary 9th Month", date.name('Month').translate('en_US'))
131
132
  end
@@ -479,10 +480,12 @@ LOCALE
479
480
  reverse_1_4 = When::Parts::GeometricComplex.new(1,4, true)
480
481
  reverse_2_3 = When::Parts::GeometricComplex.new(2,3, true)
481
482
  reverse_2_5 = When::Parts::GeometricComplex.new(2,5, true)
482
- assert_equal("..", reverse_all.to_s)
483
483
  assert_equal("1..4", reverse_1_4.to_s)
484
484
  assert_equal("2..3", reverse_2_3.to_s)
485
- assert_equal("..", (reverse_2_3 | range_2_3).to_s)
485
+ unless Float::INFINITY == Float::MAX
486
+ assert_equal("-Infinity..Infinity", reverse_all.to_s)
487
+ assert_equal("-Infinity..Infinity", (reverse_2_3 | range_2_3).to_s)
488
+ end
486
489
  assert_equal("1..2", (reverse_1_4 | range_2_5).to_s)
487
490
  end
488
491
  end
@@ -157,5 +157,50 @@ module Test
157
157
  end
158
158
  #=end
159
159
  end
160
+
161
+ def test_daien_lunation
162
+ sample = [
163
+ 2938, 2993, 2708, 2760, 2573, 2691, 2622,
164
+ 2626, 2637, 2523, 2551, 2637, 2625, 2886,
165
+ 2703, 2764, 2791, 2680, 2792, 2764, 2797,
166
+ 1402, 2626, 2380, 2807, 3003, 23, 2698]
167
+
168
+ %w(0765-02-01 0765-12-01 0768-09-01 0769-04-01 0769-07-01 0771-05-01 0772-04-01
169
+ 0772-09-01 0774-06-01 0775-02-01 0776-03-01 0780-05-01 0781-09-01 0784-10=01
170
+ 0786-03-01 0788-04-01 0791-02-01 0791-09-01 0792-05-01 0813-12-01 0816-03-01
171
+ 0820-02-01 0820-03-01 0822-02-01 0835-04-01 0836-04-01 0841-11-01 0853-02-01).each do |ptn|
172
+ date = When.when?(ptn+ '^^ChineseTwin::大衍暦')
173
+ formula = date.frame.formula[-1]
174
+ m = When::Coordinates::Residue.mod(date.to_i+1) {|cn| formula.cn_to_time(cn)}
175
+ t = formula.cn_to_time(m[0]) + Rational(1,2)
176
+ assert_equal(sample.shift, (t - t.floor) * formula.denominator)
177
+ end
178
+ end
179
+
180
+ def test_solar_terms_for_chinese_true_lunation
181
+ date = When.when?('1690-1-1^^JapaneseTwin::貞享暦(節月)')
182
+ formula = date.frame.formula[0]
183
+ class << formula
184
+ attr_reader :day_shift, :longitude_shift, :year_delta
185
+ end
186
+ assert_equal(["12S", Rational(-1,4), 2336118.19, 1.0e-06, 1684.0, 365.241696],
187
+ [formula.formula, formula.longitude_shift, formula.day_epoch, formula.year_delta, formula.year_epoch, formula.year_length.to_f])
188
+ m = When::Coordinates::Residue.mod(date.to_i+1) {|cn| formula.cn_to_time(cn)}
189
+ t = formula.cn_to_time(m[0]) + Rational(1,2)
190
+ # assert_equal(["1690-01-01", 2338355, 20278, [15.923047, 30.436807, 2338340.576953]],
191
+ # [date.to_s, date.to_i, m[0], [m[1], m[2], t].map {|x| (x*1000000).round / 1000000.0}])
192
+
193
+ date = When.when?('1801-1-1^^JapaneseTwin::寛政暦(節月)')
194
+ formula = date.frame.formula[0]
195
+ class << formula
196
+ attr_reader :day_epoch, :day_shift, :year_delta, :year_epoch, :year_length, :longitude_shift
197
+ end
198
+ assert_equal(["12S", Rational(-1,4), 2377390.607112, 1797.0, 365.242347071],
199
+ [formula.formula, formula.longitude_shift, formula.day_epoch, formula.year_epoch, formula.year_length.to_f])
200
+ m = When::Coordinates::Residue.mod(date.to_i+1) {|cn| formula.cn_to_time(cn)}
201
+ t = formula.cn_to_time(m[0]) + Rational(1,2)
202
+ # assert_equal(["1801-01-01", 2378897, 21610, [15.986637, 30.436862, 2378882.513363]],
203
+ # [date.to_s, date.to_i, m[0], [m[1], m[2], t].map {|x| (x*1000000).round / 1000000.0}])
204
+ end
160
205
  end
161
206
  end