when_exe 0.4.2 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
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,58 +1,58 @@
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
10
-
11
- class Zoroastrian < MiniTest::TestCase
12
- def test_fasli
13
- date = When.when? '1366.1.1^^Fasli?location=(_co:Iranian::Tehran)'
14
- [["1366-01-01", "1996-03-20", 2450163],
15
- ["1367-01-01", "1997-03-20", 2450528],
16
- ["1368-01-01", "1998-03-21", 2450894],
17
- ["1369-01-01", "1999-03-21", 2451259],
18
- ["1370-01-01", "2000-03-20", 2451624],
19
- ["1371-01-01", "2001-03-20", 2451989],
20
- ["1372-01-01", "2002-03-21", 2452355],
21
- ["1373-01-01", "2003-03-21", 2452720],
22
- ["1374-01-01", "2004-03-20", 2453085],
23
- ["1375-01-01", "2005-03-20", 2453450],
24
- ["1376-01-01", "2006-03-21", 2453816],
25
- ["1377-01-01", "2007-03-21", 2454181],
26
- ["1378-01-01", "2008-03-20", 2454546],
27
- ["1379-01-01", "2009-03-20", 2454911],
28
- ["1380-01-01", "2010-03-21", 2455277],
29
- ["1381-01-01", "2011-03-21", 2455642],
30
- ["1382-01-01", "2012-03-20", 2456007],
31
- ["1383-01-01", "2013-03-20", 2456372],
32
- ["1384-01-01", "2014-03-21", 2456738],
33
- ["1385-01-01", "2015-03-21", 2457103],
34
- ["1386-01-01", "2016-03-20", 2457468],
35
- ["1387-01-01", "2017-03-20", 2457833],
36
- ["1388-01-01", "2018-03-21", 2458199],
37
- ["1389-01-01", "2019-03-21", 2458564],
38
- ["1390-01-01", "2020-03-20", 2458929],
39
- ["1391-01-01", "2021-03-20", 2459294],
40
- ["1392-01-01", "2022-03-21", 2459660],
41
- ["1393-01-01", "2023-03-21", 2460025],
42
- ["1394-01-01", "2024-03-20", 2460390],
43
- ["1395-01-01", "2025-03-20", 2460755],
44
- ["1396-01-01", "2026-03-20", 2461120],
45
- ["1397-01-01", "2027-03-21", 2461486],
46
- ["1398-01-01", "2028-03-20", 2461851]].each do |sample|
47
- assert_equal(sample, [date.to_s, (When::Gregorian ^ date).to_s, date.to_i])
48
- date += When::P1Y
49
- end
50
-
51
- date = When.when? '2001.3.21'
52
- 400.times do
53
- assert_equal([1,1], (When.Calendar('Fasli') ^ date).cal_date[-2..-1])
54
- date += When::P1Y
55
- end
56
- end
57
- end
58
- end
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
10
+
11
+ class Zoroastrian < MiniTest::TestCase
12
+ def test_fasli
13
+ date = When.when? '1366.1.1^^Fasli?location=(_co:Iranian::Tehran)'
14
+ [["1366-01-01", "1996-03-20", 2450163],
15
+ ["1367-01-01", "1997-03-20", 2450528],
16
+ ["1368-01-01", "1998-03-21", 2450894],
17
+ ["1369-01-01", "1999-03-21", 2451259],
18
+ ["1370-01-01", "2000-03-20", 2451624],
19
+ ["1371-01-01", "2001-03-20", 2451989],
20
+ ["1372-01-01", "2002-03-21", 2452355],
21
+ ["1373-01-01", "2003-03-21", 2452720],
22
+ ["1374-01-01", "2004-03-20", 2453085],
23
+ ["1375-01-01", "2005-03-20", 2453450],
24
+ ["1376-01-01", "2006-03-21", 2453816],
25
+ ["1377-01-01", "2007-03-21", 2454181],
26
+ ["1378-01-01", "2008-03-20", 2454546],
27
+ ["1379-01-01", "2009-03-20", 2454911],
28
+ ["1380-01-01", "2010-03-21", 2455277],
29
+ ["1381-01-01", "2011-03-21", 2455642],
30
+ ["1382-01-01", "2012-03-20", 2456007],
31
+ ["1383-01-01", "2013-03-20", 2456372],
32
+ ["1384-01-01", "2014-03-21", 2456738],
33
+ ["1385-01-01", "2015-03-21", 2457103],
34
+ ["1386-01-01", "2016-03-20", 2457468],
35
+ ["1387-01-01", "2017-03-20", 2457833],
36
+ ["1388-01-01", "2018-03-21", 2458199],
37
+ ["1389-01-01", "2019-03-21", 2458564],
38
+ ["1390-01-01", "2020-03-20", 2458929],
39
+ ["1391-01-01", "2021-03-20", 2459294],
40
+ ["1392-01-01", "2022-03-21", 2459660],
41
+ ["1393-01-01", "2023-03-21", 2460025],
42
+ ["1394-01-01", "2024-03-20", 2460390],
43
+ ["1395-01-01", "2025-03-20", 2460755],
44
+ ["1396-01-01", "2026-03-20", 2461120],
45
+ ["1397-01-01", "2027-03-21", 2461486],
46
+ ["1398-01-01", "2028-03-20", 2461851]].each do |sample|
47
+ assert_equal(sample, [date.to_s, (When::Gregorian ^ date).to_s, date.to_i])
48
+ date += When::P1Y
49
+ end
50
+
51
+ date = When.when? '2001.3.21'
52
+ 400.times do
53
+ assert_equal([1,1], (When.Calendar('Fasli') ^ date).cal_date[-2..-1])
54
+ date += When::P1Y
55
+ end
56
+ end
57
+ end
58
+ end
@@ -1,81 +1,81 @@
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::TimeStandard
10
-
11
- class UniversalTime < MiniTest::TestCase
12
- def view(time)
13
- return time unless time.instance_of?(When::Coordinates::LeapSeconds)
14
- return [time.trunk, time.branch, time.second]
15
- end
16
-
17
- def test__delta_t
18
- date = When.when?('2009-01-01T00:00:00Z')
19
- assert_equal("2008-12-31T23:59:01Z", (date - When::TM::IntervalLength.new(60, 'second')).to_s)
20
- assert_equal("2008-12-31T23:59:00Z", (date - When::Duration('PT60S')).to_s)
21
-
22
- date = When::TM::JulianDate.dynamical_time((2500000-(When::TM::JulianDate::JD19700101-0.5))*675)
23
- assert_equal(2500000.0, +date)
24
- assert_equal(true, +date > date.to_f)
25
-
26
- date = When::TM::JulianDate.universal_time((2500000-(When::TM::JulianDate::JD19700101-0.5))*675)
27
- assert_equal(2500000.0, date.to_f)
28
- assert_equal(true, +date > date.to_f)
29
-
30
- assert_equal((40 + 377.0/2048), When::TimeStandard.delta_t(When.when?('1970-01-01T').to_f))
31
-
32
- date = When.when?('2008-10-31T23:59:60Z')
33
- assert_equal([[2008, 11, 1], [0, 0, 0, 0]], [date.cal_date, date.clk_time.clk_time])
34
-
35
- pair = When::Coordinates::Pair.new(1,1)
36
- assert_equal([-1, -1, 1], [0.9, 1, 1.1].map {|v| v<=>pair})
37
-
38
- time = When.Resource('_t:UniversalTime')
39
- date0 = When.when?('2008-12-31T23:59:58Z') ^ When.Duration('1s') # Duration('PT1S')
40
- [
41
- "2008-12-31T23:59:58Z",
42
- "2008-12-31T23:59:59Z",
43
- "2008-12-31T23:59:60Z",
44
- "2009-01-01T00:00:00Z",
45
- "2009-01-01T00:00:01Z"
46
- ].each do |sample|
47
- date = date0.next
48
- assert_equal([sample, true], [date.to_s, date.universal_time == time.from_dynamical_time(date.dynamical_time)])
49
- end
50
-
51
- it = When::V::Event.new({
52
- 'rrule' => 'FREQ=MINUTELY;BYSECOND=59,60',
53
- 'dtstart' => '2008-12-31T23:58:59Z'
54
- }).each
55
-
56
- [
57
- "2008-12-31T23:58:59Z",
58
- "2008-12-31T23:59:59Z",
59
- "2009-01-01T00:00:59Z",
60
- "2009-01-01T00:01:59Z"
61
- ].each do |sample|
62
- assert_equal(sample, it.next.to_s)
63
- end
64
-
65
- it = When::V::Event.new({
66
- 'rrule' => 'FREQ=1s', #;BYSECOND=59,60',
67
- 'dtstart' => '2008-12-31T23:59:58Z'
68
- }).each
69
-
70
- [
71
- "2008-12-31T23:59:58Z",
72
- "2008-12-31T23:59:59Z",
73
- "2008-12-31T23:59:60Z",
74
- "2009-01-01T00:00:00Z",
75
- "2009-01-01T00:00:01Z"
76
- ].each do |sample|
77
- assert_equal(sample, it.next.to_s)
78
- end
79
- end
80
- end
81
- end
1
+ # -*- coding: utf-8 -*-
2
+ =begin
3
+ Copyright (C) 2011-2014 Takashi SUGA
4
+
5
+ You may use and/or modify this file according to the license
6
+ described in the LICENSE.txt file included in this archive.
7
+ =end
8
+
9
+ module MiniTest::TimeStandard
10
+
11
+ class UniversalTime < MiniTest::TestCase
12
+ def view(time)
13
+ return time unless time.instance_of?(When::Coordinates::LeapSeconds)
14
+ return [time.trunk, time.branch, time.second]
15
+ end
16
+
17
+ def test__delta_t
18
+ date = When.when?('2009-01-01T00:00:00Z')
19
+ assert_equal("2008-12-31T23:59:01Z", (date - When::TM::IntervalLength.new(60, 'second')).to_s)
20
+ assert_equal("2008-12-31T23:59:00Z", (date - When::Duration('PT60S')).to_s)
21
+
22
+ date = When::TM::JulianDate.dynamical_time((2500000-(When::TM::JulianDate::JD19700101-0.5))*675)
23
+ assert_equal(2500000.0, +date)
24
+ assert_equal(true, +date > date.to_f)
25
+
26
+ date = When::TM::JulianDate.universal_time((2500000-(When::TM::JulianDate::JD19700101-0.5))*675)
27
+ assert_equal(2500000.0, date.to_f)
28
+ assert_equal(true, +date > date.to_f)
29
+
30
+ assert_equal((40 + 377.0/2048), When::TimeStandard.delta_t(When.when?('1970-01-01T').to_f))
31
+
32
+ date = When.when?('2008-10-31T23:59:60Z')
33
+ assert_equal([[2008, 11, 1], [0, 0, 0, 0]], [date.cal_date, date.clk_time.clk_time])
34
+
35
+ pair = When::Coordinates::Pair.new(1,1)
36
+ assert_equal([-1, -1, 1], [0.9, 1, 1.1].map {|v| v<=>pair})
37
+
38
+ time = When.Resource('_t:UniversalTime')
39
+ date0 = When.when?('2008-12-31T23:59:58Z') ^ When.Duration('1s') # Duration('PT1S')
40
+ [
41
+ "2008-12-31T23:59:58Z",
42
+ "2008-12-31T23:59:59Z",
43
+ "2008-12-31T23:59:60Z",
44
+ "2009-01-01T00:00:00Z",
45
+ "2009-01-01T00:00:01Z"
46
+ ].each do |sample|
47
+ date = date0.next
48
+ assert_equal([sample, true], [date.to_s, date.universal_time == time.from_dynamical_time(date.dynamical_time)])
49
+ end
50
+
51
+ it = When::V::Event.new({
52
+ 'rrule' => 'FREQ=MINUTELY;BYSECOND=59,60',
53
+ 'dtstart' => '2008-12-31T23:58:59Z'
54
+ }).each
55
+
56
+ [
57
+ "2008-12-31T23:58:59Z",
58
+ "2008-12-31T23:59:59Z",
59
+ "2009-01-01T00:00:59Z",
60
+ "2009-01-01T00:01:59Z"
61
+ ].each do |sample|
62
+ assert_equal(sample, it.next.to_s)
63
+ end
64
+
65
+ it = When::V::Event.new({
66
+ 'rrule' => 'FREQ=1s', #;BYSECOND=59,60',
67
+ 'dtstart' => '2008-12-31T23:59:58Z'
68
+ }).each
69
+
70
+ [
71
+ "2008-12-31T23:59:58Z",
72
+ "2008-12-31T23:59:59Z",
73
+ "2008-12-31T23:59:60Z",
74
+ "2009-01-01T00:00:00Z",
75
+ "2009-01-01T00:00:01Z"
76
+ ].each do |sample|
77
+ assert_equal(sample, it.next.to_s)
78
+ end
79
+ end
80
+ end
81
+ end
@@ -1,402 +1,402 @@
1
- # -*- coding: utf-8 -*-
2
- =begin
3
- Copyright (C) 2011-2013 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::TM
10
-
11
- #
12
- # (5.2) Temporal Objects Package
13
- #
14
- #
15
-
16
- class Separation < MiniTest::TestCase
17
- def test_nothing
18
- end
19
- end
20
-
21
- class Order < MiniTest::TestCase
22
- def test_nothing
23
- end
24
- end
25
-
26
- class RelativePosition < MiniTest::TestCase
27
- def test_nothing
28
- end
29
- end
30
-
31
- class Object < MiniTest::TestCase
32
- def test_nothing
33
- end
34
- end
35
-
36
- class Complex < MiniTest::TestCase
37
- def test_nothing
38
- end
39
- end
40
-
41
- class TopologicalComplex < MiniTest::TestCase
42
- def test_nothing
43
- end
44
- end
45
-
46
- class Primitive < MiniTest::TestCase
47
- def test_nothing
48
- end
49
- end
50
-
51
- class GeometricPrimitive < MiniTest::TestCase
52
- def test_nothing
53
- end
54
- end
55
-
56
- class Instant < MiniTest::TestCase
57
-
58
- include When::TM::RelativePosition
59
-
60
- def test__distance
61
- position = []
62
- instant = []
63
- When.when?('20110201/06').each do |sample|
64
- position << When.when?(sample)
65
- instant << When::TM::Instant.new(position[-1])
66
- end
67
- period_0202_0204 = When::TM::Period.new(instant[1], instant[3])
68
-
69
- sample = ['P2D', 'P1D', 'P0D', 'P1D', 'P2D', 'P3D']
70
- instant.each do |i|
71
- assert_equal(sample.shift, i.distance(instant[2]).to_s)
72
- end
73
-
74
- sample = ['P1D', 'P0D', 'P0D', 'P0D', 'P1D', 'P2D']
75
- instant.each do |i|
76
- assert_equal(sample.shift, i.distance(period_0202_0204).to_s)
77
- end
78
- end
79
-
80
- def test__relative_position
81
- position = []
82
- instant = []
83
- When.when?('20110201/06').each do |sample|
84
- position << When.when?(sample)
85
- instant << When::TM::Instant.new(position[-1])
86
- end
87
- period_0202_0204 = When::TM::Period.new(instant[1], instant[3])
88
-
89
- sample = [Before, Before, Equals, After, After, After]
90
- instant.each do |i|
91
- assert_equal(sample.shift, i.relative_position(instant[2]))
92
- end
93
-
94
- sample = [Before, Begins, During, Ends, After, After]
95
- instant.each do |i|
96
- assert_equal(sample.shift, i.relative_position(period_0202_0204))
97
- end
98
- end
99
- end
100
-
101
- class Period < MiniTest::TestCase
102
-
103
- include When::TM::RelativePosition
104
-
105
- def test__distance
106
- position = []
107
- instant = []
108
- When.when?('20110201/06').each do |sample|
109
- position << When.when?(sample)
110
- instant << When::TM::Instant.new(position[-1])
111
- end
112
- assert_equal(["2011-02-01", "2011-02-02", "2011-02-03",
113
- "2011-02-04", "2011-02-05", "2011-02-06"],
114
- position.map {|v| v.to_s})
115
-
116
- period_0201_0202 = When::TM::Period.new(instant[0], instant[1])
117
- period_0202_0203 = When::TM::Period.new(instant[1], instant[2])
118
- period_0203_0204 = When::TM::Period.new(instant[2], instant[3])
119
- period_0204_0205 = When::TM::Period.new(instant[3], instant[4])
120
- period_0205_0206 = When::TM::Period.new(instant[4], instant[5])
121
-
122
- period_0202_0204 = When::TM::Period.new(instant[1], instant[3])
123
- period_0204_0206 = When::TM::Period.new(instant[3], instant[5])
124
- period_0203_0206 = When::TM::Period.new(instant[2], instant[5])
125
- period_0201_0206 = When::TM::Period.new(instant[0], instant[5])
126
-
127
- extent_0201_0202 = When::EX::Extent.new(period_0201_0202)
128
- extent_0202_0203 = When::EX::Extent.new(period_0202_0203)
129
- extent_0203_0204 = When::EX::Extent.new(period_0203_0204)
130
- extent_0204_0205 = When::EX::Extent.new(period_0204_0205)
131
- extent_0205_0206 = When::EX::Extent.new(period_0205_0206)
132
-
133
- extent_0202_0204 = When::EX::Extent.new(period_0202_0204)
134
- extent_0204_0206 = When::EX::Extent.new(period_0204_0206)
135
- extent_0203_0206 = When::EX::Extent.new(period_0203_0206)
136
- extent_0201_0206 = When::EX::Extent.new(period_0201_0206)
137
-
138
- sample = ['P1D', 'P0D', 'P0D', 'P0D', 'P1D', 'P2D']
139
- instant.each do |i|
140
- assert_equal(sample.shift, period_0202_0204.distance(i).to_s)
141
- end
142
-
143
- [['P2D', period_0201_0202, period_0204_0206],
144
- ['P0D', period_0201_0202, period_0202_0204],
145
- ['P0D', period_0202_0203, period_0202_0204],
146
- ['P0D', period_0203_0204, period_0202_0204],
147
- ['P0D', period_0204_0205, period_0202_0204],
148
- ['P0D', period_0203_0206, period_0202_0204],
149
- ['P1D', period_0205_0206, period_0202_0204]].each do |sample|
150
- assert_equal(sample[0], sample[1].distance(sample[2]).to_s)
151
- assert_equal(sample[0], sample[2].distance(sample[1]).to_s)
152
- end
153
-
154
- sample = ['P1D', 'P0D', 'P0D', 'P0D', 'P1D', 'P2D']
155
- instant.each do |i|
156
- assert_equal(sample.shift, extent_0202_0204.distance(i).to_s)
157
- end
158
-
159
- [['P2D', extent_0201_0202, extent_0204_0206],
160
- ['P0D', extent_0201_0202, extent_0202_0204],
161
- ['P0D', extent_0202_0203, extent_0202_0204],
162
- ['P0D', extent_0203_0204, extent_0202_0204],
163
- ['P0D', extent_0204_0205, extent_0202_0204],
164
- ['P0D', extent_0203_0206, extent_0202_0204],
165
- ['P1D', extent_0205_0206, extent_0202_0204]].each do |sample|
166
- assert_equal(sample[0], sample[1].distance(sample[2]).to_s)
167
- assert_equal(sample[0], sample[2].distance(sample[1]).to_s)
168
- end
169
- end
170
-
171
- def test__relative_position
172
- position = []
173
- instant = []
174
- When.when?('20110201/06').each do |sample|
175
- position << When.when?(sample)
176
- instant << When::TM::Instant.new(position[-1])
177
- end
178
- period_0201_0202 = When::TM::Period.new(instant[0], instant[1])
179
- period_0202_0203 = When::TM::Period.new(instant[1], instant[2])
180
- period_0203_0204 = When::TM::Period.new(instant[2], instant[3])
181
- period_0204_0205 = When::TM::Period.new(instant[3], instant[4])
182
- period_0205_0206 = When::TM::Period.new(instant[4], instant[5])
183
-
184
- period_0202_0204 = When::TM::Period.new(instant[1], instant[3])
185
- period_0203_0206 = When::TM::Period.new(instant[2], instant[5])
186
- period_0204_0206 = When::TM::Period.new(instant[3], instant[5])
187
- period_0201_0206 = When::TM::Period.new(instant[0], instant[5])
188
-
189
- sample = [After, BegunBy, Contains, EndedBy, Before, Before]
190
- instant.each do |i|
191
- assert_equal(sample.shift, period_0202_0204.relative_position(i))
192
- end
193
-
194
- [[Before, period_0201_0202, period_0204_0206],
195
- [Meets, period_0201_0202, period_0202_0204],
196
- [Overlaps, period_0202_0204, period_0203_0206],
197
- [Begins, period_0202_0203, period_0202_0204],
198
- [BegunBy, period_0202_0204, period_0202_0203],
199
-
200
- [During, period_0202_0204, period_0201_0206],
201
- [Contains, period_0201_0206, period_0202_0204],
202
- [Equals, period_0202_0204, period_0202_0204],
203
-
204
- [OverlappedBy, period_0203_0206, period_0202_0204],
205
- [Ends, period_0203_0204, period_0202_0204],
206
- [EndedBy, period_0202_0204, period_0203_0204],
207
- [MetBy, period_0204_0205, period_0202_0204],
208
- [After, period_0205_0206, period_0202_0204]].each do |sample|
209
- assert_equal(sample[0], sample[1].relative_position(sample[2]))
210
- end
211
-
212
- end
213
- end
214
-
215
- class TopologicalPrimitive < MiniTest::TestCase
216
- def test_nothing
217
- end
218
- end
219
-
220
- class Node < MiniTest::TestCase
221
- def test_nothing
222
- end
223
- end
224
-
225
- class Edge < MiniTest::TestCase
226
- def test_nothing
227
- end
228
- end
229
-
230
- class Duration < MiniTest::TestCase
231
- def test__duration_constructors
232
- assert_equal( 1, When::TM::Duration.new(1).duration)
233
- assert_equal( 1.0/128, When::TM::Duration.second(1).duration)
234
- assert_equal( 60.0/128, When::TM::Duration.minute(1).duration)
235
- assert_equal( 3600.0/128, When::TM::Duration.hour(1).duration)
236
- assert_equal(86400.0/128, When::TM::Duration.day(1).duration)
237
- assert_equal(93784.0/128, When::TM::Duration.dhms(1,2,3,4).duration)
238
- end
239
-
240
- def test__duration_values
241
- assert_equal(1, When::TM::Duration.new(1).system)
242
- assert_equal(2, When::TM::Duration.second(2).second)
243
- assert_equal(3, When::TM::Duration.minute(3).minute)
244
- assert_equal(4, When::TM::Duration.hour(4).hour)
245
- assert_equal(5, When::TM::Duration.day(5).day)
246
- assert_equal([1,2,3,4], When::TM::Duration.dhms(1,2,3,4).to_dhms)
247
- assert_equal([-2,21,56,56], (-When::TM::Duration.dhms(1,2,3,4)).to_dhms)
248
- end
249
-
250
- def test__duration_elements
251
- duration = When::TM::Duration.dhms(1,2,3,4.5)
252
- assert_equal(1, duration[0])
253
- assert_equal(2, duration[1])
254
- assert_equal(3, duration[2])
255
- assert_equal(4.5, duration[3])
256
- end
257
-
258
- def test__duration_arithmetics
259
- assert_equal(When::TM::Duration.dhms(-2,21,56,56), -When::TM::Duration.dhms(1,2,3,4))
260
- assert_equal(When::TM::Duration.dhms(2,3,4,5), When::TM::Duration.dhms(1,2,3,4) + When::TM::Duration.dhms(1,1,1,1))
261
- assert_equal(When::TM::Duration.dhms(0,1,2,3), When::TM::Duration.dhms(1,2,3,4) - When::TM::Duration.dhms(1,1,1,1))
262
- assert_equal(When::TM::Duration.dhms(2,4,6,8), When::TM::Duration.dhms(1,2,3,4) * 2)
263
- assert_equal(When::TM::Duration.dhms(1,2,3,4), When::TM::Duration.dhms(2,4,6,8) / 2)
264
- assert_equal(2, When::TM::Duration.dhms(2,4,6,8) / When::TM::Duration.dhms(1,2,3,4))
265
- end
266
-
267
- def test__duration_and_time
268
- start = Time.now
269
- duration = When::TM::Duration.dhms(1,2,3,4.25)
270
- stop = start + duration
271
- assert_equal((RUBY_VERSION.to_f<1.9 ? 93784.25 : 93784), stop-start)
272
- assert_raises(TypeError) {
273
- ::Date.today + duration
274
- }
275
- require 'when_exe/core/duration'
276
- stop = start + duration
277
- assert_equal(93784.25, stop-start)
278
-
279
- now_date = DateTime.now
280
- duration = When::TM::Duration.hour(8)
281
- assert_equal(Rational(1,128), (now_date + duration * 3 / 128 ) - now_date)
282
- assert_equal(Rational(1,3), (now_date + duration ) - now_date)
283
- assert_equal(Rational(1,1), (now_date + duration * 3) - now_date)
284
-
285
- stop = start + When.Duration('P1DT2H3M4S')
286
- assert_equal(93784, stop-start)
287
-
288
- assert_raises(TypeError) {
289
- stop = start + When.Duration('P2M1DT2H3M4S')
290
- }
291
- end
292
- end
293
-
294
- class PeriodDuration < MiniTest::TestCase
295
- def test__period_duration
296
- period = When.Duration('P2Y3M4D')
297
- [[-2, 2], [-1, 3], [0, 4]].each do |sample|
298
- assert_equal(sample[1], period[sample[0]])
299
- end
300
- period = When.Duration('PT5H6M7S')
301
- [[1, 5], [2, 6], [3, 7]].each do |sample|
302
- assert_equal(sample[1], period[sample[0]])
303
- end
304
- period = When.Duration('P2Y3M4DT5H6M7S')
305
- [[-2, 2], [-1, 3], [0, 4], [1, 5], [2, 6], [3, 7]].each do |sample|
306
- assert_equal(sample[1], period[sample[0]])
307
- end
308
- period = When.Duration('P8W9D')
309
- [[-0.5, 8], [0, 8*7+9]].each do |sample|
310
- assert_equal(sample[1], period[sample[0]])
311
- end
312
- end
313
-
314
- def test__period_duration_diff
315
- date1 = When.when?('2012-07-01')
316
- date2 = When.when?('2012-07-02')
317
- duration = date2 - date1
318
- assert_equal('P1D', duration.to_s)
319
- assert_equal(When::TM::PeriodDuration, duration.class)
320
-
321
- if Object.const_defined?(:TZInfo)
322
- time = When.when?('2013-03-10T01:00:00', :tz=>'America/New_York')
323
- assert_equal('2013-03-10T02:30:00-04:00', (time + When.Duration('PT1.5H')).to_s) # ��ʂ�1.5����
324
- else
325
- puts
326
- puts "Tests for TZInfo have been skipped at line #{__LINE__} of #{__FILE__.split(/\//)[-1]}."
327
- end
328
-
329
- vcal = When.Resource("examples/USA-DST.ics?C=New_York&Z=E&D=04&DZ=06&S=05&SZ=07")
330
- time = When.when?('2013-03-10T01:00:00', :clock=>vcal['America/New_York'])
331
- assert_equal('2013-03-10T02:30:00-04:00', (time + When.Duration('PT1.5H')).to_s) # ��ʂ�1.5����
332
- end
333
-
334
- Sample10 = %w(2013-01-31 2013-02-28 2013-03-31 2013-04-30 2013-05-31
335
- 2013-06-30 2013-07-31 2013-08-31 2013-09-30 2013-10-31)
336
-
337
- Sample12 = %w(2013-01-31 2013-02-28 2013-03-31 2013-04-30 2013-05-31 2013-06-30
338
- 2013-07-31 2013-08-31 2013-09-30 2013-10-31 2013-11-30 2013-12-31)
339
-
340
- def test__duration_each
341
- sample = Sample10.dup
342
- When::P1M.enum_for(When.when?('2013-01-31'), :forward, 10).each do |date|
343
- assert_equal(sample.shift, date.to_s)
344
- end
345
-
346
- count = 0
347
- (When.when?('2013-01-31') ^ When::P1M).each({:count_limit=>0}) do |date|
348
- count += 1
349
- end
350
- assert_equal(0, count)
351
-
352
- sample = Sample10.dup
353
- (When.when?('2013-01-31') ^ When::P1M).each({:count_limit=>10}) do |date|
354
- assert_equal(sample.shift, date.to_s)
355
- end
356
-
357
- sample = Sample12.dup
358
- (When.when?('2013-01-31') ^ When::P1M).each({:until=>When.when?('2013-12-31')}) do |date|
359
- assert_equal(sample.shift, date.to_s)
360
- end
361
-
362
- sample = Sample12.reverse
363
- (When.when?('2013-12-31') ^ -When::P1M).each({:until=>When.when?('2013-01-31')}) do |date|
364
- assert_equal(sample.shift, date.to_s)
365
- end
366
- end
367
- end
368
-
369
- class IntervalLength < MiniTest::TestCase
370
- def test__interval_length
371
- [
372
- ['7E-3s', 7, 3, 10, 'second', '7E-3s' ],
373
- ['8X-2m', 8, 2, 60, 'minute', '8X-2m' ],
374
- ['6(12)7D', 6, -7, 12, 'day', '6(12)+7D' ],
375
- ['1(16)4*10S', 1, -4, 16, '10', '1(16)+4*10S']
376
- ].each do |sample|
377
- interval = When.Duration(sample[0])
378
- assert_equal(sample[1..5], [interval.value, interval.factor, interval.radix, interval.unit, interval.to_s])
379
- end
380
- end
381
-
382
- def test__interval_length_diff
383
- time1 = When.when?('2012-07-01T01:23:45+09:00')
384
- time2 = When.when?('2012-07-02T01:23:45+09:00')
385
- duration = time2 - time1
386
- assert_equal('86401.0s', duration.to_s)
387
- assert_equal(When::TM::IntervalLength, duration.class)
388
-
389
- if Object.const_defined?(:TZInfo)
390
- time = When.when?('2013-03-10T01:00:00', :tz=>'America/New_York')
391
- assert_equal('2013-03-10T03:30:00-04:00', (time + When.Duration('1.5h')).to_s) # �����I��1.5����
392
- else
393
- puts
394
- puts "Tests for TZInfo have been skipped at line #{__LINE__} of #{__FILE__.split(/\//)[-1]}."
395
- end
396
-
397
- vcal = When.Resource("examples/USA-DST.ics?C=New_York&Z=E&D=04&DZ=06&S=05&SZ=07")
398
- time = When.when?('2013-03-10T01:00:00', :clock=>vcal['America/New_York'])
399
- assert_equal('2013-03-10T03:30:00-04:00', (time + When.Duration('1.5h')).to_s) # �����I��1.5����
400
- end
401
- end
402
- end
1
+ # -*- coding: utf-8 -*-
2
+ =begin
3
+ Copyright (C) 2011-2013 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::TM
10
+
11
+ #
12
+ # (5.2) Temporal Objects Package
13
+ #
14
+ #
15
+
16
+ class Separation < MiniTest::TestCase
17
+ def test_nothing
18
+ end
19
+ end
20
+
21
+ class Order < MiniTest::TestCase
22
+ def test_nothing
23
+ end
24
+ end
25
+
26
+ class RelativePosition < MiniTest::TestCase
27
+ def test_nothing
28
+ end
29
+ end
30
+
31
+ class Object < MiniTest::TestCase
32
+ def test_nothing
33
+ end
34
+ end
35
+
36
+ class Complex < MiniTest::TestCase
37
+ def test_nothing
38
+ end
39
+ end
40
+
41
+ class TopologicalComplex < MiniTest::TestCase
42
+ def test_nothing
43
+ end
44
+ end
45
+
46
+ class Primitive < MiniTest::TestCase
47
+ def test_nothing
48
+ end
49
+ end
50
+
51
+ class GeometricPrimitive < MiniTest::TestCase
52
+ def test_nothing
53
+ end
54
+ end
55
+
56
+ class Instant < MiniTest::TestCase
57
+
58
+ include When::TM::RelativePosition
59
+
60
+ def test__distance
61
+ position = []
62
+ instant = []
63
+ When.when?('20110201/06').each do |sample|
64
+ position << When.when?(sample)
65
+ instant << When::TM::Instant.new(position[-1])
66
+ end
67
+ period_0202_0204 = When::TM::Period.new(instant[1], instant[3])
68
+
69
+ sample = ['P2D', 'P1D', 'P0D', 'P1D', 'P2D', 'P3D']
70
+ instant.each do |i|
71
+ assert_equal(sample.shift, i.distance(instant[2]).to_s)
72
+ end
73
+
74
+ sample = ['P1D', 'P0D', 'P0D', 'P0D', 'P1D', 'P2D']
75
+ instant.each do |i|
76
+ assert_equal(sample.shift, i.distance(period_0202_0204).to_s)
77
+ end
78
+ end
79
+
80
+ def test__relative_position
81
+ position = []
82
+ instant = []
83
+ When.when?('20110201/06').each do |sample|
84
+ position << When.when?(sample)
85
+ instant << When::TM::Instant.new(position[-1])
86
+ end
87
+ period_0202_0204 = When::TM::Period.new(instant[1], instant[3])
88
+
89
+ sample = [Before, Before, Equals, After, After, After]
90
+ instant.each do |i|
91
+ assert_equal(sample.shift, i.relative_position(instant[2]))
92
+ end
93
+
94
+ sample = [Before, Begins, During, Ends, After, After]
95
+ instant.each do |i|
96
+ assert_equal(sample.shift, i.relative_position(period_0202_0204))
97
+ end
98
+ end
99
+ end
100
+
101
+ class Period < MiniTest::TestCase
102
+
103
+ include When::TM::RelativePosition
104
+
105
+ def test__distance
106
+ position = []
107
+ instant = []
108
+ When.when?('20110201/06').each do |sample|
109
+ position << When.when?(sample)
110
+ instant << When::TM::Instant.new(position[-1])
111
+ end
112
+ assert_equal(["2011-02-01", "2011-02-02", "2011-02-03",
113
+ "2011-02-04", "2011-02-05", "2011-02-06"],
114
+ position.map {|v| v.to_s})
115
+
116
+ period_0201_0202 = When::TM::Period.new(instant[0], instant[1])
117
+ period_0202_0203 = When::TM::Period.new(instant[1], instant[2])
118
+ period_0203_0204 = When::TM::Period.new(instant[2], instant[3])
119
+ period_0204_0205 = When::TM::Period.new(instant[3], instant[4])
120
+ period_0205_0206 = When::TM::Period.new(instant[4], instant[5])
121
+
122
+ period_0202_0204 = When::TM::Period.new(instant[1], instant[3])
123
+ period_0204_0206 = When::TM::Period.new(instant[3], instant[5])
124
+ period_0203_0206 = When::TM::Period.new(instant[2], instant[5])
125
+ period_0201_0206 = When::TM::Period.new(instant[0], instant[5])
126
+
127
+ extent_0201_0202 = When::EX::Extent.new(period_0201_0202)
128
+ extent_0202_0203 = When::EX::Extent.new(period_0202_0203)
129
+ extent_0203_0204 = When::EX::Extent.new(period_0203_0204)
130
+ extent_0204_0205 = When::EX::Extent.new(period_0204_0205)
131
+ extent_0205_0206 = When::EX::Extent.new(period_0205_0206)
132
+
133
+ extent_0202_0204 = When::EX::Extent.new(period_0202_0204)
134
+ extent_0204_0206 = When::EX::Extent.new(period_0204_0206)
135
+ extent_0203_0206 = When::EX::Extent.new(period_0203_0206)
136
+ extent_0201_0206 = When::EX::Extent.new(period_0201_0206)
137
+
138
+ sample = ['P1D', 'P0D', 'P0D', 'P0D', 'P1D', 'P2D']
139
+ instant.each do |i|
140
+ assert_equal(sample.shift, period_0202_0204.distance(i).to_s)
141
+ end
142
+
143
+ [['P2D', period_0201_0202, period_0204_0206],
144
+ ['P0D', period_0201_0202, period_0202_0204],
145
+ ['P0D', period_0202_0203, period_0202_0204],
146
+ ['P0D', period_0203_0204, period_0202_0204],
147
+ ['P0D', period_0204_0205, period_0202_0204],
148
+ ['P0D', period_0203_0206, period_0202_0204],
149
+ ['P1D', period_0205_0206, period_0202_0204]].each do |sample|
150
+ assert_equal(sample[0], sample[1].distance(sample[2]).to_s)
151
+ assert_equal(sample[0], sample[2].distance(sample[1]).to_s)
152
+ end
153
+
154
+ sample = ['P1D', 'P0D', 'P0D', 'P0D', 'P1D', 'P2D']
155
+ instant.each do |i|
156
+ assert_equal(sample.shift, extent_0202_0204.distance(i).to_s)
157
+ end
158
+
159
+ [['P2D', extent_0201_0202, extent_0204_0206],
160
+ ['P0D', extent_0201_0202, extent_0202_0204],
161
+ ['P0D', extent_0202_0203, extent_0202_0204],
162
+ ['P0D', extent_0203_0204, extent_0202_0204],
163
+ ['P0D', extent_0204_0205, extent_0202_0204],
164
+ ['P0D', extent_0203_0206, extent_0202_0204],
165
+ ['P1D', extent_0205_0206, extent_0202_0204]].each do |sample|
166
+ assert_equal(sample[0], sample[1].distance(sample[2]).to_s)
167
+ assert_equal(sample[0], sample[2].distance(sample[1]).to_s)
168
+ end
169
+ end
170
+
171
+ def test__relative_position
172
+ position = []
173
+ instant = []
174
+ When.when?('20110201/06').each do |sample|
175
+ position << When.when?(sample)
176
+ instant << When::TM::Instant.new(position[-1])
177
+ end
178
+ period_0201_0202 = When::TM::Period.new(instant[0], instant[1])
179
+ period_0202_0203 = When::TM::Period.new(instant[1], instant[2])
180
+ period_0203_0204 = When::TM::Period.new(instant[2], instant[3])
181
+ period_0204_0205 = When::TM::Period.new(instant[3], instant[4])
182
+ period_0205_0206 = When::TM::Period.new(instant[4], instant[5])
183
+
184
+ period_0202_0204 = When::TM::Period.new(instant[1], instant[3])
185
+ period_0203_0206 = When::TM::Period.new(instant[2], instant[5])
186
+ period_0204_0206 = When::TM::Period.new(instant[3], instant[5])
187
+ period_0201_0206 = When::TM::Period.new(instant[0], instant[5])
188
+
189
+ sample = [After, BegunBy, Contains, EndedBy, Before, Before]
190
+ instant.each do |i|
191
+ assert_equal(sample.shift, period_0202_0204.relative_position(i))
192
+ end
193
+
194
+ [[Before, period_0201_0202, period_0204_0206],
195
+ [Meets, period_0201_0202, period_0202_0204],
196
+ [Overlaps, period_0202_0204, period_0203_0206],
197
+ [Begins, period_0202_0203, period_0202_0204],
198
+ [BegunBy, period_0202_0204, period_0202_0203],
199
+
200
+ [During, period_0202_0204, period_0201_0206],
201
+ [Contains, period_0201_0206, period_0202_0204],
202
+ [Equals, period_0202_0204, period_0202_0204],
203
+
204
+ [OverlappedBy, period_0203_0206, period_0202_0204],
205
+ [Ends, period_0203_0204, period_0202_0204],
206
+ [EndedBy, period_0202_0204, period_0203_0204],
207
+ [MetBy, period_0204_0205, period_0202_0204],
208
+ [After, period_0205_0206, period_0202_0204]].each do |sample|
209
+ assert_equal(sample[0], sample[1].relative_position(sample[2]))
210
+ end
211
+
212
+ end
213
+ end
214
+
215
+ class TopologicalPrimitive < MiniTest::TestCase
216
+ def test_nothing
217
+ end
218
+ end
219
+
220
+ class Node < MiniTest::TestCase
221
+ def test_nothing
222
+ end
223
+ end
224
+
225
+ class Edge < MiniTest::TestCase
226
+ def test_nothing
227
+ end
228
+ end
229
+
230
+ class Duration < MiniTest::TestCase
231
+ def test__duration_constructors
232
+ assert_equal( 1, When::TM::Duration.new(1).duration)
233
+ assert_equal( 1.0/128, When::TM::Duration.second(1).duration)
234
+ assert_equal( 60.0/128, When::TM::Duration.minute(1).duration)
235
+ assert_equal( 3600.0/128, When::TM::Duration.hour(1).duration)
236
+ assert_equal(86400.0/128, When::TM::Duration.day(1).duration)
237
+ assert_equal(93784.0/128, When::TM::Duration.dhms(1,2,3,4).duration)
238
+ end
239
+
240
+ def test__duration_values
241
+ assert_equal(1, When::TM::Duration.new(1).system)
242
+ assert_equal(2, When::TM::Duration.second(2).second)
243
+ assert_equal(3, When::TM::Duration.minute(3).minute)
244
+ assert_equal(4, When::TM::Duration.hour(4).hour)
245
+ assert_equal(5, When::TM::Duration.day(5).day)
246
+ assert_equal([1,2,3,4], When::TM::Duration.dhms(1,2,3,4).to_dhms)
247
+ assert_equal([-2,21,56,56], (-When::TM::Duration.dhms(1,2,3,4)).to_dhms)
248
+ end
249
+
250
+ def test__duration_elements
251
+ duration = When::TM::Duration.dhms(1,2,3,4.5)
252
+ assert_equal(1, duration[0])
253
+ assert_equal(2, duration[1])
254
+ assert_equal(3, duration[2])
255
+ assert_equal(4.5, duration[3])
256
+ end
257
+
258
+ def test__duration_arithmetics
259
+ assert_equal(When::TM::Duration.dhms(-2,21,56,56), -When::TM::Duration.dhms(1,2,3,4))
260
+ assert_equal(When::TM::Duration.dhms(2,3,4,5), When::TM::Duration.dhms(1,2,3,4) + When::TM::Duration.dhms(1,1,1,1))
261
+ assert_equal(When::TM::Duration.dhms(0,1,2,3), When::TM::Duration.dhms(1,2,3,4) - When::TM::Duration.dhms(1,1,1,1))
262
+ assert_equal(When::TM::Duration.dhms(2,4,6,8), When::TM::Duration.dhms(1,2,3,4) * 2)
263
+ assert_equal(When::TM::Duration.dhms(1,2,3,4), When::TM::Duration.dhms(2,4,6,8) / 2)
264
+ assert_equal(2, When::TM::Duration.dhms(2,4,6,8) / When::TM::Duration.dhms(1,2,3,4))
265
+ end
266
+
267
+ def test__duration_and_time
268
+ start = Time.now
269
+ duration = When::TM::Duration.dhms(1,2,3,4.25)
270
+ stop = start + duration
271
+ assert_equal((RUBY_VERSION.to_f<1.9 ? 93784.25 : 93784), stop-start)
272
+ assert_raises(TypeError) {
273
+ ::Date.today + duration
274
+ }
275
+ require 'when_exe/core/duration'
276
+ stop = start + duration
277
+ assert_equal(93784.25, stop-start)
278
+
279
+ now_date = DateTime.now
280
+ duration = When::TM::Duration.hour(8)
281
+ assert_equal(Rational(1,128), (now_date + duration * 3 / 128 ) - now_date)
282
+ assert_equal(Rational(1,3), (now_date + duration ) - now_date)
283
+ assert_equal(Rational(1,1), (now_date + duration * 3) - now_date)
284
+
285
+ stop = start + When.Duration('P1DT2H3M4S')
286
+ assert_equal(93784, stop-start)
287
+
288
+ assert_raises(TypeError) {
289
+ stop = start + When.Duration('P2M1DT2H3M4S')
290
+ }
291
+ end
292
+ end
293
+
294
+ class PeriodDuration < MiniTest::TestCase
295
+ def test__period_duration
296
+ period = When.Duration('P2Y3M4D')
297
+ [[-2, 2], [-1, 3], [0, 4]].each do |sample|
298
+ assert_equal(sample[1], period[sample[0]])
299
+ end
300
+ period = When.Duration('PT5H6M7S')
301
+ [[1, 5], [2, 6], [3, 7]].each do |sample|
302
+ assert_equal(sample[1], period[sample[0]])
303
+ end
304
+ period = When.Duration('P2Y3M4DT5H6M7S')
305
+ [[-2, 2], [-1, 3], [0, 4], [1, 5], [2, 6], [3, 7]].each do |sample|
306
+ assert_equal(sample[1], period[sample[0]])
307
+ end
308
+ period = When.Duration('P8W9D')
309
+ [[-0.5, 8], [0, 8*7+9]].each do |sample|
310
+ assert_equal(sample[1], period[sample[0]])
311
+ end
312
+ end
313
+
314
+ def test__period_duration_diff
315
+ date1 = When.when?('2012-07-01')
316
+ date2 = When.when?('2012-07-02')
317
+ duration = date2 - date1
318
+ assert_equal('P1D', duration.to_s)
319
+ assert_equal(When::TM::PeriodDuration, duration.class)
320
+
321
+ if Object.const_defined?(:TZInfo)
322
+ time = When.when?('2013-03-10T01:00:00', :tz=>'America/New_York')
323
+ assert_equal('2013-03-10T02:30:00-04:00', (time + When.Duration('PT1.5H')).to_s) # ��ʂ�1.5����
324
+ else
325
+ puts
326
+ puts "Tests for TZInfo have been skipped at line #{__LINE__} of #{__FILE__.split(/\//)[-1]}."
327
+ end
328
+
329
+ vcal = When.Resource("examples/USA-DST.ics?C=New_York&Z=E&D=04&DZ=06&S=05&SZ=07")
330
+ time = When.when?('2013-03-10T01:00:00', :clock=>vcal['America/New_York'])
331
+ assert_equal('2013-03-10T02:30:00-04:00', (time + When.Duration('PT1.5H')).to_s) # ��ʂ�1.5����
332
+ end
333
+
334
+ Sample10 = %w(2013-01-31 2013-02-28 2013-03-31 2013-04-30 2013-05-31
335
+ 2013-06-30 2013-07-31 2013-08-31 2013-09-30 2013-10-31)
336
+
337
+ Sample12 = %w(2013-01-31 2013-02-28 2013-03-31 2013-04-30 2013-05-31 2013-06-30
338
+ 2013-07-31 2013-08-31 2013-09-30 2013-10-31 2013-11-30 2013-12-31)
339
+
340
+ def test__duration_each
341
+ sample = Sample10.dup
342
+ When::P1M.enum_for(When.when?('2013-01-31'), :forward, 10).each do |date|
343
+ assert_equal(sample.shift, date.to_s)
344
+ end
345
+
346
+ count = 0
347
+ (When.when?('2013-01-31') ^ When::P1M).each({:count_limit=>0}) do |date|
348
+ count += 1
349
+ end
350
+ assert_equal(0, count)
351
+
352
+ sample = Sample10.dup
353
+ (When.when?('2013-01-31') ^ When::P1M).each({:count_limit=>10}) do |date|
354
+ assert_equal(sample.shift, date.to_s)
355
+ end
356
+
357
+ sample = Sample12.dup
358
+ (When.when?('2013-01-31') ^ When::P1M).each({:until=>When.when?('2013-12-31')}) do |date|
359
+ assert_equal(sample.shift, date.to_s)
360
+ end
361
+
362
+ sample = Sample12.reverse
363
+ (When.when?('2013-12-31') ^ -When::P1M).each({:until=>When.when?('2013-01-31')}) do |date|
364
+ assert_equal(sample.shift, date.to_s)
365
+ end
366
+ end
367
+ end
368
+
369
+ class IntervalLength < MiniTest::TestCase
370
+ def test__interval_length
371
+ [
372
+ ['7E-3s', 7, 3, 10, 'second', '7E-3s' ],
373
+ ['8X-2m', 8, 2, 60, 'minute', '8X-2m' ],
374
+ ['6(12)7D', 6, -7, 12, 'day', '6(12)+7D' ],
375
+ ['1(16)4*10S', 1, -4, 16, '10', '1(16)+4*10S']
376
+ ].each do |sample|
377
+ interval = When.Duration(sample[0])
378
+ assert_equal(sample[1..5], [interval.value, interval.factor, interval.radix, interval.unit, interval.to_s])
379
+ end
380
+ end
381
+
382
+ def test__interval_length_diff
383
+ time1 = When.when?('2012-07-01T01:23:45+09:00')
384
+ time2 = When.when?('2012-07-02T01:23:45+09:00')
385
+ duration = time2 - time1
386
+ assert_equal('86401.0s', duration.to_s)
387
+ assert_equal(When::TM::IntervalLength, duration.class)
388
+
389
+ if Object.const_defined?(:TZInfo)
390
+ time = When.when?('2013-03-10T01:00:00', :tz=>'America/New_York')
391
+ assert_equal('2013-03-10T03:30:00-04:00', (time + When.Duration('1.5h')).to_s) # �����I��1.5����
392
+ else
393
+ puts
394
+ puts "Tests for TZInfo have been skipped at line #{__LINE__} of #{__FILE__.split(/\//)[-1]}."
395
+ end
396
+
397
+ vcal = When.Resource("examples/USA-DST.ics?C=New_York&Z=E&D=04&DZ=06&S=05&SZ=07")
398
+ time = When.when?('2013-03-10T01:00:00', :clock=>vcal['America/New_York'])
399
+ assert_equal('2013-03-10T03:30:00-04:00', (time + When.Duration('1.5h')).to_s) # �����I��1.5����
400
+ end
401
+ end
402
+ end