timesteps 0.9.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSES +22 -0
- data/Note.ja.md +76 -0
- data/README.md +57 -0
- data/Rakefile +11 -0
- data/lib/timesteps/calendar.rb +104 -0
- data/lib/timesteps/datetimelike.rb +530 -0
- data/lib/timesteps/format.rb +251 -0
- data/lib/timesteps/grads.rb +43 -0
- data/lib/timesteps/parse_timestamp.rb +48 -0
- data/lib/timesteps/timestep.rb +362 -0
- data/lib/timesteps/timestepconverter.rb +63 -0
- data/lib/timesteps/timestepdatetimeext.rb +79 -0
- data/lib/timesteps/timesteppair.rb +202 -0
- data/lib/timesteps.rb +10 -0
- data/spec/allleap_spec.rb +330 -0
- data/spec/fixed360day_spec.rb +341 -0
- data/spec/noleap_spec.rb +330 -0
- data/spec/timestep_spec.rb +405 -0
- data/spec/timesteppair_spec.rb +99 -0
- data/timesteps.gemspec +26 -0
- metadata +64 -0
@@ -0,0 +1,405 @@
|
|
1
|
+
# rspec-power_assert
|
2
|
+
require 'timesteps'
|
3
|
+
require 'rspec-power_assert'
|
4
|
+
|
5
|
+
unless defined? CALENDAR_NAMES
|
6
|
+
CALENDAR_NAMES = [
|
7
|
+
"standard",
|
8
|
+
"proleptic_gregorian",
|
9
|
+
"proleptic_julian",
|
10
|
+
"noleap",
|
11
|
+
"allleap",
|
12
|
+
"360_day"
|
13
|
+
]
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "TimeStep.new" do
|
17
|
+
|
18
|
+
example 'origin' do
|
19
|
+
|
20
|
+
spec = "1 days since 2001-02-03 04:05:06 +07:00"
|
21
|
+
tests = [
|
22
|
+
[spec, "standard", DateTime.new(2001,2,3,4,5,6,7.quo(24),Date::ITALY)],
|
23
|
+
[spec, "gregorian", DateTime.new(2001,2,3,4,5,6,7.quo(24),Date::ITALY)],
|
24
|
+
[spec, "proleptic_gregorian", DateTime.new(2001,2,3,4,5,6,7.quo(24),Date::GREGORIAN)],
|
25
|
+
[spec, "proleptic_julian", DateTime.new(2001,2,3,4,5,6,7.quo(24),Date::JULIAN)],
|
26
|
+
[spec, "noleap", DateTime::NoLeap.new(2001,2,3,4,5,6,7.quo(24))],
|
27
|
+
[spec, "365_day", DateTime::NoLeap.new(2001,2,3,4,5,6,7.quo(24))],
|
28
|
+
[spec, "allleap", DateTime::AllLeap.new(2001,2,3,4,5,6,7.quo(24))],
|
29
|
+
[spec, "366_day", DateTime::AllLeap.new(2001,2,3,4,5,6,7.quo(24))],
|
30
|
+
[spec, "360_day", DateTime::Fixed360Day.new(2001,2,3,4,5,6,7.quo(24))],
|
31
|
+
]
|
32
|
+
|
33
|
+
tests.each do |spec, calendar, date|
|
34
|
+
|
35
|
+
ts = TimeStep.new(spec, calendar: calendar)
|
36
|
+
|
37
|
+
is_asserted_by { ts.origin == date }
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
example 'interval' do
|
44
|
+
|
45
|
+
tests = [
|
46
|
+
["year since 2001-02-03 04:05:06 +07:00", 1, :years],
|
47
|
+
["month since 2001-02-03 04:05:06 +07:00", 1, :months],
|
48
|
+
["day since 2001-02-03 04:05:06 +07:00", 1, :days],
|
49
|
+
["hour since 2001-02-03 04:05:06 +07:00", 1, :hours],
|
50
|
+
["minute since 2001-02-03 04:05:06 +07:00", 1, :minutes],
|
51
|
+
["second since 2001-02-03 04:05:06 +07:00", 1, :seconds],
|
52
|
+
|
53
|
+
["d since 2001-02-03 04:05:06 +07:00", 1, :days],
|
54
|
+
["hr since 2001-02-03 04:05:06 +07:00", 1, :hours],
|
55
|
+
["h since 2001-02-03 04:05:06 +07:00", 1, :hours],
|
56
|
+
["min since 2001-02-03 04:05:06 +07:00", 1, :minutes],
|
57
|
+
["sec since 2001-02-03 04:05:06 +07:00", 1, :seconds],
|
58
|
+
["s since 2001-02-03 04:05:06 +07:00", 1, :seconds],
|
59
|
+
|
60
|
+
["3 years since 2001-02-03 04:05:06 +07:00", 3, :years],
|
61
|
+
["3 months since 2001-02-03 04:05:06 +07:00", 3, :months],
|
62
|
+
["3 days since 2001-02-03 04:05:06 +07:00", 3, :days],
|
63
|
+
["3 hours since 2001-02-03 04:05:06 +07:00", 3, :hours],
|
64
|
+
["3 minutes since 2001-02-03 04:05:06 +07:00", 3, :minutes],
|
65
|
+
["3 seconds since 2001-02-03 04:05:06 +07:00", 3, :seconds],
|
66
|
+
|
67
|
+
["3 years since 2001-02-03 04:05:06 +07:00", 3, :years],
|
68
|
+
["3 months since 2001-02-03 04:05:06 +07:00", 3, :months],
|
69
|
+
["3 days since 2001-02-03 04:05:06 +07:00", 3, :days],
|
70
|
+
["3 hours since 2001-02-03 04:05:06 +07:00", 3, :hours],
|
71
|
+
["3 minutes since 2001-02-03 04:05:06 +07:00", 3, :minutes],
|
72
|
+
["3 seconds since 2001-02-03 04:05:06 +07:00", 3, :seconds],
|
73
|
+
|
74
|
+
["3years since 2001-02-03 04:05:06 +07:00", 3, :years],
|
75
|
+
["3months since 2001-02-03 04:05:06 +07:00", 3, :months],
|
76
|
+
["3days since 2001-02-03 04:05:06 +07:00", 3, :days],
|
77
|
+
["3hours since 2001-02-03 04:05:06 +07:00", 3, :hours],
|
78
|
+
["3minutes since 2001-02-03 04:05:06 +07:00", 3, :minutes],
|
79
|
+
["3seconds since 2001-02-03 04:05:06 +07:00", 3, :seconds],
|
80
|
+
|
81
|
+
["60 years since 2001-02-03 04:05:06 +07:00", 60, :years],
|
82
|
+
["60 months since 2001-02-03 04:05:06 +07:00", 60, :months],
|
83
|
+
["60 days since 2001-02-03 04:05:06 +07:00", 60, :days],
|
84
|
+
["60 hours since 2001-02-03 04:05:06 +07:00", 60, :hours],
|
85
|
+
["60 minutes since 2001-02-03 04:05:06 +07:00", 60, :minutes],
|
86
|
+
["60 seconds since 2001-02-03 04:05:06 +07:00", 60, :seconds],
|
87
|
+
|
88
|
+
["-3 years since 2001-02-03 04:05:06 +07:00", -3, :years],
|
89
|
+
["-3 months since 2001-02-03 04:05:06 +07:00", -3, :months],
|
90
|
+
["-3 days since 2001-02-03 04:05:06 +07:00", -3, :days],
|
91
|
+
["-3 hours since 2001-02-03 04:05:06 +07:00", -3, :hours],
|
92
|
+
["-3 minutes since 2001-02-03 04:05:06 +07:00", -3, :minutes],
|
93
|
+
["-3 seconds since 2001-02-03 04:05:06 +07:00", -3, :seconds],
|
94
|
+
|
95
|
+
["3.5 days since 2001-02-03 04:05:06 +07:00", 3.5, :days],
|
96
|
+
["3.5 hours since 2001-02-03 04:05:06 +07:00", 3.5, :hours],
|
97
|
+
["3.5 minutes since 2001-02-03 04:05:06 +07:00", 3.5, :minutes],
|
98
|
+
["3.5 seconds since 2001-02-03 04:05:06 +07:00", 3.5, :seconds],
|
99
|
+
|
100
|
+
["3.5e2 days since 2001-02-03 04:05:06 +07:00", 3.5e2, :days],
|
101
|
+
["3.5e2 hours since 2001-02-03 04:05:06 +07:00", 3.5e2, :hours],
|
102
|
+
["3.5e2 minutes since 2001-02-03 04:05:06 +07:00", 3.5e2, :minutes],
|
103
|
+
["3.5e2 seconds since 2001-02-03 04:05:06 +07:00", 3.5e2, :seconds],
|
104
|
+
|
105
|
+
["3.5e21 days since 2001-02-03 04:05:06 +07:00", 3.5e21, :days],
|
106
|
+
["3.5e21 hours since 2001-02-03 04:05:06 +07:00", 3.5e21, :hours],
|
107
|
+
["3.5e21 minutes since 2001-02-03 04:05:06 +07:00", 3.5e21, :minutes],
|
108
|
+
["3.5e21 seconds since 2001-02-03 04:05:06 +07:00", 3.5e21, :seconds],
|
109
|
+
|
110
|
+
["3.5e-2 days since 2001-02-03 04:05:06 +07:00", 3.5e-2, :days],
|
111
|
+
["3.5e-2 hours since 2001-02-03 04:05:06 +07:00", 3.5e-2, :hours],
|
112
|
+
["3.5e-2 minutes since 2001-02-03 04:05:06 +07:00", 3.5e-2, :minutes],
|
113
|
+
["3.5e-2 seconds since 2001-02-03 04:05:06 +07:00", 3.5e-2, :seconds],
|
114
|
+
]
|
115
|
+
|
116
|
+
tests.each do |spec, numeric, symbol|
|
117
|
+
ts = TimeStep.new(spec)
|
118
|
+
|
119
|
+
is_asserted_by { ts.numeric == numeric }
|
120
|
+
is_asserted_by { ts.symbol == symbol }
|
121
|
+
end
|
122
|
+
|
123
|
+
end
|
124
|
+
|
125
|
+
end
|
126
|
+
|
127
|
+
describe "TimeStep#time_at" do
|
128
|
+
|
129
|
+
|
130
|
+
example 'invalid argument' do
|
131
|
+
|
132
|
+
ts = TimeStep.new("1 seconds since 2001-02-03 04:05:06 +07:00")
|
133
|
+
|
134
|
+
expect { ts.time_at("string") }.to raise_error(ArgumentError)
|
135
|
+
|
136
|
+
end
|
137
|
+
|
138
|
+
|
139
|
+
example 'seconds' do
|
140
|
+
|
141
|
+
CALENDAR_NAMES.each do |calendar|
|
142
|
+
|
143
|
+
ts = TimeStep.new("1 seconds since 2001-02-03 04:05:06 +07:00", calendar: calendar)
|
144
|
+
|
145
|
+
is_asserted_by { ts.time_at(0) == ts.origin }
|
146
|
+
is_asserted_by { ts.time_at(1) == ts.origin + 1.quo(86400) }
|
147
|
+
is_asserted_by { ts.time_at(1000000) == ts.origin + 1000000.quo(86400) }
|
148
|
+
is_asserted_by { ts.time_at(-1) == ts.origin - 1.quo(86400) }
|
149
|
+
is_asserted_by { ts.time_at(-1000000) == ts.origin - 1000000.quo(86400) }
|
150
|
+
|
151
|
+
end
|
152
|
+
|
153
|
+
end
|
154
|
+
|
155
|
+
example 'days' do
|
156
|
+
|
157
|
+
CALENDAR_NAMES.each do |calendar|
|
158
|
+
|
159
|
+
ts = TimeStep.new("1 days since 2001-02-03 04:05:06 +07:00", calendar: calendar)
|
160
|
+
|
161
|
+
is_asserted_by { ts.time_at(0) == ts.origin }
|
162
|
+
is_asserted_by { ts.time_at(1) == ts.origin.next_day(1) }
|
163
|
+
is_asserted_by { ts.time_at(366) == ts.origin.next_day(366) }
|
164
|
+
is_asserted_by { ts.time_at(-1) == ts.origin.prev_day(1) }
|
165
|
+
is_asserted_by { ts.time_at(-366) == ts.origin.prev_day(366) }
|
166
|
+
|
167
|
+
is_asserted_by { ts.time_at(1.5) == (ts.origin + 1.5) }
|
168
|
+
is_asserted_by { ts.time_at(-1.5) == (ts.origin - 1.5) }
|
169
|
+
|
170
|
+
end
|
171
|
+
|
172
|
+
end
|
173
|
+
|
174
|
+
example 'months' do
|
175
|
+
|
176
|
+
CALENDAR_NAMES.each do |calendar|
|
177
|
+
|
178
|
+
ts = TimeStep.new("1 months since 2001-02-03 04:05:06 +07:00", calendar: calendar)
|
179
|
+
|
180
|
+
is_asserted_by { ts.time_at(0) == ts.origin }
|
181
|
+
is_asserted_by { ts.time_at(1) == ts.origin.next_month(1) }
|
182
|
+
is_asserted_by { ts.time_at(366) == ts.origin.next_month(366) }
|
183
|
+
is_asserted_by { ts.time_at(-1) == ts.origin.prev_month(1) }
|
184
|
+
is_asserted_by { ts.time_at(-366) == ts.origin.prev_month(366) }
|
185
|
+
|
186
|
+
# months timestep don't permit fractional index
|
187
|
+
expect { ts.time_at(1.5) }.to raise_error(RuntimeError)
|
188
|
+
|
189
|
+
end
|
190
|
+
|
191
|
+
end
|
192
|
+
|
193
|
+
example 'years' do
|
194
|
+
|
195
|
+
CALENDAR_NAMES.each do |calendar|
|
196
|
+
|
197
|
+
ts = TimeStep.new("1 years since 2001-02-03 04:05:06 +07:00", calendar: calendar)
|
198
|
+
|
199
|
+
is_asserted_by { ts.time_at(0) == ts.origin }
|
200
|
+
is_asserted_by { ts.time_at(1) == ts.origin.next_year(1) }
|
201
|
+
is_asserted_by { ts.time_at(366) == ts.origin.next_year(366) }
|
202
|
+
is_asserted_by { ts.time_at(-1) == ts.origin.prev_year(1) }
|
203
|
+
is_asserted_by { ts.time_at(-366) == ts.origin.prev_year(366) }
|
204
|
+
|
205
|
+
# years timestep don't permit fractional index
|
206
|
+
expect { ts.time_at(1.5) }.to raise_error(RuntimeError)
|
207
|
+
|
208
|
+
end
|
209
|
+
|
210
|
+
end
|
211
|
+
|
212
|
+
end
|
213
|
+
|
214
|
+
describe "TimeStep#index_at" do
|
215
|
+
|
216
|
+
example 'seconds' do
|
217
|
+
|
218
|
+
CALENDAR_NAMES.each do |calendar|
|
219
|
+
|
220
|
+
ts = TimeStep.new("1 seconds since 2001-02-03 04:05:06 +07:00", calendar: calendar)
|
221
|
+
|
222
|
+
is_asserted_by { ts.index_at( ts.origin ) == 0 }
|
223
|
+
is_asserted_by { ts.index_at( ts.origin + 1.quo(86400) ) == 1 }
|
224
|
+
is_asserted_by { ts.index_at( ts.origin + 100.quo(86400) ) == 100 }
|
225
|
+
is_asserted_by { ts.index_at( ts.origin + 0.5.to_r.quo(86400) ) == 0.5 }
|
226
|
+
is_asserted_by { ts.index_at( ts.origin - 0.5.to_r.quo(86400) ) == -0.5 }
|
227
|
+
|
228
|
+
end
|
229
|
+
|
230
|
+
end
|
231
|
+
|
232
|
+
example 'days' do
|
233
|
+
|
234
|
+
CALENDAR_NAMES.each do |calendar|
|
235
|
+
|
236
|
+
ts = TimeStep.new("1 days since 2001-02-03 04:05:06 +07:00", calendar: calendar)
|
237
|
+
|
238
|
+
is_asserted_by { ts.index_at( ts.origin ) == 0 }
|
239
|
+
is_asserted_by { ts.index_at( ts.origin + 1 ) == 1 }
|
240
|
+
is_asserted_by { ts.index_at( ts.origin + 100 ) == 100 }
|
241
|
+
is_asserted_by { ts.index_at( ts.origin + 0.5 ) == 0.5 }
|
242
|
+
is_asserted_by { ts.index_at( ts.origin - 0.5 ) == -0.5 }
|
243
|
+
|
244
|
+
end
|
245
|
+
|
246
|
+
end
|
247
|
+
|
248
|
+
example 'months' do
|
249
|
+
|
250
|
+
CALENDAR_NAMES.each do |calendar|
|
251
|
+
|
252
|
+
ts = TimeStep.new("1 months since 2001-02-03 04:05:06 +07:00", calendar: calendar)
|
253
|
+
|
254
|
+
is_asserted_by { ts.index_at( ts.origin ) == 0 }
|
255
|
+
is_asserted_by { ts.index_at( ts.origin.next_month(1) ) == 1 }
|
256
|
+
is_asserted_by { ts.index_at( ts.origin.next_month(100) ) == 100 }
|
257
|
+
is_asserted_by { ts.index_at( ts.origin.prev_month(1) ) == -1 }
|
258
|
+
is_asserted_by { ts.index_at( ts.origin.prev_month(100) ) == -100 }
|
259
|
+
|
260
|
+
end
|
261
|
+
|
262
|
+
end
|
263
|
+
|
264
|
+
example 'years' do
|
265
|
+
|
266
|
+
CALENDAR_NAMES.each do |calendar|
|
267
|
+
|
268
|
+
ts = TimeStep.new("1 years since 2001-02-03 04:05:06 +07:00", calendar: calendar)
|
269
|
+
|
270
|
+
is_asserted_by { ts.index_at( ts.origin ) == 0 }
|
271
|
+
is_asserted_by { ts.index_at( ts.origin.next_year(1) ) == 1 }
|
272
|
+
is_asserted_by { ts.index_at( ts.origin.next_year(100) ) == 100 }
|
273
|
+
is_asserted_by { ts.index_at( ts.origin.prev_year(1) ) == -1 }
|
274
|
+
is_asserted_by { ts.index_at( ts.origin.prev_year(100) ) == -100 }
|
275
|
+
is_asserted_by { ts.index_at( ts.origin.next_year(1) - 1 ) == 0 }
|
276
|
+
is_asserted_by { ts.index_at( ts.origin.next_year(100) - 1 ) == 99 }
|
277
|
+
is_asserted_by { ts.index_at( ts.origin.prev_year(1) + 1 ) == 0 }
|
278
|
+
is_asserted_by { ts.index_at( ts.origin.prev_year(100) + 1 ) == -99 }
|
279
|
+
|
280
|
+
end
|
281
|
+
|
282
|
+
end
|
283
|
+
|
284
|
+
end
|
285
|
+
|
286
|
+
describe "TimeStep#days_at" do
|
287
|
+
|
288
|
+
example 'seconds' do
|
289
|
+
|
290
|
+
CALENDAR_NAMES.each do |calendar|
|
291
|
+
|
292
|
+
ts = TimeStep.new("1 seconds since 2001-02-03 04:05:06 +07:00", calendar: calendar)
|
293
|
+
|
294
|
+
is_asserted_by { ts.days_at( 1 ) == 1.quo(86400) }
|
295
|
+
is_asserted_by { ts.days_at( 100 ) == 100.quo(86400) }
|
296
|
+
is_asserted_by { ts.days_at( 0.5 ) == 0.5.to_r.quo(86400) }
|
297
|
+
is_asserted_by { ts.days_at( -0.5 ) == -0.5.to_r.quo(86400) }
|
298
|
+
|
299
|
+
end
|
300
|
+
|
301
|
+
end
|
302
|
+
|
303
|
+
example 'days' do
|
304
|
+
|
305
|
+
CALENDAR_NAMES.each do |calendar|
|
306
|
+
|
307
|
+
ts = TimeStep.new("1 days since 2001-02-03 04:05:06 +07:00", calendar: calendar)
|
308
|
+
|
309
|
+
is_asserted_by { ts.days_at( 1 ) == 1 }
|
310
|
+
is_asserted_by { ts.days_at( 100 ) == 100 }
|
311
|
+
is_asserted_by { ts.days_at( 0.5 ) == 0.5 }
|
312
|
+
is_asserted_by { ts.days_at( -0.5 ) == -0.5 }
|
313
|
+
|
314
|
+
end
|
315
|
+
|
316
|
+
end
|
317
|
+
|
318
|
+
example 'months' do
|
319
|
+
|
320
|
+
CALENDAR_NAMES.each do |calendar|
|
321
|
+
|
322
|
+
ts = TimeStep.new("1 months since 2001-02-03 04:05:06 +07:00", calendar: calendar)
|
323
|
+
|
324
|
+
is_asserted_by { ts.days_at( 1 ) == ts.origin.next_month - ts.origin }
|
325
|
+
is_asserted_by { ts.days_at( 100 ) == ts.origin.next_month(100) - ts.origin }
|
326
|
+
is_asserted_by { ts.days_at( -1 ) == ts.origin.prev_month - ts.origin }
|
327
|
+
is_asserted_by { ts.days_at( -100 ) == ts.origin.prev_month(100) - ts.origin }
|
328
|
+
|
329
|
+
end
|
330
|
+
|
331
|
+
end
|
332
|
+
|
333
|
+
example 'years' do
|
334
|
+
|
335
|
+
CALENDAR_NAMES.each do |calendar|
|
336
|
+
|
337
|
+
ts = TimeStep.new("1 years since 2001-02-03 04:05:06 +07:00", calendar: calendar)
|
338
|
+
|
339
|
+
is_asserted_by { ts.days_at( 1 ) == ts.origin.next_year - ts.origin }
|
340
|
+
is_asserted_by { ts.days_at( 100 ) == ts.origin.next_year(100) - ts.origin }
|
341
|
+
is_asserted_by { ts.days_at( -1 ) == ts.origin.prev_year - ts.origin }
|
342
|
+
is_asserted_by { ts.days_at( -100 ) == ts.origin.prev_year(100) - ts.origin }
|
343
|
+
|
344
|
+
end
|
345
|
+
|
346
|
+
end
|
347
|
+
|
348
|
+
end
|
349
|
+
|
350
|
+
describe "TimeStep#shift_origin" do
|
351
|
+
|
352
|
+
example do
|
353
|
+
|
354
|
+
CALENDAR_NAMES.each do |calendar|
|
355
|
+
|
356
|
+
ts = TimeStep.new("1 years since 2001-02-03 04:05:06 +07:00", calendar: calendar)
|
357
|
+
|
358
|
+
is_asserted_by { ts.shift_origin(1).origin == ts.time_at(1) }
|
359
|
+
|
360
|
+
end
|
361
|
+
|
362
|
+
end
|
363
|
+
|
364
|
+
end
|
365
|
+
|
366
|
+
describe "TimeStep#new_origin" do
|
367
|
+
|
368
|
+
example do
|
369
|
+
|
370
|
+
CALENDAR_NAMES.each do |calendar|
|
371
|
+
|
372
|
+
ts = TimeStep.new("1 years since 2001-02-03 04:05:06 +07:00", calendar: calendar)
|
373
|
+
d = ts.time_at(1)
|
374
|
+
|
375
|
+
is_asserted_by { ts.new_origin(d).origin == d }
|
376
|
+
|
377
|
+
end
|
378
|
+
|
379
|
+
end
|
380
|
+
|
381
|
+
end
|
382
|
+
|
383
|
+
describe "TimeStep#limit" do
|
384
|
+
|
385
|
+
example do
|
386
|
+
|
387
|
+
CALENDAR_NAMES.each do |calendar|
|
388
|
+
|
389
|
+
ts = TimeStep.new("1 hours since 2001-02-03 04:05:06 +07:00", calendar: calendar, count: 31)
|
390
|
+
is_asserted_by { ts.limit == ts.time_at(30) }
|
391
|
+
|
392
|
+
ts = TimeStep.new("1 hours since 2001-02-03 04:05:06 +07:00", calendar: calendar)
|
393
|
+
ts.count = 31
|
394
|
+
is_asserted_by { ts.limit == ts.time_at(30) }
|
395
|
+
|
396
|
+
ts = TimeStep.new("1 hours since 2001-02-03 04:05:06 +07:00", calendar: calendar)
|
397
|
+
ts.limit = ts.time_at(30)
|
398
|
+
is_asserted_by { ts.count == 31 }
|
399
|
+
|
400
|
+
end
|
401
|
+
|
402
|
+
end
|
403
|
+
|
404
|
+
end
|
405
|
+
|
@@ -0,0 +1,99 @@
|
|
1
|
+
# rspec-power_assert
|
2
|
+
require 'timesteps'
|
3
|
+
require 'rspec-power_assert'
|
4
|
+
|
5
|
+
describe "TimeStep::Pair.new" do
|
6
|
+
|
7
|
+
example "spec" do
|
8
|
+
|
9
|
+
spec1 = "1 days since 2001-02-03 04:05:06 +07:00"
|
10
|
+
spec2 = "1 hours since 2001-02-03 04:05:06 +07:00"
|
11
|
+
|
12
|
+
pair = TimeStep::Pair.new(spec1, spec2)
|
13
|
+
|
14
|
+
ts1 = TimeStep.new(spec1)
|
15
|
+
ts2 = TimeStep.new(spec2)
|
16
|
+
|
17
|
+
is_asserted_by { pair.from == ts1 }
|
18
|
+
is_asserted_by { pair.to == ts2 }
|
19
|
+
is_asserted_by { pair.difference == 0 }
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "TimeStep::Pair#forward" do
|
26
|
+
|
27
|
+
example "different hours" do
|
28
|
+
|
29
|
+
spec1 = "1 hours since 2001-02-03 04:05:06 +07:00"
|
30
|
+
spec2 = "3 hours since 2001-02-02 04:05:06 +07:00"
|
31
|
+
|
32
|
+
pair = TimeStep::Pair.new(spec1, spec2)
|
33
|
+
|
34
|
+
is_asserted_by { pair.forward(0) == 24.quo(3) }
|
35
|
+
is_asserted_by { pair.forward(1) == 25.quo(3) }
|
36
|
+
is_asserted_by { pair.forward(24) == 48.quo(3) }
|
37
|
+
is_asserted_by { pair.forward(1.5) == (51.quo(2)).quo(3) }
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
example "different days" do
|
42
|
+
|
43
|
+
spec1 = "3 days since 2001-02-03 04:05:06 +07:00"
|
44
|
+
spec2 = "1 days since 2001-02-02 04:05:06 +07:00"
|
45
|
+
|
46
|
+
pair = TimeStep::Pair.new(spec1, spec2)
|
47
|
+
|
48
|
+
is_asserted_by { pair.forward(0) == 1 }
|
49
|
+
is_asserted_by { pair.forward(1) == 4 }
|
50
|
+
is_asserted_by { pair.forward(10) == 31 }
|
51
|
+
is_asserted_by { pair.forward(1.5) == 11.quo(2) }
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
example "different months" do
|
56
|
+
|
57
|
+
spec1 = "3 months since 2001-02-03 04:05:06 +07:00"
|
58
|
+
spec2 = "1 months since 2001-01-03 04:05:06 +07:00"
|
59
|
+
|
60
|
+
pair = TimeStep::Pair.new(spec1, spec2)
|
61
|
+
|
62
|
+
is_asserted_by { pair.forward(0) == 1 }
|
63
|
+
is_asserted_by { pair.forward(1) == 4 }
|
64
|
+
is_asserted_by { pair.forward(10) == 31 }
|
65
|
+
|
66
|
+
expect { pair.forward(1.5) }.to raise_error(RuntimeError)
|
67
|
+
end
|
68
|
+
|
69
|
+
example "different years" do
|
70
|
+
|
71
|
+
spec1 = "3 years since 2001-02-03 04:05:06 +07:00"
|
72
|
+
spec2 = "1 years since 2000-02-03 04:05:06 +07:00"
|
73
|
+
|
74
|
+
pair = TimeStep::Pair.new(spec1, spec2)
|
75
|
+
|
76
|
+
is_asserted_by { pair.forward(0) == 1 }
|
77
|
+
is_asserted_by { pair.forward(1) == 4 }
|
78
|
+
is_asserted_by { pair.forward(10) == 31 }
|
79
|
+
|
80
|
+
expect { pair.forward(1.5) }.to raise_error(RuntimeError)
|
81
|
+
|
82
|
+
end
|
83
|
+
|
84
|
+
example "different offset" do
|
85
|
+
|
86
|
+
ts = TimeStep.new("hour since 2001-01-01 00:00:00 +09:00")
|
87
|
+
unix = TimeStep.new("seconds since 1970-01-01 00:00:00")
|
88
|
+
|
89
|
+
pair = TimeStep::Pair.new(ts, unix)
|
90
|
+
|
91
|
+
is_asserted_by { pair.forward(0) == 978274800 }
|
92
|
+
is_asserted_by { pair.forward_time(0) == DateTime.new(2000,12,31,15,0,0,0) }
|
93
|
+
is_asserted_by { Time.at(pair.forward(0), in: "+00:00") == ts.origin.to_time }
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
|
98
|
+
end
|
99
|
+
|
data/timesteps.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
|
2
|
+
Gem::Specification::new do |s|
|
3
|
+
version = "0.9.3"
|
4
|
+
|
5
|
+
files = Dir.glob("**/*") - [
|
6
|
+
Dir.glob("timesteps-*.gem"),
|
7
|
+
Dir.glob("doc/**/*"),
|
8
|
+
Dir.glob("examples/**/*"),
|
9
|
+
].flatten
|
10
|
+
|
11
|
+
s.platform = Gem::Platform::RUBY
|
12
|
+
s.name = "timesteps"
|
13
|
+
s.summary = "A library for handling discrete time series in constant increments"
|
14
|
+
s.description = <<-HERE
|
15
|
+
A library for handling discrete time series in constant increments.
|
16
|
+
The main purpose of this library is to describe the time axis
|
17
|
+
when dealing with time series of observational data and climate data.
|
18
|
+
HERE
|
19
|
+
s.version = version
|
20
|
+
s.licenses = ['MIT']
|
21
|
+
s.author = "Hiroki Motoyoshi"
|
22
|
+
s.email = ""
|
23
|
+
s.homepage = 'https://github.com/himotoyoshi/timesteps'
|
24
|
+
s.files = files
|
25
|
+
s.required_ruby_version = ">= 2.5.1"
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: timesteps
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.9.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Hiroki Motoyoshi
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-05-04 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: " A library for handling discrete time series in constant increments.\n
|
14
|
+
\ The main purpose of this library is to describe the time axis \n when dealing
|
15
|
+
with time series of observational data and climate data.\n"
|
16
|
+
email: ''
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- LICENSES
|
22
|
+
- Note.ja.md
|
23
|
+
- README.md
|
24
|
+
- Rakefile
|
25
|
+
- lib/timesteps.rb
|
26
|
+
- lib/timesteps/calendar.rb
|
27
|
+
- lib/timesteps/datetimelike.rb
|
28
|
+
- lib/timesteps/format.rb
|
29
|
+
- lib/timesteps/grads.rb
|
30
|
+
- lib/timesteps/parse_timestamp.rb
|
31
|
+
- lib/timesteps/timestep.rb
|
32
|
+
- lib/timesteps/timestepconverter.rb
|
33
|
+
- lib/timesteps/timestepdatetimeext.rb
|
34
|
+
- lib/timesteps/timesteppair.rb
|
35
|
+
- spec/allleap_spec.rb
|
36
|
+
- spec/fixed360day_spec.rb
|
37
|
+
- spec/noleap_spec.rb
|
38
|
+
- spec/timestep_spec.rb
|
39
|
+
- spec/timesteppair_spec.rb
|
40
|
+
- timesteps.gemspec
|
41
|
+
homepage: https://github.com/himotoyoshi/timesteps
|
42
|
+
licenses:
|
43
|
+
- MIT
|
44
|
+
metadata: {}
|
45
|
+
post_install_message:
|
46
|
+
rdoc_options: []
|
47
|
+
require_paths:
|
48
|
+
- lib
|
49
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 2.5.1
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
requirements: []
|
60
|
+
rubygems_version: 3.0.3
|
61
|
+
signing_key:
|
62
|
+
specification_version: 4
|
63
|
+
summary: A library for handling discrete time series in constant increments
|
64
|
+
test_files: []
|