timesteps 1.0.2 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Note.ja.md +37 -6
- data/lib/timesteps/timestep.rb +17 -10
- data/spec/timestep_spec.rb +56 -2
- data/timesteps.gemspec +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ca436a0b5acbd7fc5f9dbb1c937e2b4beeadedf179f5aba8cba8c92610f9bb86
|
4
|
+
data.tar.gz: a9b9585faae128d76f50a32f4d8fcd68f0d02b7a9d500ffd5cced220d4d07131
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 207e61a139b6753ade655c016431c2ef9e99eefdd6068043cd371271b251ca4d347656d551fee0d6f5792f852dd1ce38fa1657470e1d6c8180bb44ea868958c8
|
7
|
+
data.tar.gz: 90ec417c9e01d092497677392969ee85ed183ec68c68e22dd4ce3bc8b496413c65cf3167cb5a7fa94879b0bd869097fcba24141af30e25cf72c84c6083a6eaa2
|
data/Note.ja.md
CHANGED
@@ -6,13 +6,36 @@ topicブランチ -> Feature開発版
|
|
6
6
|
|
7
7
|
"XX since YYY" と since: time を同時に指定下場合は、前者が採用される (sinceオプションは無視される)。
|
8
8
|
|
9
|
-
### 時間の単位 (udunits)
|
10
|
-
|
11
|
-
|
9
|
+
### 時間の単位 (udunits + α)
|
10
|
+
|
11
|
+
Normal cases
|
12
|
+
|
13
|
+
* years, year, yrs, yr, y
|
14
|
+
* months, month, mons, mon
|
12
15
|
* days, day, d
|
13
|
-
* hours, hour, h
|
14
|
-
* minutes, minute, min
|
15
|
-
* seconds, sec, s
|
16
|
+
* hours, hour, hrs, hr, h
|
17
|
+
* minutes, minute, mins, min, m
|
18
|
+
* seconds, second, secs, sec, s
|
19
|
+
* milliseconds, millisecond, msecs, msec, ms
|
20
|
+
* microseconds, microsecond, usecs, usec, us
|
21
|
+
* ayears, ayear
|
22
|
+
|
23
|
+
Week days (has a one week intervals and a day offset)
|
24
|
+
|
25
|
+
* weeks-sun, week-sun, w-sun
|
26
|
+
* weeks-mon, week-mon, w-mon
|
27
|
+
* weeks-tue, week-tue, w-tue
|
28
|
+
* weeks-wed, week-wed, w-wed
|
29
|
+
* weeks-thu, week-thu, w-thu
|
30
|
+
* weeks-fri, week-fri, w-fri
|
31
|
+
* weeks-sat, week-sat, w-sat
|
32
|
+
* sundays, sunday
|
33
|
+
* mondays, monday
|
34
|
+
* tuesdays, tuesday
|
35
|
+
* wednesdays, wednesday
|
36
|
+
* thursdays, thursday
|
37
|
+
* fridays, friday
|
38
|
+
* saturdays, saturdays
|
16
39
|
|
17
40
|
### クラス構成
|
18
41
|
|
@@ -54,6 +77,7 @@ topicブランチ -> Feature開発版
|
|
54
77
|
TimeSteps::Calendar#parse(spec) (initialized with bc: option)
|
55
78
|
|
56
79
|
### 暦の種類
|
80
|
+
|
57
81
|
#### standard, gregorian
|
58
82
|
|
59
83
|
* 今日使われているグレゴリオ暦
|
@@ -86,7 +110,14 @@ topicブランチ -> Feature開発版
|
|
86
110
|
ts = TimeStep.new("6 hours since 2012-01-10 09:00:00")
|
87
111
|
ts = ts.shift_origin_with_days(-256.quo(24))
|
88
112
|
|
113
|
+
### 謎仕様(修正求む)
|
114
|
+
|
115
|
+
#### 1日を1年単位で求めると...
|
116
|
+
|
117
|
+
ts = TimeStep.new("year since 2022-01-01")
|
118
|
+
ts.in("days").inverse(1) ### => (1/2)
|
89
119
|
|
120
|
+
なぜに(1/2)
|
90
121
|
|
91
122
|
|
92
123
|
|
data/lib/timesteps/timestep.rb
CHANGED
@@ -35,16 +35,22 @@ class TimeStep
|
|
35
35
|
'hours?',
|
36
36
|
'minutes?',
|
37
37
|
'seconds?',
|
38
|
+
'yrs?',
|
39
|
+
'y',
|
40
|
+
'mons?',
|
38
41
|
'd',
|
39
42
|
'hrs?',
|
40
43
|
'h',
|
41
44
|
'mins?',
|
45
|
+
'm',
|
42
46
|
'secs?',
|
43
47
|
's',
|
44
48
|
'milliseconds?',
|
45
49
|
'msecs?',
|
46
50
|
'ms',
|
47
51
|
'microseconds?',
|
52
|
+
'usecs?',
|
53
|
+
'us',
|
48
54
|
'(?:weeks?|w)(?:\-(?:sun|mon|tue|wed|thu|fri|sat))?',
|
49
55
|
'sundays?',
|
50
56
|
'mondays?',
|
@@ -206,13 +212,13 @@ class TimeStep
|
|
206
212
|
end
|
207
213
|
@interval = @numeric
|
208
214
|
case symbol
|
209
|
-
when /\
|
215
|
+
when /\A(years?|yrs?|y)\z/i
|
210
216
|
unless numeric.denominator == 1
|
211
217
|
raise "numeric factor for year should be an integer"
|
212
218
|
end
|
213
219
|
@symbol = :years
|
214
220
|
@interval *= 356.242*86400
|
215
|
-
when /\
|
221
|
+
when /\A(months?|mons?)\z/i
|
216
222
|
unless numeric.denominator == 1
|
217
223
|
raise "numeric factor for month should be an integer"
|
218
224
|
end
|
@@ -224,7 +230,7 @@ class TimeStep
|
|
224
230
|
when /\A(hours?|hrs?|h)\z/i
|
225
231
|
@symbol = :hours
|
226
232
|
@interval *= 3600
|
227
|
-
when /\A(minutes?|mins
|
233
|
+
when /\A(minutes?|mins?|m)\z/i
|
228
234
|
@symbol = :minutes
|
229
235
|
@interval *= 60
|
230
236
|
when /\A(seconds?|secs?|s)\z/i
|
@@ -232,7 +238,7 @@ class TimeStep
|
|
232
238
|
when /\A(milliseconds?|msecs?|ms)\z/i
|
233
239
|
@symbol = :seconds
|
234
240
|
@interval *= 1.quo(1000)
|
235
|
-
when /\
|
241
|
+
when /\A(microseconds?|usecs?|us)\z/i
|
236
242
|
@symbol = :seconds
|
237
243
|
@interval *= 1.quo(1000000)
|
238
244
|
when /\A(weeks?|w)\-(sun|mon|tue|wed|thu|fri|sat)\z/i
|
@@ -243,12 +249,12 @@ class TimeStep
|
|
243
249
|
when /\A(weeks?|w)\z/i
|
244
250
|
@symbol = :weeks
|
245
251
|
@interval *= 7*86400
|
246
|
-
when /\
|
252
|
+
when /\A(sundays?|mondays?|tuesdays?|wednesdays?|thursday?|fridays?|saturdays?)\z/i
|
247
253
|
symbol =~ /\A(\w{3})/i
|
248
254
|
@wday = $1.downcase.intern
|
249
255
|
@symbol = WDAY_NAME[@wday].intern ### :sundays, :mondays, ...
|
250
256
|
@interval *= 7*86400
|
251
|
-
when /\
|
257
|
+
when /\A(ayears?)\z/i
|
252
258
|
@symbol = :days
|
253
259
|
@numeric *= 365.242198781.to_r
|
254
260
|
@interval = @numeric * 86400
|
@@ -453,6 +459,7 @@ class TimeStep
|
|
453
459
|
time = times.first
|
454
460
|
time = time.to_datetime if time.is_a?(Time)
|
455
461
|
time = @calendar.parse(time, format: format, offset: @origin.offset) if time.is_a?(String)
|
462
|
+
time = time.new_offset(@origin.offset) if time.offset != @origin.offset
|
456
463
|
case @symbol
|
457
464
|
when :years
|
458
465
|
diff = time.difference_in_years(@origin)
|
@@ -562,7 +569,7 @@ class TimeStep
|
|
562
569
|
#
|
563
570
|
# @return [Numeric]
|
564
571
|
def next_index_of (time)
|
565
|
-
time = @calendar.parse(time
|
572
|
+
time = @calendar.parse(time) if time.is_a?(String)
|
566
573
|
return index_at(time).floor + 1
|
567
574
|
end
|
568
575
|
|
@@ -579,7 +586,7 @@ class TimeStep
|
|
579
586
|
#
|
580
587
|
# @return [Numeric]
|
581
588
|
def prev_index_of (time)
|
582
|
-
time = @calendar.parse(time
|
589
|
+
time = @calendar.parse(time) if time.is_a?(String)
|
583
590
|
return index_at(time).ceil - 1
|
584
591
|
end
|
585
592
|
|
@@ -687,8 +694,8 @@ class TimeStep
|
|
687
694
|
# ts.range("2001", "2002", ends: "[)")
|
688
695
|
# ts.range("2001", 1)
|
689
696
|
#
|
690
|
-
# @param start [Numeric, DateTime]
|
691
|
-
# @param last [Numeric, DateTime]
|
697
|
+
# @param start [Numeric, DateTime, String]
|
698
|
+
# @param last [Numeric, DateTime, String]
|
692
699
|
# @param count [Integer]
|
693
700
|
# @param ends [String] one of "[]", "()", "[)", "(]"
|
694
701
|
#
|
data/spec/timestep_spec.rb
CHANGED
@@ -50,12 +50,15 @@ describe "TimeStep.new" do
|
|
50
50
|
["minute since 2001-02-03 04:05:06 +07:00", 1, :minutes],
|
51
51
|
["second since 2001-02-03 04:05:06 +07:00", 1, :seconds],
|
52
52
|
|
53
|
+
["yr since 2001-02-03 04:05:06 +07:00", 1, :years],
|
54
|
+
["mon since 2001-02-03 04:05:06 +07:00", 1, :months],
|
53
55
|
["d since 2001-02-03 04:05:06 +07:00", 1, :days],
|
54
56
|
["hr since 2001-02-03 04:05:06 +07:00", 1, :hours],
|
55
57
|
["h since 2001-02-03 04:05:06 +07:00", 1, :hours],
|
56
58
|
["min since 2001-02-03 04:05:06 +07:00", 1, :minutes],
|
57
59
|
["sec since 2001-02-03 04:05:06 +07:00", 1, :seconds],
|
58
60
|
["s since 2001-02-03 04:05:06 +07:00", 1, :seconds],
|
61
|
+
["ms since 2001-02-03 04:05:06 +07:00", 1, :seconds],
|
59
62
|
|
60
63
|
["3 years since 2001-02-03 04:05:06 +07:00", 3, :years],
|
61
64
|
["3 months since 2001-02-03 04:05:06 +07:00", 3, :months],
|
@@ -115,12 +118,23 @@ describe "TimeStep.new" do
|
|
115
118
|
|
116
119
|
tests.each do |spec, numeric, symbol|
|
117
120
|
ts = TimeStep.new(spec)
|
118
|
-
|
119
121
|
is_asserted_by { ts.numeric == numeric }
|
120
122
|
is_asserted_by { ts.symbol == symbol }
|
121
123
|
end
|
122
124
|
|
123
125
|
end
|
126
|
+
|
127
|
+
example 'without since' do
|
128
|
+
|
129
|
+
is_asserted_by { TimeStep.new("year").origin == DateTime.new(0) }
|
130
|
+
is_asserted_by { TimeStep.new("month").origin == DateTime.new(0) }
|
131
|
+
is_asserted_by { TimeStep.new("week").origin == DateTime.new(0) }
|
132
|
+
is_asserted_by { TimeStep.new("day").origin == DateTime.new(0) }
|
133
|
+
is_asserted_by { TimeStep.new("hour").origin == DateTime.new(1970,1,1) }
|
134
|
+
is_asserted_by { TimeStep.new("min").origin == DateTime.new(1970,1,1) }
|
135
|
+
is_asserted_by { TimeStep.new("sec").origin == DateTime.new(1970,1,1) }
|
136
|
+
|
137
|
+
end
|
124
138
|
|
125
139
|
example 'since option with format' do
|
126
140
|
|
@@ -337,6 +351,17 @@ describe "TimeStep#index_at" do
|
|
337
351
|
|
338
352
|
end
|
339
353
|
|
354
|
+
example 'different offset' do
|
355
|
+
|
356
|
+
ts = TimeStep.new("1 seconds since 1970-01-01 00:00:00")
|
357
|
+
|
358
|
+
time_utc = DateTime.parse("2001-01-01 00:00:00 +00:00")
|
359
|
+
time_jst = DateTime.parse("2001-01-01 09:00:00 +09:00")
|
360
|
+
|
361
|
+
is_asserted_by { ts.index_at(time_utc) == ts.index_at(time_jst) }
|
362
|
+
|
363
|
+
end
|
364
|
+
|
340
365
|
end
|
341
366
|
|
342
367
|
describe "TimeStep#duration_at" do
|
@@ -436,7 +461,6 @@ describe "TimeStep#new_origin" do
|
|
436
461
|
|
437
462
|
end
|
438
463
|
|
439
|
-
|
440
464
|
describe "TimeStep#right_time?" do
|
441
465
|
|
442
466
|
example do
|
@@ -449,3 +473,33 @@ describe "TimeStep#right_time?" do
|
|
449
473
|
|
450
474
|
end
|
451
475
|
|
476
|
+
describe "TimeStep#truncate" do
|
477
|
+
|
478
|
+
example 'hours' do
|
479
|
+
|
480
|
+
ts = TimeStep.new("1 hour")
|
481
|
+
|
482
|
+
time1 = DateTime.parse("2001-01-01 01:30:00 +00:00")
|
483
|
+
time1_jst = DateTime.parse("2001-01-01 10:30:00 +09:00")
|
484
|
+
time2 = DateTime.parse("2001-01-01 01:00:00 +00:00")
|
485
|
+
|
486
|
+
is_asserted_by { ts.truncate(time1).offset == 0 }
|
487
|
+
is_asserted_by { time2 == ts.truncate(time1) }
|
488
|
+
is_asserted_by { time2 == ts.truncate(time1_jst) }
|
489
|
+
|
490
|
+
ts_jst = TimeStep.new("1 hour since 1970-01-01 00:00 +09:00")
|
491
|
+
|
492
|
+
time1 = DateTime.parse("2001-01-01 01:30:00 +00:00")
|
493
|
+
time1_jst = DateTime.parse("2001-01-01 10:30:00 +09:00")
|
494
|
+
time2 = DateTime.parse("2001-01-01 01:00:00 +00:00")
|
495
|
+
time2_jst = DateTime.parse("2001-01-01 10:00:00 +09:00")
|
496
|
+
|
497
|
+
is_asserted_by { ts_jst.truncate(time1).offset == 9.quo(24) }
|
498
|
+
is_asserted_by { time2 == ts_jst.truncate(time1) }
|
499
|
+
is_asserted_by { time2 == ts_jst.truncate(time1_jst) }
|
500
|
+
is_asserted_by { time2_jst == ts_jst.truncate(time1) }
|
501
|
+
is_asserted_by { time2_jst == ts_jst.truncate(time1_jst) }
|
502
|
+
|
503
|
+
end
|
504
|
+
|
505
|
+
end
|
data/timesteps.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: timesteps
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hiroki Motoyoshi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-09-23 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: " A library for time conversion and intercomparison of multiple time
|
14
14
|
series data \n in the case of handling time series data of the type that specifies
|
@@ -71,7 +71,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
71
71
|
- !ruby/object:Gem::Version
|
72
72
|
version: '0'
|
73
73
|
requirements: []
|
74
|
-
rubygems_version: 3.
|
74
|
+
rubygems_version: 3.0.3
|
75
75
|
signing_key:
|
76
76
|
specification_version: 4
|
77
77
|
summary: A library for handling discrete time series in constant increments
|