timesteps 1.0.0 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8ec2401e1d32acce3ddb048864c34b37de56ad5f83066fa617baeea8c65abc3a
4
- data.tar.gz: '083c51a6c6fd1f295e7d2359960f5fe893ccc0847bcf014b7928f629c21e1a8e'
3
+ metadata.gz: 7475cc3a4a0af27a77730770cd4c952282ecfd1054d3bdd08a53d1da76ebe5a7
4
+ data.tar.gz: fdb95e8bd70ec9f2bcddf3b8c206f8db1330f169b54b531d74e4fc4148be92e3
5
5
  SHA512:
6
- metadata.gz: e242891a7aed17ea1a3c0c138e80382b55422b5d6c9cbeec0c32e0b5725d5979a1e7631b110eb136ca4942c16023b93b325390f28be30792aa15f637a736c09b
7
- data.tar.gz: 4da60d62efce29eeb13b1fe93d2621cdc616c6d8fe4d421922257bbb5e28c5695504d6804806430feb1dd42adbba7870de37b41758cf3df121dae59b57c1d3bf
6
+ metadata.gz: 1c8e36605a8128a20a7bf27af046e44d7f3d37cacb3669a7e28c4fa17aa4f0883bc9b44730756471b73f16afee6ef114b8b7021d2cee7812869914a3c832fdab
7
+ data.tar.gz: 3598ecc55200ff8e1aa474c0fd3f5c4c443b973c853557db3003e8489eb69f2630b76e4a2a44106ede8328efec69aca90d5e72e23bb95d2cdaed97d226657bfc
data/NEWS.md CHANGED
@@ -1,6 +1,12 @@
1
1
  NEWS
2
2
  ====
3
3
 
4
+ 0.9.9 -> 1.0.2
5
+ --------------
6
+
7
+ * [Add] DateTime#next, DateTime#prev
8
+ * [Add] TimeStep#right_time?
9
+
4
10
  0.9.8 -> 0.9.9
5
11
  --------------
6
12
 
data/Note.ja.md CHANGED
@@ -4,8 +4,6 @@ masterブランチ -> gem リリース最新版
4
4
  developブランチ -> 開発統合版
5
5
  topicブランチ -> Feature開発版
6
6
 
7
-
8
-
9
7
  "XX since YYY" と since: time を同時に指定下場合は、前者が採用される (sinceオプションは無視される)。
10
8
 
11
9
  ### 時間の単位 (udunits)
data/README.md CHANGED
@@ -1,10 +1,14 @@
1
- timesteps
1
+ TimeSteps
2
2
  ================
3
3
 
4
4
  A library for handling discrete time series in constant increments.
5
5
  The primary purpose is to describe the time axis
6
6
  when dealing with time series of observational data and climate data.
7
7
 
8
+ This library relies heavily on the DateTime class. However,
9
+ the DateTime class has been deprecated,
10
+ so please keep that in mind when using this library.
11
+
8
12
  Features
9
13
  --------
10
14
 
@@ -195,6 +199,13 @@ ts = TimeStep.new("3 hours since 2001-01-01 09:00:00", calendar: "noleap")
195
199
 
196
200
  # specify origin time with DateTime object
197
201
  ts = TimeStep.new("3 hours", since: DateTime.parse("2001-01-01 09:00:00"))
202
+
203
+ # hourly increments whose origin is the most recent convenient time to the current time
204
+ ts = TimeStep.new("1 hour").new_origin(DateTime.now, truncate: true)
205
+
206
+ # hourly increments whose origin is the most recent convenient time to the current time
207
+ # with +0900 time offset
208
+ ts = TimeStep.new("1 hour", offset: "+0900").new_origin(DateTime.now, truncate: true)
198
209
  ```
199
210
 
200
211
  ### Attributes of TimeStep object
@@ -296,5 +307,6 @@ conv.forward(0, 56, 81, with_time: true)
296
307
  # "ts2"=>[-48, 8, 33],
297
308
  # "ts3"=>[-72, -16, 9]}
298
309
 
310
+
299
311
  ```
300
312
 
@@ -25,6 +25,34 @@ class DateTime
25
25
  return TimePeriod.new(interval_spec, since: self, calendar: calendar, ends: ends, tz: tz)
26
26
  end
27
27
 
28
+ def next (*args)
29
+ case args.size
30
+ when 1
31
+ num = 1
32
+ unit = args[0]
33
+ when 2
34
+ num = args[0]
35
+ unit = args[1]
36
+ else
37
+ raise "invalid number of argumets"
38
+ end
39
+ return TimeStep.new(unit, since: self).time_at(num)
40
+ end
41
+
42
+ def prev (*args)
43
+ case args.size
44
+ when 1
45
+ num = 1
46
+ unit = args[0]
47
+ when 2
48
+ num = args[0]
49
+ unit = args[1]
50
+ else
51
+ raise "invalid number of argumets"
52
+ end
53
+ return TimeStep.new(unit, since: self).time_at(-num)
54
+ end
55
+
28
56
  end
29
57
 
30
58
  class DateTime::NoLeap
@@ -35,10 +35,14 @@ 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?',
@@ -516,8 +520,9 @@ class TimeStep
516
520
  # @param time [DateTime, String]
