timesteps 0.9.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,341 @@
1
+ # rspec-power_assert
2
+ require 'timesteps'
3
+ require 'rspec-power_assert'
4
+
5
+ describe "Fixed360Day.new" do
6
+
7
+ example 'full arguments' do
8
+
9
+ is_asserted_by {
10
+ DateTime::Fixed360Day.new(-4712,1,1,0,0,0,0).is_a?(DateTime::Fixed360Day)
11
+ }
12
+
13
+ d = DateTime::Fixed360Day.new(2001, 3, 5, 9, 35, 12.5, 9.quo(24))
14
+
15
+ is_asserted_by { d.year == 2001 }
16
+ is_asserted_by { d.month == 3 }
17
+ is_asserted_by { d.day == 5 }
18
+ is_asserted_by { d.hour == 9 }
19
+ is_asserted_by { d.minute == 35 }
20
+ is_asserted_by { d.second + d.second_fraction == 12.5 }
21
+ is_asserted_by { d.offset == 9.quo(24) }
22
+
23
+ end
24
+
25
+ example 'ommitted arguments' do
26
+
27
+ is_asserted_by {
28
+ DateTime::Fixed360Day.new().is_a?(DateTime::Fixed360Day)
29
+ }
30
+
31
+ d = DateTime::Fixed360Day.new()
32
+
33
+ is_asserted_by { d.year == -4712 }
34
+ is_asserted_by { d.month == 1 }
35
+ is_asserted_by { d.day == 1 }
36
+ is_asserted_by { d.hour == 0 }
37
+ is_asserted_by { d.minute == 0 }
38
+ is_asserted_by { d.second + d.second_fraction == 0.0 }
39
+ is_asserted_by { d.offset == 0 }
40
+
41
+ end
42
+
43
+ example "raised for invalid date" do
44
+
45
+ # leap day for noleap calendar
46
+ is_asserted_by {
47
+ DateTime::Fixed360Day.new(2020,2,29).is_a?(DateTime::Fixed360Day)
48
+ }
49
+
50
+ # date not exist
51
+ expect { DateTime::Fixed360Day.new(2020,1,31) }.to raise_error(RuntimeError)
52
+ expect { DateTime::Fixed360Day.new(2020,3,31) }.to raise_error(RuntimeError)
53
+ expect { DateTime::Fixed360Day.new(2020,5,31) }.to raise_error(RuntimeError)
54
+ expect { DateTime::Fixed360Day.new(2020,7,31) }.to raise_error(RuntimeError)
55
+ expect { DateTime::Fixed360Day.new(2020,8,31) }.to raise_error(RuntimeError)
56
+ expect { DateTime::Fixed360Day.new(2020,10,31) }.to raise_error(RuntimeError)
57
+ expect { DateTime::Fixed360Day.new(2020,12,31) }.to raise_error(RuntimeError)
58
+
59
+ # date not exist
60
+ expect { DateTime::Fixed360Day.new(2020,4,31) }.to raise_error(RuntimeError)
61
+
62
+ end
63
+
64
+ end
65
+
66
+ describe "Fixed360Day.jd" do
67
+
68
+ example "epoch" do
69
+
70
+ d = DateTime::Fixed360Day.jd(0)
71
+ is_asserted_by { d.jd == 0 }
72
+
73
+ end
74
+
75
+ example "unixpoch" do
76
+
77
+ jd = DateTime::Fixed360Day::UNIX_EPOCH_IN_AJD.ceil
78
+
79
+ d = DateTime::Fixed360Day.jd(jd)
80
+ is_asserted_by { d.jd == jd }
81
+ is_asserted_by { d.year == 1970 }
82
+ is_asserted_by { d.month == 1 }
83
+ is_asserted_by { d.day == 1 }
84
+
85
+ end
86
+
87
+ end
88
+
89
+ describe "Fixed360Day#<=>" do
90
+
91
+ example {
92
+
93
+ d1 = DateTime::Fixed360Day.new(2001, 3, 5, 9, 35, 12.5, 9.quo(24))
94
+ d2 = DateTime::Fixed360Day.new(2001, 3, 5, 9, 35, 12.5, 9.quo(24))
95
+
96
+ is_asserted_by { d1 == d2 }
97
+
98
+ }
99
+
100
+ end
101
+
102
+ describe "Fixed360Day.parse_timestamp" do
103
+
104
+ example '2001-03-05T09:35:12.5+09:00' do
105
+
106
+ d1 = DateTime::Fixed360Day.new(2001, 3, 5, 9, 35, 12.5, 9.quo(24))
107
+
108
+ [
109
+ '2001-03-05T09:35:12.5+09:00',
110
+ '2001-03-05 09:35:12.5 +09:00',
111
+ '2001-03-05 09:35:12.5 +0900',
112
+ '2001-03-05 09:35:12.5 +900',
113
+ '2001-03-05 09:35:12.5 +09',
114
+ '2001-03-05 09:35:12.5 +9',
115
+ '2001/03/05 09:35:12.5 +09:00',
116
+ '2001-3-5 9:35:12.5 +09:00',
117
+ '05,Mar,2001 09:35:12.5 +09:00',
118
+ '05-Mar-2001 09:35:12.5 +09:00',
119
+ ].each do |string|
120
+
121
+ d2 = DateTime::Fixed360Day.parse_timestamp(string)
122
+
123
+ is_asserted_by { d2 == d1 }
124
+ end
125
+
126
+ end
127
+
128
+ example 'raise for "2000-02-29"' do
129
+
130
+ # leap day for noleap calendar
131
+ is_asserted_by { DateTime::Fixed360Day.parse_timestamp("2000-2-29").is_a?(DateTime::Fixed360Day) }
132
+
133
+
134
+ end
135
+
136
+ example "with bc option" do
137
+
138
+ d1 = DateTime::Fixed360Day.new(0, 1, 1, 0, 0, 0, 0)
139
+ d2 = DateTime::Fixed360Day.parse_timestamp('BC 0001-1-1 00:00:00')
140
+ d3 = DateTime::Fixed360Day.parse_timestamp('-0001-1-1 00:00:00', bc: true)
141
+
142
+ is_asserted_by { d2 == d1 }
143
+ is_asserted_by { d3 == d1 }
144
+
145
+ end
146
+
147
+ example '2000-12-31 24:00:00' do
148
+
149
+ d1 = DateTime::Fixed360Day.new(2001, 1, 1, 0, 0, 0, 0)
150
+ d2 = DateTime::Fixed360Day.parse_timestamp('2000-12-30 24:00:00')
151
+
152
+ is_asserted_by { d2 == d1 }
153
+
154
+ end
155
+
156
+
157
+ end
158
+
159
+ describe "Fixed360Day#jd" do
160
+
161
+ example 'epoch' do
162
+
163
+ d = DateTime::Fixed360Day.new()
164
+ is_asserted_by { d.jd == 0 }
165
+
166
+ end
167
+
168
+ example 'few-years' do
169
+
170
+ d = DateTime::Fixed360Day.new(-4712,12,30)
171
+ is_asserted_by { d.jd == 359 }
172
+
173
+ d = DateTime::Fixed360Day.new(-4711,1,1)
174
+ is_asserted_by { d.jd == 360 }
175
+
176
+ d = DateTime::Fixed360Day.new(-4708,1,1)
177
+ is_asserted_by { d.jd == 360*4 }
178
+
179
+ d = DateTime::Fixed360Day.new(-4713,1,1)
180
+ is_asserted_by { d.jd == -360 }
181
+
182
+ d = DateTime::Fixed360Day.new(-4716,1,1)
183
+ is_asserted_by { d.jd == -360*4 }
184
+
185
+ end
186
+
187
+ end
188
+
189
+ describe "Fixed360Day#ajd" do
190
+
191
+ example 'epoch' do
192
+
193
+ d = DateTime::Fixed360Day.new()
194
+ is_asserted_by { d.ajd == -1.quo(2) }
195
+
196
+ end
197
+
198
+ example 'few-years' do
199
+
200
+ d = DateTime::Fixed360Day.new(-4712,12,30)
201
+ is_asserted_by { d.ajd == 359-1.quo(2) }
202
+
203
+ d = DateTime::Fixed360Day.new(-4711,1,1)
204
+ is_asserted_by { d.ajd == 360-1.quo(2) }
205
+
206
+ d = DateTime::Fixed360Day.new(-4708,1,1)
207
+ is_asserted_by { d.ajd == 360*4-1.quo(2) }
208
+
209
+ d = DateTime::Fixed360Day.new(-4713,1,1)
210
+ is_asserted_by { d.ajd == -360-1.quo(2) }
211
+
212
+ d = DateTime::Fixed360Day.new(-4716,1,1)
213
+ is_asserted_by { d.ajd == -360*4-1.quo(2) }
214
+
215
+ end
216
+
217
+ end
218
+
219
+ describe "Fixed360Day#strftime" do
220
+
221
+ example 'standard' do
222
+
223
+ d = DateTime::Fixed360Day.new(2001, 3, 5, 9, 35, 12.5, 9.quo(24))
224
+
225
+ is_asserted_by { d.strftime("%FT%T.%L%:z") == "2001-03-05T09:35:12.500+09:00" }
226
+ is_asserted_by { d.strftime("%Y%m%d%H%M%S") == "20010305093512" }
227
+
228
+ end
229
+
230
+ end
231
+
232
+
233
+ describe "Fixed360Day#next_XXX" do
234
+
235
+ example "next_year" do
236
+
237
+ d = DateTime::Fixed360Day.new(2001, 3, 5, 9, 35, 12.5, 9.quo(24))
238
+
239
+ is_asserted_by { d.next_year().year == 2002 }
240
+ is_asserted_by { d.next_year(10).year == 2011 }
241
+
242
+ is_asserted_by { d.prev_year().year == 2000 }
243
+ is_asserted_by { d.prev_year(10).year == 1991 }
244
+
245
+ end
246
+
247
+ example "next_month" do
248
+
249
+ d = DateTime::Fixed360Day.new(2001, 3, 5, 9, 35, 12.5, 9.quo(24))
250
+
251
+ is_asserted_by { d.next_month().month == 4 }
252
+ is_asserted_by { d.next_month(10).month == 1 }
253
+ is_asserted_by { (d>>1).month == 4 }
254
+ is_asserted_by { (d>>10).month == 1 }
255
+
256
+ is_asserted_by { d.prev_month().month == 2 }
257
+ is_asserted_by { d.prev_month(10).month == 5 }
258
+ is_asserted_by { (d<<1).month == 2 }
259
+ is_asserted_by { (d<<10).month == 5 }
260
+
261
+ is_asserted_by { (d>>12).year == 2002 }
262
+ is_asserted_by { (d>>10*12).year == 2011 }
263
+ is_asserted_by { (d<<12).year == 2000 }
264
+ is_asserted_by { (d<<10*12).year == 1991 }
265
+
266
+ end
267
+
268
+ example "next_day" do
269
+
270
+ d = DateTime::Fixed360Day.new(2001, 3, 5, 9, 35, 12.5, 9.quo(24))
271
+
272
+ is_asserted_by { d.next_day().day == 6 }
273
+ is_asserted_by { d.next_day(10).day == 15 }
274
+ is_asserted_by { d.next_day(30).day == 5 }
275
+
276
+ is_asserted_by { (d + 1).day == 6 }
277
+ is_asserted_by { (d + 10).day == 15 }
278
+ is_asserted_by { (d + 30).day == 5 }
279
+
280
+ is_asserted_by { d.prev_day().day == 4 }
281
+ is_asserted_by { d.prev_day(10).day == 25 }
282
+ is_asserted_by { d.prev_day(30).day == 5 }
283
+
284
+ is_asserted_by { (d - 1).day == 4 }
285
+ is_asserted_by { (d - 10).day == 25 }
286
+ is_asserted_by { (d - 30).day == 5 }
287
+
288
+ end
289
+
290
+ end
291
+
292
+ describe "Fixed360Day#fraction" do
293
+
294
+ example do
295
+
296
+ d1 = DateTime::Fixed360Day.new(2001, 3, 5, 9, 35, 12.5, 9.quo(24))
297
+ d2 = DateTime::Fixed360Day.new(2001, 3, 5, 9, 35, 12.893, 9.quo(24))
298
+
299
+ is_asserted_by { d1.fraction == 9.quo(24) + 35.quo(1440) + 12.5.to_r.quo(86400) }
300
+ is_asserted_by { d2.fraction == 9.quo(24) + 35.quo(1440) + 12.893.to_r.quo(86400) }
301
+
302
+ end
303
+
304
+ end
305
+
306
+ describe "Fixed360Day#difference_in_years" do
307
+
308
+ example do
309
+
310
+ d1 = DateTime::Fixed360Day.new(2001, 3, 5, 9, 35, 12.5, 9.quo(24))
311
+ d2 = DateTime::Fixed360Day.new(2002, 3, 4, 9, 35, 12.5, 9.quo(24))
312
+ d3 = DateTime::Fixed360Day.new(2002, 3, 5, 9, 35, 11.5, 9.quo(24))
313
+ d4 = DateTime::Fixed360Day.new(2002, 3, 5, 9, 35, 12.5, 9.quo(24))
314
+
315
+ is_asserted_by { d2.difference_in_years(d1) == 0 }
316
+ is_asserted_by { d3.difference_in_years(d1) == 0 }
317
+ is_asserted_by { d4.difference_in_years(d1) == 1 }
318
+
319
+ end
320
+
321
+ end
322
+
323
+ describe "Fixed360Day#difference_in_months" do
324
+
325
+ example do
326
+
327
+ d1 = DateTime::Fixed360Day.new(2001, 3, 5, 9, 35, 12.5, 9.quo(24))
328
+ d2 = DateTime::Fixed360Day.new(2001, 4, 4, 9, 35, 12.5, 9.quo(24))
329
+ d3 = DateTime::Fixed360Day.new(2001, 4, 5, 9, 35, 11.5, 9.quo(24))
330
+ d4 = DateTime::Fixed360Day.new(2001, 4, 5, 9, 35, 12.5, 9.quo(24))
331
+ d5 = DateTime::Fixed360Day.new(2002, 3, 5, 9, 35, 12.5, 9.quo(24))
332
+
333
+ is_asserted_by { d2.difference_in_months(d1) == 0 }
334
+ is_asserted_by { d3.difference_in_months(d1) == 0 }
335
+ is_asserted_by { d4.difference_in_months(d1) == 1 }
336
+ is_asserted_by { d5.difference_in_months(d1) == 12 }
337
+
338
+ end
339
+
340
+ end
341
+
@@ -0,0 +1,330 @@
1
+ # rspec-power_assert
2
+ require 'timesteps'
3
+ require 'rspec-power_assert'
4
+
5
+ describe "NoLeap.new" do
6
+
7
+ example 'full arguments' do
8
+
9
+ is_asserted_by {
10
+ DateTime::NoLeap.new(-4712,1,1,0,0,0,0).is_a?(DateTime::NoLeap)
11
+ }
12
+
13
+ d = DateTime::NoLeap.new(2001, 3, 5, 9, 35, 12.5, 9.quo(24))
14
+
15
+ is_asserted_by { d.year == 2001 }
16
+ is_asserted_by { d.month == 3 }
17
+ is_asserted_by { d.day == 5 }
18
+ is_asserted_by { d.hour == 9 }
19
+ is_asserted_by { d.minute == 35 }
20
+ is_asserted_by { d.second + d.second_fraction == 12.5 }
21
+ is_asserted_by { d.offset == 9.quo(24) }
22
+
23
+ end
24
+
25
+ example 'ommitted arguments' do
26
+
27
+ is_asserted_by {
28
+ DateTime::NoLeap.new().is_a?(DateTime::NoLeap)
29
+ }
30
+
31
+ d = DateTime::NoLeap.new()
32
+
33
+ is_asserted_by { d.year == -4712 }
34
+ is_asserted_by { d.month == 1 }
35
+ is_asserted_by { d.day == 1 }
36
+ is_asserted_by { d.hour == 0 }
37
+ is_asserted_by { d.minute == 0 }
38
+ is_asserted_by { d.second + d.second_fraction == 0.0 }
39
+ is_asserted_by { d.offset == 0 }
40
+
41
+ end
42
+
43
+ example "raised for invalid date" do
44
+
45
+ # leap day for noleap calendar
46
+ expect { DateTime::NoLeap.new(2020,2,29) }.to raise_error(RuntimeError)
47
+
48
+ # date not exist
49
+ expect { DateTime::NoLeap.new(2020,4,31) }.to raise_error(RuntimeError)
50
+
51
+ end
52
+
53
+ end
54
+
55
+ describe "NoLeap.jd" do
56
+
57
+ example "epoch" do
58
+
59
+ d = DateTime::NoLeap.jd(0)
60
+ is_asserted_by { d.jd == 0 }
61
+
62
+ end
63
+
64
+ example "unixpoch" do
65
+
66
+ jd = DateTime::NoLeap::UNIX_EPOCH_IN_AJD.ceil
67
+
68
+ d = DateTime::NoLeap.jd(jd)
69
+ is_asserted_by { d.jd == jd }
70
+ is_asserted_by { d.year == 1970 }
71
+ is_asserted_by { d.month == 1 }
72
+ is_asserted_by { d.day == 1 }
73
+
74
+ end
75
+
76
+ end
77
+
78
+ describe "NoLeap#<=>" do
79
+
80
+ example {
81
+
82
+ d1 = DateTime::NoLeap.new(2001, 3, 5, 9, 35, 12.5, 9.quo(24))
83
+ d2 = DateTime::NoLeap.new(2001, 3, 5, 9, 35, 12.5, 9.quo(24))
84
+
85
+ is_asserted_by { d1 == d2 }
86
+
87
+ }
88
+
89
+ end
90
+
91
+ describe "NoLeap.parse_timestamp" do
92
+
93
+ example '2001-03-05T09:35:12.5+09:00' do
94
+
95
+ d1 = DateTime::NoLeap.new(2001, 3, 5, 9, 35, 12.5, 9.quo(24))
96
+
97
+ [
98
+ '2001-03-05T09:35:12.5+09:00',
99
+ '2001-03-05 09:35:12.5 +09:00',
100
+ '2001-03-05 09:35:12.5 +0900',
101
+ '2001-03-05 09:35:12.5 +900',
102
+ '2001-03-05 09:35:12.5 +09',
103
+ '2001-03-05 09:35:12.5 +9',
104
+ '2001/03/05 09:35:12.5 +09:00',
105
+ '2001-3-5 9:35:12.5 +09:00',
106
+ '05,Mar,2001 09:35:12.5 +09:00',
107
+ '05-Mar-2001 09:35:12.5 +09:00',
108
+ ].each do |string|
109
+
110
+ d2 = DateTime::NoLeap.parse_timestamp(string)
111
+
112
+ is_asserted_by { d2 == d1 }
113
+ end
114
+
115
+ end
116
+
117
+ example 'raise for "2000-02-29"' do
118
+
119
+ # leap day for noleap calendar
120
+ expect { DateTime::NoLeap.parse_timestamp("2000-2-29") }.to raise_error(RuntimeError)
121
+
122
+ end
123
+
124
+ example "with bc option" do
125
+
126
+ d1 = DateTime::NoLeap.new(0, 1, 1, 0, 0, 0, 0)
127
+ d2 = DateTime::NoLeap.parse_timestamp('BC 0001-1-1 00:00:00')
128
+ d3 = DateTime::NoLeap.parse_timestamp('-0001-1-1 00:00:00', bc: true)
129
+
130
+ is_asserted_by { d2 == d1 }
131
+ is_asserted_by { d3 == d1 }
132
+
133
+ end
134
+
135
+ example '2000-12-31 24:00:00' do
136
+
137
+ d1 = DateTime::NoLeap.new(2001, 1, 1, 0, 0, 0, 0)
138
+ d2 = DateTime::NoLeap.parse_timestamp('2000-12-31 24:00:00')
139
+
140
+ is_asserted_by { d2 == d1 }
141
+
142
+ end
143
+
144
+
145
+ end
146
+
147
+ describe "NoLeap#jd" do
148
+
149
+ example 'epoch' do
150
+
151
+ d = DateTime::NoLeap.new()
152
+ is_asserted_by { d.jd == 0 }
153
+
154
+ end
155
+
156
+ example 'few-years' do
157
+
158
+ d = DateTime::NoLeap.new(-4712,12,31)
159
+ is_asserted_by { d.jd == 364 }
160
+
161
+ d = DateTime::NoLeap.new(-4711,1,1)
162
+ is_asserted_by { d.jd == 365 }
163
+
164
+ d = DateTime::NoLeap.new(-4708,1,1)
165
+ is_asserted_by { d.jd == 365*4 }
166
+
167
+ d = DateTime::NoLeap.new(-4713,1,1)
168
+ is_asserted_by { d.jd == -365 }
169
+
170
+ d = DateTime::NoLeap.new(-4716,1,1)
171
+ is_asserted_by { d.jd == -365*4 }
172
+
173
+ end
174
+
175
+ end
176
+
177
+ describe "NoLeap#ajd" do
178
+
179
+ example 'epoch' do
180
+
181
+ d = DateTime::NoLeap.new()
182
+ is_asserted_by { d.ajd == -1.quo(2) }
183
+
184
+ end
185
+
186
+ example 'few-years' do
187
+
188
+ d = DateTime::NoLeap.new(-4712,12,31)
189
+ is_asserted_by { d.ajd == 364-1.quo(2) }
190
+
191
+ d = DateTime::NoLeap.new(-4711,1,1)
192
+ is_asserted_by { d.ajd == 365-1.quo(2) }
193
+
194
+ d = DateTime::NoLeap.new(-4708,1,1)
195
+ is_asserted_by { d.ajd == 365*4-1.quo(2) }
196
+
197
+ d = DateTime::NoLeap.new(-4713,1,1)
198
+ is_asserted_by { d.ajd == -365-1.quo(2) }
199
+
200
+ d = DateTime::NoLeap.new(-4716,1,1)
201
+ is_asserted_by { d.ajd == -365*4-1.quo(2) }
202
+
203
+ end
204
+
205
+ end
206
+
207
+ describe "NoLeap#strftime" do
208
+
209
+ example 'standard' do
210
+
211
+ d = DateTime::NoLeap.new(2001, 3, 5, 9, 35, 12.5, 9.quo(24))
212
+
213
+ is_asserted_by { d.strftime("%FT%T.%L%:z") == "2001-03-05T09:35:12.500+09:00" }
214
+ is_asserted_by { d.strftime("%Y%m%d%H%M%S") == "20010305093512" }
215
+
216
+ end
217
+
218
+ end
219
+
220
+
221
+ describe "NoLeap#next_XXX" do
222
+
223
+ example "next_year" do
224
+
225
+ d = DateTime::NoLeap.new(2001, 3, 5, 9, 35, 12.5, 9.quo(24))
226
+
227
+ is_asserted_by { d.next_year().year == 2002 }
228
+ is_asserted_by { d.next_year(10).year == 2011 }
229
+
230
+ is_asserted_by { d.prev_year().year == 2000 }
231
+ is_asserted_by { d.prev_year(10).year == 1991 }
232
+
233
+ end
234
+
235
+ example "next_month" do
236
+
237
+ d = DateTime::NoLeap.new(2001, 3, 5, 9, 35, 12.5, 9.quo(24))
238
+
239
+ is_asserted_by { d.next_month().month == 4 }
240
+ is_asserted_by { d.next_month(10).month == 1 }
241
+ is_asserted_by { (d>>1).month == 4 }
242
+ is_asserted_by { (d>>10).month == 1 }
243
+
244
+ is_asserted_by { d.prev_month().month == 2 }
245
+ is_asserted_by { d.prev_month(10).month == 5 }
246
+ is_asserted_by { (d<<1).month == 2 }
247
+ is_asserted_by { (d<<10).month == 5 }
248
+
249
+ is_asserted_by { (d>>12).year == 2002 }
250
+ is_asserted_by { (d>>10*12).year == 2011 }
251
+ is_asserted_by { (d<<12).year == 2000 }
252
+ is_asserted_by { (d<<10*12).year == 1991 }
253
+
254
+ end
255
+
256
+ example "next_day" do
257
+
258
+ d = DateTime::NoLeap.new(2001, 3, 5, 9, 35, 12.5, 9.quo(24))
259
+
260
+ is_asserted_by { d.next_day().day == 6 }
261
+ is_asserted_by { d.next_day(10).day == 15 }
262
+ is_asserted_by { d.next_day(31).day == 5 }
263
+
264
+ is_asserted_by { (d + 1).day == 6 }
265
+ is_asserted_by { (d + 10).day == 15 }
266
+ is_asserted_by { (d + 31).day == 5 }
267
+
268
+ is_asserted_by { d.prev_day().day == 4 }
269
+ is_asserted_by { d.prev_day(10).day == 23 }
270
+ is_asserted_by { d.prev_day(31).day == 2 }
271
+
272
+ is_asserted_by { (d - 1).day == 4 }
273
+ is_asserted_by { (d - 10).day == 23 }
274
+ is_asserted_by { (d - 31).day == 2 }
275
+
276
+ end
277
+
278
+ end
279
+
280
+ describe "NoLeap#fraction" do
281
+
282
+ example do
283
+
284
+ d1 = DateTime::NoLeap.new(2001, 3, 5, 9, 35, 12.5, 9.quo(24))
285
+ d2 = DateTime::NoLeap.new(2001, 3, 5, 9, 35, 12.893, 9.quo(24))
286
+
287
+ is_asserted_by { d1.fraction == 9.quo(24) + 35.quo(1440) + 12.5.to_r.quo(86400) }
288
+ is_asserted_by { d2.fraction == 9.quo(24) + 35.quo(1440) + 12.893.to_r.quo(86400) }
289
+
290
+ end
291
+
292
+ end
293
+
294
+ describe "NoLeap#difference_in_years" do
295
+
296
+ example do
297
+
298
+ d1 = DateTime::NoLeap.new(2001, 3, 5, 9, 35, 12.5, 9.quo(24))
299
+ d2 = DateTime::NoLeap.new(2002, 3, 4, 9, 35, 12.5, 9.quo(24))
300
+ d3 = DateTime::NoLeap.new(2002, 3, 5, 9, 35, 11.5, 9.quo(24))
301
+ d4 = DateTime::NoLeap.new(2002, 3, 5, 9, 35, 12.5, 9.quo(24))
302
+
303
+ is_asserted_by { d2.difference_in_years(d1) == 0 }
304
+ is_asserted_by { d3.difference_in_years(d1) == 0 }
305
+ is_asserted_by { d4.difference_in_years(d1) == 1 }
306
+
307
+ end
308
+
309
+ end
310
+
311
+ describe "NoLeap#new_offset" do
312
+
313
+ example do
314
+
315
+ d1 = DateTime::NoLeap.new(2001, 3, 5, 9, 35, 12.5, 9.quo(24))
316
+
317
+ d2 = d1.new_offset(0)
318
+ d3 = DateTime::NoLeap.new(2001, 3, 5, 0, 35, 12.5, 0)
319
+
320
+ is_asserted_by { d2 == d3 }
321
+
322
+ d4 = d1.new_offset(-9.quo(24))
323
+ d5 = DateTime::NoLeap.new(2001, 3, 4, 15, 35, 12.5, -9.quo(24))
324
+
325
+ is_asserted_by { d4 == d5 }
326
+
327
+ end
328
+
329
+ end
330
+