timesteps 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7475cc3a4a0af27a77730770cd4c952282ecfd1054d3bdd08a53d1da76ebe5a7
4
- data.tar.gz: fdb95e8bd70ec9f2bcddf3b8c206f8db1330f169b54b531d74e4fc4148be92e3
3
+ metadata.gz: ca436a0b5acbd7fc5f9dbb1c937e2b4beeadedf179f5aba8cba8c92610f9bb86
4
+ data.tar.gz: a9b9585faae128d76f50a32f4d8fcd68f0d02b7a9d500ffd5cced220d4d07131
5
5
  SHA512:
6
- metadata.gz: 1c8e36605a8128a20a7bf27af046e44d7f3d37cacb3669a7e28c4fa17aa4f0883bc9b44730756471b73f16afee6ef114b8b7021d2cee7812869914a3c832fdab
7
- data.tar.gz: 3598ecc55200ff8e1aa474c0fd3f5c4c443b973c853557db3003e8489eb69f2630b76e4a2a44106ede8328efec69aca90d5e72e23bb95d2cdaed97d226657bfc
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
- * years, year
11
- * months,month
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
 
@@ -49,6 +49,8 @@ class TimeStep
49
49
  'msecs?',
50
50
  'ms',
51
51
  'microseconds?',
52
+ 'usecs?',
53
+ 'us',
52
54
  '(?:weeks?|w)(?:\-(?:sun|mon|tue|wed|thu|fri|sat))?',
53
55
  'sundays?',
54
56
  'mondays?',
@@ -210,13 +212,13 @@ class TimeStep
210
212
  end
211
213
  @interval = @numeric
212
214
  case symbol
213
- when /\Ayears?\z/i
215
+ when /\A(years?|yrs?|y)\z/i
214
216
  unless numeric.denominator == 1
215
217
  raise "numeric factor for year should be an integer"
216
218
  end
217
219
  @symbol = :years
218
220
  @interval *= 356.242*86400
219
- when /\Amonths?\z/i
221
+ when /\A(months?|mons?)\z/i
220
222
  unless numeric.denominator == 1
221
223
  raise "numeric factor for month should be an integer"
222
224
  end
@@ -228,7 +230,7 @@ class TimeStep
228
230
  when /\A(hours?|hrs?|h)\z/i
229
231
  @symbol = :hours
230
232
  @interval *= 3600
231
- when /\A(minutes?|mins?)\z/i
233
+ when /\A(minutes?|mins?|m)\z/i
232
234
  @symbol = :minutes
233
235
  @interval *= 60
234
236
  when /\A(seconds?|secs?|s)\z/i
@@ -236,7 +238,7 @@ class TimeStep
236
238
  when /\A(milliseconds?|msecs?|ms)\z/i
237
239
  @symbol = :seconds
238
240
  @interval *= 1.quo(1000)
239
- when /\Amicroseconds?\z/i
241
+ when /\A(microseconds?|usecs?|us)\z/i
240
242
  @symbol = :seconds
241
243
  @interval *= 1.quo(1000000)
242
244
  when /\A(weeks?|w)\-(sun|mon|tue|wed|thu|fri|sat)\z/i
@@ -247,12 +249,12 @@ class TimeStep
247
249
  when /\A(weeks?|w)\z/i
248
250
  @symbol = :weeks
249
251
  @interval *= 7*86400
250
- when /\Asundays?|mondays?|tuesdays?|wednesdays?|thursday?|fridays?|saturdays?\z/i
252
+ when /\A(sundays?|mondays?|tuesdays?|wednesdays?|thursday?|fridays?|saturdays?)\z/i
251
253
  symbol =~ /\A(\w{3})/i
252
254
  @wday = $1.downcase.intern
253
255
  @symbol = WDAY_NAME[@wday].intern ### :sundays, :mondays, ...
254
256
  @interval *= 7*86400
255
- when /\Aayears?\z/i
257
+ when /\A(ayears?)\z/i
256
258
  @symbol = :days
257
259
  @numeric *= 365.242198781.to_r
258
260
  @interval = @numeric * 86400
@@ -457,6 +459,7 @@ class TimeStep
457
459
  time = times.first
458
460
  time = time.to_datetime if time.is_a?(Time)
459
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
460
463
  case @symbol
461
464
  when :years
462
465
  diff = time.difference_in_years(@origin)
@@ -566,7 +569,7 @@ class TimeStep
566
569
  #
567
570
  # @return [Numeric]
568
571
  def next_index_of (time)
569
- time = @calendar.parse(time, offset: @origin.offset) if time.is_a?(String)
572
+ time = @calendar.parse(time) if time.is_a?(String)
570
573
  return index_at(time).floor + 1
571
574
  end
572
575
 
@@ -583,7 +586,7 @@ class TimeStep
583
586
  #
584
587
  # @return [Numeric]
585
588
  def prev_index_of (time)
586
- time = @calendar.parse(time, offset: @origin.offset) if time.is_a?(String)
589
+ time = @calendar.parse(time) if time.is_a?(String)
587
590
  return index_at(time).ceil - 1
588
591
  end
589
592
 
@@ -691,8 +694,8 @@ class TimeStep
691
694
  # ts.range("2001", "2002", ends: "[)")
692
695
  # ts.range("2001", 1)
693
696
  #
694
- # @param start [Numeric, DateTime]
695
- # @param last [Numeric, DateTime]
697
+ # @param start [Numeric, DateTime, String]
698
+ # @param last [Numeric, DateTime, String]
696
699
  # @param count [Integer]
697
700
  # @param ends [String] one of "[]", "()", "[)", "(]"
698
701
  #
@@ -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
@@ -1,6 +1,6 @@
1
1
 
2
2
  Gem::Specification::new do |s|
3
- version = "1.0.3"
3
+ version = "1.0.4"
4
4
 
5
5
  files = Dir.glob("**/*") + [".yardopts"] - [
6
6
  Dir.glob("timesteps-*.gem"),
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.3
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: 2022-06-21 00:00:00.000000000 Z
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.1.6
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