517
521
  #
518
522
  # @return [TimeStep]
519
- def new_origin (time)
523
+ def new_origin (time, truncate: false)
520
524
  time = @calendar.parse(time, offset: @origin.offset) if time.is_a?(String)
525
+ time = self.truncate(time) if truncate
521
526
  if @wday
522
527
  origin = time - time.wday + WDAY[@wday]
523
528
  origin -= 7 unless time >= origin
@@ -627,7 +632,7 @@ class TimeStep
627
632
  # @return [TimeStep::Pair]
628
633
  def in (unit)
629
634
  other = TimeStep.new(unit, since: @origin, calendar: @calendar)
630
- return Pair.new(self, other)
635
+ return Pair.new(self, other)
631
636
  end
632
637
 
633
638
  # Creates new timestep pair object which refers `other` from `self`
@@ -696,5 +701,19 @@ class TimeStep
696
701
  return TimeStep::Range.new(self, start, last, count: count, ends: ends)
697
702
  end
698
703
 
704
+ # Check whether the given time is right or not for timestep.
705
+ #
706
+ # @example
707
+ # ts = TimeStep.new("1 hour")
708
+ # ts.right_time?(ts.parse("2001-01-01 01:00:00"))
709
+ # # => true
710
+ # ts.right_time?(ts.parse("2001-01-01 01:30:00"))
711
+ # # => false
712
+ #
713
+ # @return [TimeStep::Range]
714
+ def right_time? (time)
715
+ return index_at(time).integer?
716
+ end
717
+
699
718
  end
700
719
 
@@ -25,7 +25,7 @@ class TimeStep::Range
25
25
  when Time
26
26
  last = timestep.index_at(last.to_datetime)
27
27
  when DateTime, DateTimeLike, String
28
- last = timestep.index_at(last)
28
+ last = timestep.index_at(last)
29
29
  else
30
30
  raise "unknown argument"
31
31
  end
@@ -48,22 +48,24 @@ class TimeStep::Range
48
48
  end
49
49
 
50
50
  if include_start
51
- @start = start.ceil
51
+ start = start.ceil
52
52
  else
53
- @start = start.floor + 1
53
+ start = start.floor + 1
54
54
  end
55
55
 
56
56
  if include_last
57
- @last = last.floor
57
+ last = last.floor
58
58
  else
59
- @last = last.ceil - 1
59
+ last = last.ceil - 1
60
60
  end
61
61
 
62
- @timestep = timestep.new_origin(timestep.time_at(@start))
63
- @count = @last - @start + 1
64
-
65
- @start_time = @timestep.time_at(@start)
66
- @last_time = @timestep.time_at(@last)
62
+ @timestep = timestep.new_origin(timestep.time_at(start))
63
+ @start_time = timestep.time_at(start)
64
+ @last_time = timestep.time_at(last)
65
+
66
+ @start = @timestep.index_at(@start_time)
67
+ @last = @timestep.index_at(@last_time)
68
+ @count = @last - @start + 1
67
69
  end
68
70
 
69
71
  attr_reader :timestep, :count, :start, :last, :start_time, :last_time
@@ -118,8 +120,8 @@ class TimeStep::Range
118
120
  # @param time [DateTime]
119
121
  #
120
122
  # @return [TimeStep]
121
- def new_origin (time)
122
- timestep = @timestep.new_origin(time)
123
+ def new_origin (time, truncate: false)
124
+ timestep = @timestep.new_origin(time, truncate: truncate)
123
125
  return TimeStep::Range.new(timestep, count: @count)
124
126
  end
125
127
 
@@ -127,12 +129,12 @@ class TimeStep::Range
127
129
 
128
130
  def each_time (&block)
129
131
  if block
130
- @start.upto(@last) do |k|
132
+ (@start..@last).each do |k|
131
133
  block.call(@timestep.time_at(k))
132
134
  end
133
135
  else
134
136
  return Enumerator.new {|y|
135
- @start.upto(@last) do |k|
137
+ (@start..@last).each do |k|
136
138
  y << @timestep.time_at(k)
137
139
  end
138
140
  }
@@ -436,3 +436,16 @@ describe "TimeStep#new_origin" do
436
436
 
437
437
  end
438
438
 
439
+
440
+ describe "TimeStep#right_time?" do
441
+
442
+ example do
443
+
444
+ ts = TimeStep.new("1 hour")
445
+ is_asserted_by { ts.right_time?(ts.parse("2001-01-01 01:00:00")) == true }
446
+ is_asserted_by { ts.right_time?(ts.parse("2001-01-01 01:30:00")) == false }
447
+
448
+ end
449
+
450
+ end
451
+
data/timesteps.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
 
2
2
  Gem::Specification::new do |s|
3
- version = "1.0.0"
3
+ version = "1.0.3"
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.0
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hiroki Motoyoshi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-10-27 00:00:00.000000000 Z
11
+ date: 2022-06-21 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.2
74
+ rubygems_version: 3.1.6
75
75
  signing_key:
76
76
  specification_version: 4
77
77
  summary: A library for handling discrete time series in constant increments