when_exe 0.4.2 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +24 -23
  3. data/lib/when_exe/ephemeris/moon.rb +333 -333
  4. data/lib/when_exe/linkeddata.rb +0 -1
  5. data/lib/when_exe/locales/encoding_conversion.rb +134 -134
  6. data/lib/when_exe/locales/iast.rb +90 -90
  7. data/lib/when_exe/locales/transliteration_table.rb +62 -62
  8. data/lib/when_exe/parts/method_cash.rb +224 -224
  9. data/lib/when_exe/region/chinese/calendars.rb +1016 -1016
  10. data/lib/when_exe/region/geologicalage.rb +1 -1
  11. data/lib/when_exe/region/japanese/calendars.rb +397 -397
  12. data/lib/when_exe/region/japanese/eclipses.rb +1194 -1194
  13. data/lib/when_exe/region/japanese/nihon_shoki.rb +70 -70
  14. data/lib/when_exe/region/korean.rb +384 -384
  15. data/lib/when_exe/region/ryukyu.rb +101 -101
  16. data/lib/when_exe/tmposition.rb +2 -2
  17. data/lib/when_exe/tmreference.rb +3 -3
  18. data/lib/when_exe/version.rb +1 -1
  19. data/test/scripts/geometric_complex.rb +41 -41
  20. data/test/scripts/korea.rb +59 -59
  21. data/test/scripts/thai.rb +36 -36
  22. data/test/test/basictypes.rb +431 -431
  23. data/test/test/calendarnote.rb +86 -86
  24. data/test/test/calendartypes.rb +97 -97
  25. data/test/test/coordinates.rb +397 -397
  26. data/test/test/ephemeris.rb +115 -115
  27. data/test/test/ephemeris/moon.rb +14 -14
  28. data/test/test/ephemeris/planets.rb +14 -14
  29. data/test/test/ephemeris/sun.rb +14 -14
  30. data/test/test/inspect.rb +153 -153
  31. data/test/test/parts.rb +488 -488
  32. data/test/test/region/armenian.rb +20 -20
  33. data/test/test/region/bahai.rb +58 -58
  34. data/test/test/region/balinese.rb +34 -34
  35. data/test/test/region/chinese.rb +229 -229
  36. data/test/test/region/christian.rb +226 -226
  37. data/test/test/region/coptic.rb +27 -27
  38. data/test/test/region/discordian.rb +20 -20
  39. data/test/test/region/french.rb +33 -33
  40. data/test/test/region/geologicalage.rb +17 -17
  41. data/test/test/region/iran.rb +54 -54
  42. data/test/test/region/islamic.rb +54 -54
  43. data/test/test/region/japanese.rb +261 -261
  44. data/test/test/region/jewish.rb +63 -63
  45. data/test/test/region/shire.rb +58 -58
  46. data/test/test/region/swedish.rb +45 -45
  47. data/test/test/region/thai.rb +116 -116
  48. data/test/test/region/tibetan.rb +30 -30
  49. data/test/test/region/vietnamese.rb +102 -102
  50. data/test/test/region/zoroastrian.rb +58 -58
  51. data/test/test/timestandard.rb +81 -81
  52. data/test/test/tmobjects.rb +402 -402
  53. data/test/test/tmreference.rb +157 -157
  54. metadata +4 -88
