timesteps 1.0.0 → 1.0.1

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: 8ec2401e1d32acce3ddb048864c34b37de56ad5f83066fa617baeea8c65abc3a
4
- data.tar.gz: '083c51a6c6fd1f295e7d2359960f5fe893ccc0847bcf014b7928f629c21e1a8e'
3
+ metadata.gz: 9f12b99565a7b2bdc24a8e9c6e3d2b38a439d3b273f73df6af514f1bee2c7905
4
+ data.tar.gz: e2680119ef10f30ea98803e89e9dd2e6f0b9d0b9291939100896ce3c192d0b86
5
5
  SHA512:
6
- metadata.gz: e242891a7aed17ea1a3c0c138e80382b55422b5d6c9cbeec0c32e0b5725d5979a1e7631b110eb136ca4942c16023b93b325390f28be30792aa15f637a736c09b
7
- data.tar.gz: 4da60d62efce29eeb13b1fe93d2621cdc616c6d8fe4d421922257bbb5e28c5695504d6804806430feb1dd42adbba7870de37b41758cf3df121dae59b57c1d3bf
6
+ metadata.gz: ffca26ce458c6867518d4804e50fa85e673c972e32941299697b19a49b20baba1731a9d512d566bffa4532870a4e0f229e154c61d20e8b3ad1ec94e95d3ba2fc
7
+ data.tar.gz: a1b3f59a940a30d3e7634cdbbb748fa39f45558ce0ac65412b8630c2a847293f708dc8fbe85760eb13f4462d82067e2c677dac84ba0b6cfafed48622b10cea90
data/README.md CHANGED
@@ -195,6 +195,13 @@ ts = TimeStep.new("3 hours since 2001-01-01 09:00:00", calendar: "noleap")
195
195
 
196
196
  # specify origin time with DateTime object
197
197
  ts = TimeStep.new("3 hours", since: DateTime.parse("2001-01-01 09:00:00"))
198
+
199
+ # hourly increments whose origin is the most recent convenient time to the current time
200
+ ts = TimeStep.new("1 hour").new_origin(DateTime.now, truncate: true)
201
+
202
+ # hourly increments whose origin is the most recent convenient time to the current time
203
+ # with +0900 time offset
204
+ ts = TimeStep.new("1 hour", offset: "+0900").new_origin(DateTime.now, truncate: true)
198
205
  ```
199
206
 
200
207
  ### Attributes of TimeStep object
@@ -296,5 +303,6 @@ conv.forward(0, 56, 81, with_time: true)
296
303
  # "ts2"=>[-48, 8, 33],
297
304
  # "ts3"=>[-72, -16, 9]}
298
305
 
306
+
299
307
  ```
300
308
 
@@ -516,8 +516,9 @@ class TimeStep
516
516
  # @param time [DateTime, String]
517
517
  #
518
518
  # @return [TimeStep]
519
- def new_origin (time)
519
+ def new_origin (time, truncate: false)
520
520
  time = @calendar.parse(time, offset: @origin.offset) if time.is_a?(String)
521
+ time = self.truncate(time) if truncate
521
522
  if @wday
522
523
  origin = time - time.wday + WDAY[@wday]
523
524
  origin -= 7 unless time >= origin
@@ -627,7 +628,7 @@ class TimeStep
627
628
  # @return [TimeStep::Pair]
628
629
  def in (unit)
629
630
  other = TimeStep.new(unit, since: @origin, calendar: @calendar)
630
- return Pair.new(self, other)
631
+ return Pair.new(self, other)
631
632
  end
632
633
 
633
634
  # Creates new timestep pair object which refers `other` from `self`
@@ -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
  }
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.1"
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.1
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: 2021-10-28 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