@@ -1,115 +1,115 @@
1
- # -*- coding: utf-8 -*-
2
- =begin
3
- Copyright (C) 2011-2014 Takashi SUGA
4
-
5
- You may use and/or modify this file according to the license
6
- described in the LICENSE.txt file included in this archive.
7
- =end
8
-
9
- module MiniTest::Ephemeris
10
-
11
- class Ephemeris < MiniTest::TestCase
12
- def test_nothing
13
- end
14
- end
15
-
16
- class CelestialObject < MiniTest::TestCase
17
- def test_nothing
18
- end
19
- end
20
-
21
- class Star < MiniTest::TestCase
22
-
23
- def test_nothing
24
- end
25
-
26
- # 恒星
27
- class Fixed < MiniTest::TestCase
28
- def test__access_hr
29
- polaris = When::Resource('_sc:HR0424')
30
- assert_equal("Alp UMi", polaris.bayer_name)
31
- end
32
- end
33
-
34
- # 春分点
35
- class Vernal < MiniTest::TestCase
36
- def test_nothing
37
- end
38
- end
39
-
40
- # 北極
41
- class Pole < MiniTest::TestCase
42
- def test_nothing
43
- end
44
- end
45
- end
46
-
47
- class Planet < MiniTest::TestCase
48
- def test_nothing
49
- end
50
- end
51
-
52
- class Coords < MiniTest::TestCase
53
- def test_nothing
54
- end
55
- end
56
-
57
- class Formula < MiniTest::TestCase
58
- def test__sunrise
59
-
60
- assert_raises(NoMethodError) { When.when?('2012-11-15').sunrise }
61
-
62
- assert_equal(nil, When.when?('2013-06-21T+09:00', :long=>135, :lat=>70).sunrise)
63
-
64
- if Object.const_defined?(:TZInfo)
65
- assert_equal(0, /2012-11-15T06:16/ =~ When.when?('2012-11-15', :tz=>'Asia/Tokyo').sunrise.to_s)
66
- assert_equal(0, /2012-11-15T06:16/ =~ When.when?('2012-11-15', :tz=>'Asia/Tokyo', :location=>'_l:long=139.7414&lat=35.6581').sunrise.to_s)
67
- else
68
- puts
69
- puts "Tests for TZInfo have been skipped at line #{__LINE__} of #{__FILE__.split(/\//)[-1]}."
70
- end
71
- assert_equal(0, /2012-11-15T06:16/ =~ When.when?('2012-11-15T+09:00', :long=>139.7414, :lat=>35.6581).sunrise.to_s)
72
- assert_equal(0, /2012-11-14T21:16/ =~ When.when?('2012-11-15', :long=>139.7414, :lat=>35.6581).sunrise.to_s)
73
-
74
- today = '2014-3-4'
75
-
76
- location = When.Location('long=139.413012E&lat=35.412222N')
77
- assert_equal(0, /2014-03-03T21:07/ =~ When.when?(today, {:location=>location}).sunrise.to_s)
78
-
79
- When::Coordinates::Spatial.default_location = location
80
- assert_equal(0, /2014-03-03T21:07/ =~ When.when?(today).sunrise.to_s)
81
-
82
- When::TM::Clock.local_time = '+09:00'
83
- assert_equal(0, /2014-03-04T06:07/ =~ When.when?(today).sunrise.to_s)
84
- end
85
-
86
- def test__lunisolar_location
87
- formula1 = When.Resource('_ep:Formula?formula=1L')
88
- formula2 = When.Resource('_ep:Formula?formula=12S')
89
- date = When.when?('2014-08-01', :clock=>'+09:00')
90
- assert_equal('2014-07-27T07:41+09:00', formula1.nearest_past(date).floor(When::MINUTE).to_s)
91
- assert_equal('2014-07-23T06:41+09:00', formula2.nearest_past(date).floor(When::MINUTE).to_s)
92
- assert_equal('2014-07-07T13:15+09:00', formula2.nearest_past(date, 0.5).floor(When::MINUTE).to_s)
93
- end
94
- end
95
-
96
- if Object.const_defined?(:TZInfo)
97
- class Note < MiniTest::TestCase
98
- def test__tide
99
-
100
- sample = [%w(2013-10-02T02:58+09:00 _n:Ephemeris/Notes::day::Tide::Low_Tide),
101
- %w(2013-10-02T09:09+09:00 _n:Ephemeris/Notes::day::Tide::High_Tide),
102
- %w(2013-10-02T15:20+09:00 _n:Ephemeris/Notes::day::Tide::Low_Tide),
103
- %w(2013-10-02T21:32+09:00 _n:Ephemeris/Notes::day::Tide::High_Tide)]
104
-
105
- note = When.CalendarNote('Ephemeris?interval=0.0')
106
- date = When.when?('2013-10-02', :tz=>'Asia/Tokyo')
107
- note.tide(date).each do |d|
108
- assert_equal(sample.shift, [d.floor(When::MINUTE).to_s, d.events[0].iri(true)])
109
- end
110
- end
111
- end
112
- else
113
- puts "Tests for TZInfo have been skipped at line #{__LINE__} of #{__FILE__.split(/\//)[-1]}."
114
- end
115
- end
1
+ # -*- coding: utf-8 -*-
2
+ =begin
3
+ Copyright (C) 2011-2014 Takashi SUGA
4
+
5
+ You may use and/or modify this file according to the license
6
+ described in the LICENSE.txt file included in this archive.
7
+ =end
8
+
9
+ module MiniTest::Ephemeris
10
+
11
+ class Ephemeris < MiniTest::TestCase
12
+ def test_nothing
13
+ end
14
+ end
15
+
16
+ class CelestialObject < MiniTest::TestCase
17
+ def test_nothing
18
+ end
19
+ end
20
+
21
+ class Star < MiniTest::TestCase
22
+
23
+ def test_nothing
24
+ end
25
+
26
+ # 恒星
27
+ class Fixed < MiniTest::TestCase
28
+ def test__access_hr
29
+ polaris = When::Resource('_sc:HR0424')
30
+ assert_equal("Alp UMi", polaris.bayer_name)
31
+ end
32
+ end
33
+
34
+ # 春分点
35
+ class Vernal < MiniTest::TestCase
36
+ def test_nothing
37
+ end
38
+ end
39
+
40
+ # 北極
41
+ class Pole < MiniTest::TestCase
42
+ def test_nothing
43
+ end
44
+ end
45
+ end
46
+
47
+ class Planet < MiniTest::TestCase
48
+ def test_nothing
49
+ end
50
+ end
51
+
52
+ class Coords < MiniTest::TestCase
53
+ def test_nothing
54
+ end
55
+ end
56
+
57
+ class Formula < MiniTest::TestCase
58
+ def test__sunrise
59
+
60
+ assert_raises(NoMethodError) { When.when?('2012-11-15').sunrise }
61
+
62
+ assert_equal(nil, When.when?('2013-06-21T+09:00', :long=>135, :lat=>70).sunrise)
63
+
64
+ if Object.const_defined?(:TZInfo)
65
+ assert_equal(0, /2012-11-15T06:16/ =~ When.when?('2012-11-15', :tz=>'Asia/Tokyo').sunrise.to_s)
66
+ assert_equal(0, /2012-11-15T06:16/ =~ When.when?('2012-11-15', :tz=>'Asia/Tokyo', :location=>'_l:long=139.7414&lat=35.6581').sunrise.to_s)
67
+ else
68
+ puts
69
+ puts "Tests for TZInfo have been skipped at line #{__LINE__} of #{__FILE__.split(/\//)[-1]}."
70
+ end
71
+ assert_equal(0, /2012-11-15T06:16/ =~ When.when?('2012-11-15T+09:00', :long=>139.7414, :lat=>35.6581).sunrise.to_s)
72
+ assert_equal(0, /2012-11-14T21:16/ =~ When.when?('2012-11-15', :long=>139.7414, :lat=>35.6581).sunrise.to_s)
73
+
74
+ today = '2014-3-4'
75
+
76
+ location = When.Location('long=139.413012E&lat=35.412222N')
77
+ assert_equal(0, /2014-03-03T21:07/ =~ When.when?(today, {:location=>location}).sunrise.to_s)
78
+
79
+ When::Coordinates::Spatial.default_location = location
80
+ assert_equal(0, /2014-03-03T21:07/ =~ When.when?(today).sunrise.to_s)
81
+
82
+ When::TM::Clock.local_time = '+09:00'
83
+ assert_equal(0, /2014-03-04T06:07/ =~ When.when?(today).sunrise.to_s)
84
+ end
85
+
86
+ def test__lunisolar_location
87
+ formula1 = When.Resource('_ep:Formula?formula=1L')
88
+ formula2 = When.Resource('_ep:Formula?formula=12S')
89
+ date = When.when?('2014-08-01', :clock=>'+09:00')
90
+ assert_equal('2014-07-27T07:41+09:00', formula1.nearest_past(date).floor(When::MINUTE).to_s)
91
+ assert_equal('2014-07-23T06:41+09:00', formula2.nearest_past(date).floor(When::MINUTE).to_s)
92
+ assert_equal('2014-07-07T13:15+09:00', formula2.nearest_past(date, 0.5).floor(When::MINUTE).to_s)
93
+ end
94
+ end
95
+
96
+ if Object.const_defined?(:TZInfo)
97
+ class Note < MiniTest::TestCase
98
+ def test__tide
99
+
100
+ sample = [%w(2013-10-02T02:58+09:00 _n:Ephemeris/Notes::day::Tide::Low_Tide),
101
+ %w(2013-10-02T09:09+09:00 _n:Ephemeris/Notes::day::Tide::High_Tide),
102
+ %w(2013-10-02T15:20+09:00 _n:Ephemeris/Notes::day::Tide::Low_Tide),
103
+ %w(2013-10-02T21:32+09:00 _n:Ephemeris/Notes::day::Tide::High_Tide)]
104
+
105
+ note = When.CalendarNote('Ephemeris?interval=0.0')
106
+ date = When.when?('2013-10-02', :tz=>'Asia/Tokyo')
107
+ note.tide(date).each do |d|
108
+ assert_equal(sample.shift, [d.floor(When::MINUTE).to_s, d.events[0].iri(true)])
109
+ end
110
+ end
111
+ end
112
+ else
113
+ puts "Tests for TZInfo have been skipped at line #{__LINE__} of #{__FILE__.split(/\//)[-1]}."
114
+ end
115
+ end
@@ -1,14 +1,14 @@
1
- # -*- coding: utf-8 -*-
2
- =begin
3
- Copyright (C) 2011 Takashi SUGA
4
-
5
- You may use and/or modify this file according to the license
6
- described in the LICENSE.txt file included in this archive.
7
- =end
8
-
9
- module MiniTest::Ephemeris
10
- class Moon < MiniTest::TestCase
11
- def test_nothing
12
- end
13
- end
14
- end
1
+ # -*- coding: utf-8 -*-
2
+ =begin
3
+ Copyright (C) 2011 Takashi SUGA
4
+
5
+ You may use and/or modify this file according to the license
6
+ described in the LICENSE.txt file included in this archive.
7
+ =end
8
+
9
+ module MiniTest::Ephemeris
10
+ class Moon < MiniTest::TestCase
11
+ def test_nothing
12
+ end
13
+ end
14
+ end
@@ -1,14 +1,14 @@
1
- # -*- coding: utf-8 -*-
2
- =begin
3
- Copyright (C) 2011 Takashi SUGA
4
-
5
- You may use and/or modify this file according to the license
6
- described in the LICENSE.txt file included in this archive.
7
- =end
8
-
9
- module MiniTest::Ephemeris
10
- class Planets < MiniTest::TestCase
11
- def test_nothing
12
- end
13
- end
14
- end
1
+ # -*- coding: utf-8 -*-
2
+ =begin
3
+ Copyright (C) 2011 Takashi SUGA
4
+
5
+ You may use and/or modify this file according to the license
6
+ described in the LICENSE.txt file included in this archive.
7
+ =end
8
+
9
+ module MiniTest::Ephemeris
10
+ class Planets < MiniTest::TestCase
11
+ def test_nothing
12
+ end
13
+ end
14
+ end
@@ -1,14 +1,14 @@
1
- # -*- coding: utf-8 -*-
2
- =begin
3
- Copyright (C) 2011 Takashi SUGA
4
-
5
- You may use and/or modify this file according to the license
6
- described in the LICENSE.txt file included in this archive.
7
- =end
8
-
9
- module MiniTest::Ephemeris
10
- class Sun < MiniTest::TestCase
11
- def test_nothing
12
- end
13
- end
14
- end
1
+ # -*- coding: utf-8 -*-
2
+ =begin
3
+ Copyright (C) 2011 Takashi SUGA
4
+
5
+ You may use and/or modify this file according to the license
6
+ described in the LICENSE.txt file included in this archive.
7
+ =end
8
+
9
+ module MiniTest::Ephemeris
10
+ class Sun < MiniTest::TestCase
11
+ def test_nothing
12
+ end
13
+ end
14
+ end
data/test/test/inspect.rb CHANGED
@@ -1,153 +1,153 @@
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
10
-
11
- class Inspect < MiniTest::TestCase
12
-
13
- def test__strftime_1
14
- ns = 'ISO, jwiki=http://ja.wikipedia.org/wiki/, ewiki=http://en.wikipedia.org/wiki/'
15
- locale = '=jwiki:, en=ewiki:'
16
- term1 = When::BasicTypes::M17n.new('[月曜, Monday]', ns, locale)
17
- term2 = When::BasicTypes::M17n.new('[です, It is]', ns, locale)
18
- form = When::BasicTypes::M17n.new('[%s%s%2d:, %2$s %1$s%3$2d-]', ns, locale)
19
- assert_equal(["月曜です 1%", "It is Monday 1%"],
20
- ['ja_JP', 'en_US'].map {|c| (form % [term1, term2, When::Coordinates::Pair.new(1,-2)]).translate(c)})
21
-
22
- pair11 = When::Coordinates::Pair.new(1,1)
23
- assert_equal("2:", "%d:" % pair11)
24
- assert_equal("2=", "%d=" % pair11)
25
- assert_equal("1=", When.m17n("%d:") % pair11)
26
-
27
- date = When.when?('2011-02-28T12:34:56+09:00')
28
- assert_equal(["February", {""=>"February", "ja"=>"2月"}], [date.name(-1).to_s, date.name(-1).names])
29
- assert_equal("Mon Feb 28 12:34:56 +0900 2011", date.strftime('%+'))
30
-
31
- date = When.when?('2011-05-17T12:34:56', {:clock=>'+09:00'})
32
- # assert_equal("5月", date.strftime('%.2b').translate('ja'))
33
- assert_equal("05", date.strftime('%m'))
34
- assert_equal("Tue May 17 12:34:56 +0900 2011", date.strftime('%+'))
35
- # assert_equal("火 5月 17 12:34:56 +0900 2011", date.strftime('%+').translate('ja'))
36
-
37
- clock = When.Clock('+09:00')
38
- #pp clock.to_s
39
- assert_equal("+09:00", clock.label.to_s)
40
- assert_equal(nil, clock.referenceEvent)
41
- assert_equal("T00+09:00", clock.referenceTime.to_s)
42
- assert_equal("T*15:00:00Z", clock.utcReference.to_s)
43
- end
44
-
45
- def test__strftime_2
46
- [['%c', 'ja', '2012/04/03 10:14:00'], ['%c', 'fr', '03 avril 2012 10:14:00'],
47
- ['%x', 'ja', '2012/04/03' ], ['%x', 'fr', '03/04/2012' ],
48
- ['%X', 'ja', '10:14:00' ], ['%X', 'fr', '10:14:00' ]
49
- ].each do |sample|
50
- assert_equal(sample[2], When.when?('2012-4-3T10:14:00').
51
- strftime(sample[0], sample[1]))
52
- end
53
- end
54
-
55
- def test__strftime_3
56
- [['DateTime', 'ja', '2012/04/03 10:14:00' ], ['DateTime', 'fr', '03 avril 2012 10:14:00' ],
57
- ['DateTimeLong', 'ja', '2012年04月03日(火) 10時14分00秒 +0000'], ['DateTimeLong', 'fr', 'mardi 03 avril 2012 10:14'],
58
- ['DateTimeShort', 'ja', '12/04/03 10:14' ], ['DateTimeShort', 'fr', '03 avr 10:14' ],
59
- ['Date', 'ja', '2012/04/03' ], ['Date', 'fr', '03/04/2012' ],
60
- ['DateLong', 'ja', '2012年04月03日(火)' ], ['DateLong', 'fr', ' 3 avril 2012' ],
61
- ['DateShort', 'ja', '04/03' ], ['DateShort', 'fr', ' 3 avr' ],
62
- ['Time', 'ja', '10:14:00' ], ['Time', 'fr', '10:14:00' ]
63
- ].each do |sample|
64
- assert_equal(sample[2], When.when?('2012-4-3T10:14:00').
65
- strftime(When.Resource('_m:CalendarFormats::'+sample[0]), sample[1]))
66
- end
67
- end
68
-
69
- def test__name
70
- month = When.when?('AP1393.1.1T12:34:56').name('month')
71
- assert_equal("فروردین", month.translate('ar'))
72
- end
73
-
74
- def test__coordinates
75
- date = When.when?('2012.3=16T12:34:56', {:frame=>When::CalendarTypes::ChineseLuniSolar.new({'time_basis'=>'+09:00'})})
76
- assert_equal(2012, date.year )
77
- assert_equal(When::Coordinates::Pair.new(3,1), date.month)
78
- assert_equal( 16, date.day )
79
- assert_equal( 12, date.hour )
80
- assert_equal( 34, date.minute)
81
- assert_equal( 56, date.second)
82
- assert_equal( 4, date.ymon )
83
- assert_equal( 105, date.yday )
84
- assert_equal( 16, date.mday )
85
- assert_equal( 0, date.wday )
86
- end
87
-
88
- def mweek(dow, day)
89
- dow = (dow + 1) % 7
90
- w,d = (day - 1).divmod(7)
91
- (d < dow) ? w : w+1
92
- end
93
-
94
- def test__term
95
- # [13,14,15].each do |d|
96
- # 7.times do |i|
97
- # p [d, i, mweek(i, d)]
98
- # end
99
- # end
100
- # raise
101
- format = ['%U %w %W %j', '%G-W%V-%u']
102
- 7.times do |i|
103
- 2.times do |k|
104
- [ '1-1' , '1-2' , '1-3' , '1-4' , '1-5' , '1-6' , '1-7' , '1-8' ,
105
- '12-24','12-25','12-26','12-27','12-28','12-29','12-30','12-31',].each do |m|
106
- date1 = When.when?("#{2000+4*i+k}-#{m}")
107
- expr0 = format.map {|f| date1.to_date.strftime(f)}
108
- date2 = When.when?(expr0[1])
109
- expr1 = format.map {|f| date1.strftime(f)}
110
- expr2 = format.map {|f| date2.strftime(f)}
111
- assert_equal([expr0,expr0,mweek(date1.to_i % 7, date1.day)], [expr1,expr2,date1.mweek])
112
- end
113
- end
114
- end
115
- end
116
-
117
- def test__month_included
118
- assert_equal([['December 2013',
119
- ['*', '-', '-', '-', '-', '-', 1, 2],
120
- ['*', 3, 4, 5, 6, 7, 8, 9],
121
- ['*', 10, 11, 12, 13, 14, 15, 16],
122
- ['*', 17, 18, 19, 20, 21, 22, 23],
123
- ['*', 24, 25, 26, 27, 28, 29, 30, 31]]],
124
-
125
- When.when?('2013-12-30').month_included('WorldWeek') {|date, type|
126
- case type
127
- when When::YEAR ; date.strftime('%Y')
128
- when When::MONTH ; date.strftime('%B %Y')
129
- when When::WEEK ; '*'
130
- when When::DAY ; date[When::DAY]
131
- else ; '-'
132
- end
133
- })
134
- end
135
-
136
- def test__round
137
- date = When.when?("2010-09-29T14:45:12.33+09:00")
138
- assert_equal(%w(2010-09-29T14:45:12.33+09:00 2010-09-29T14:45:12+09:00), [date.to_s, date.to_s(3, true)])
139
-
140
- date = When.when?('2013-10-28T23:59:59.999', :clock=>'+09:00', :precision=>3)
141
- assert_equal(%w(2013-10-28T23:59:59+09:00 2013-10-28T24:00:00+09:00), [date.to_s, date.to_s(3, true)])
142
-
143
- date = When.when?('2013-10-28T23:59:59.999', :clock=>'+09:00')
144
- assert_equal(%w(2013-10-28T23:59:59.99+09:00 2013-10-28T24:00:00+09:00), [date.to_s, date.to_s(3, true)])
145
-
146
- date = When.when?('2013-10-28T23:59:29.999', :clock=>'+09:00')
147
- assert_equal(%w(2013-10-28T23:59:29.99+09:00 2013-10-28T23:59+09:00), [date.to_s, date.to_s(2, true)])
148
-
149
- date = When.when?('2013-10-28T23:59:30.001', :clock=>'+09:00')
150
- assert_equal(%w(2013-10-28T23:59:30.00+09:00 2013-10-28T24:00+09:00), [date.to_s, date.to_s(2, true)])
151
- end
152
- end
153
- 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
10
+
11
+ class Inspect < MiniTest::TestCase
12
+
13
+ def test__strftime_1
14
+ ns = 'ISO, jwiki=http://ja.wikipedia.org/wiki/, ewiki=http://en.wikipedia.org/wiki/'
15
+ locale = '=jwiki:, en=ewiki:'
16
+ term1 = When::BasicTypes::M17n.new('[月曜, Monday]', ns, locale)
17
+ term2 = When::BasicTypes::M17n.new('[です, It is]', ns, locale)
18
+ form = When::BasicTypes::M17n.new('[%s%s%2d:, %2$s %1$s%3$2d-]', ns, locale)
19
+ assert_equal(["月曜です 1%", "It is Monday 1%"],
20
+ ['ja_JP', 'en_US'].map {|c| (form % [term1, term2, When::Coordinates::Pair.new(1,-2)]).translate(c)})
21
+
22
+ pair11 = When::Coordinates::Pair.new(1,1)
23
+ assert_equal("2:", "%d:" % pair11)
24
+ assert_equal("2=", "%d=" % pair11)
25
+ assert_equal("1=", When.m17n("%d:") % pair11)
26
+
27
+ date = When.when?('2011-02-28T12:34:56+09:00')
28
+ assert_equal(["February", {""=>"February", "ja"=>"2月"}], [date.name(-1).to_s, date.name(-1).names])
29
+ assert_equal("Mon Feb 28 12:34:56 +0900 2011", date.strftime('%+'))
30
+
31
+ date = When.when?('2011-05-17T12:34:56', {:clock=>'+09:00'})
32
+ # assert_equal("5月", date.strftime('%.2b').translate('ja'))
33
+ assert_equal("05", date.strftime('%m'))
34
+ assert_equal("Tue May 17 12:34:56 +0900 2011", date.strftime('%+'))
35
+ # assert_equal("火 5月 17 12:34:56 +0900 2011", date.strftime('%+').translate('ja'))
36
+
37
+ clock = When.Clock('+09:00')
38
+ #pp clock.to_s
39
+ assert_equal("+09:00", clock.label.to_s)
40
+ assert_equal(nil, clock.referenceEvent)
41
+ assert_equal("T00+09:00", clock.referenceTime.to_s)
42
+ assert_equal("T*15:00:00Z", clock.utcReference.to_s)
43
+ end
44
+
45
+ def test__strftime_2
46
+ [['%c', 'ja', '2012/04/03 10:14:00'], ['%c', 'fr', '03 avril 2012 10:14:00'],
47
+ ['%x', 'ja', '2012/04/03' ], ['%x', 'fr', '03/04/2012' ],
48
+ ['%X', 'ja', '10:14:00' ], ['%X', 'fr', '10:14:00' ]
49
+ ].each do |sample|
50
+ assert_equal(sample[2], When.when?('2012-4-3T10:14:00').
51
+ strftime(sample[0], sample[1]))
52
+ end
53
+ end
54
+
55
+ def test__strftime_3
56
+ [['DateTime', 'ja', '2012/04/03 10:14:00' ], ['DateTime', 'fr', '03 avril 2012 10:14:00' ],
57
+ ['DateTimeLong', 'ja', '2012年04月03日(火) 10時14分00秒 +0000'], ['DateTimeLong', 'fr', 'mardi 03 avril 2012 10:14'],
58
+ ['DateTimeShort', 'ja', '12/04/03 10:14' ], ['DateTimeShort', 'fr', '03 avr 10:14' ],
59
+ ['Date', 'ja', '2012/04/03' ], ['Date', 'fr', '03/04/2012' ],
60
+ ['DateLong', 'ja', '2012年04月03日(火)' ], ['DateLong', 'fr', ' 3 avril 2012' ],
61
+ ['DateShort', 'ja', '04/03' ], ['DateShort', 'fr', ' 3 avr' ],
62
+ ['Time', 'ja', '10:14:00' ], ['Time', 'fr', '10:14:00' ]
63
+ ].each do |sample|
64
+ assert_equal(sample[2], When.when?('2012-4-3T10:14:00').
65
+ strftime(When.Resource('_m:CalendarFormats::'+sample[0]), sample[1]))
66
+ end
67
+ end
68
+
69
+ def test__name
70
+ month = When.when?('AP1393.1.1T12:34:56').name('month')
71
+ assert_equal("فروردین", month.translate('ar'))
72
+ end
73
+
74
+ def test__coordinates
75
+ date = When.when?('2012.3=16T12:34:56', {:frame=>When::CalendarTypes::ChineseLuniSolar.new({'time_basis'=>'+09:00'})})
76
+ assert_equal(2012, date.year )
77
+ assert_equal(When::Coordinates::Pair.new(3,1), date.month)
78
+ assert_equal( 16, date.day )
79
+ assert_equal( 12, date.hour )
80
+ assert_equal( 34, date.minute)
81
+ assert_equal( 56, date.second)
82
+ assert_equal( 4, date.ymon )
83
+ assert_equal( 105, date.yday )
84
+ assert_equal( 16, date.mday )
85
+ assert_equal( 0, date.wday )
86
+ end
87
+
88
+ def mweek(dow, day)
89
+ dow = (dow + 1) % 7
90
+ w,d = (day - 1).divmod(7)
91
+ (d < dow) ? w : w+1
92
+ end
93
+
94
+ def test__term
95
+ # [13,14,15].each do |d|
96
+ # 7.times do |i|
97
+ # p [d, i, mweek(i, d)]
98
+ # end
99
+ # end
100
+ # raise
101
+ format = ['%U %w %W %j', '%G-W%V-%u']
102
+ 7.times do |i|
103
+ 2.times do |k|
104
+ [ '1-1' , '1-2' , '1-3' , '1-4' , '1-5' , '1-6' , '1-7' , '1-8' ,
105
+ '12-24','12-25','12-26','12-27','12-28','12-29','12-30','12-31',].each do |m|
106
+ date1 = When.when?("#{2000+4*i+k}-#{m}")
107
+ expr0 = format.map {|f| date1.to_date.strftime(f)}
108
+ date2 = When.when?(expr0[1])
109
+ expr1 = format.map {|f| date1.strftime(f)}
110
+ expr2 = format.map {|f| date2.strftime(f)}
111
+ assert_equal([expr0,expr0,mweek(date1.to_i % 7, date1.day)], [expr1,expr2,date1.mweek])
112
+ end
113
+ end
114
+ end
115
+ end
116
+
117
+ def test__month_included
118
+ assert_equal([['December 2013',
119
+ ['*', '-', '-', '-', '-', '-', 1, 2],
120
+ ['*', 3, 4, 5, 6, 7, 8, 9],
121
+ ['*', 10, 11, 12, 13, 14, 15, 16],
122
+ ['*', 17, 18, 19, 20, 21, 22, 23],
123
+ ['*', 24, 25, 26, 27, 28, 29, 30, 31]]],
124
+
125
+ When.when?('2013-12-30').month_included('WorldWeek') {|date, type|
126
+ case type
127
+ when When::YEAR ; date.strftime('%Y')
128
+ when When::MONTH ; date.strftime('%B %Y')
129
+ when When::WEEK ; '*'
130
+ when When::DAY ; date[When::DAY]
131
+ else ; '-'
132
+ end
133
+ })
134
+ end
135
+
136
+ def test__round
137
+ date = When.when?("2010-09-29T14:45:12.33+09:00")
138
+ assert_equal(%w(2010-09-29T14:45:12.33+09:00 2010-09-29T14:45:12+09:00), [date.to_s, date.to_s(3, true)])
139
+
140
+ date = When.when?('2013-10-28T23:59:59.999', :clock=>'+09:00', :precision=>3)
141
+ assert_equal(%w(2013-10-28T23:59:59+09:00 2013-10-28T24:00:00+09:00), [date.to_s, date.to_s(3, true)])
142
+
143
+ date = When.when?('2013-10-28T23:59:59.999', :clock=>'+09:00')
144
+ assert_equal(%w(2013-10-28T23:59:59.99+09:00 2013-10-28T24:00:00+09:00), [date.to_s, date.to_s(3, true)])
145
+
146
+ date = When.when?('2013-10-28T23:59:29.999', :clock=>'+09:00')
147
+ assert_equal(%w(2013-10-28T23:59:29.99+09:00 2013-10-28T23:59+09:00), [date.to_s, date.to_s(2, true)])
148
+
149
+ date = When.when?('2013-10-28T23:59:30.001', :clock=>'+09:00')
150
+ assert_equal(%w(2013-10-28T23:59:30.00+09:00 2013-10-28T24:00+09:00), [date.to_s, date.to_s(2, true)])
151
+ end
152
+ end
153
+ end