timesteps 1.0.0 → 1.0.1
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 +4 -4
- data/README.md +8 -0
- data/lib/timesteps/timestep.rb +3 -2
- data/lib/timesteps/timestep_range.rb +15 -13
- data/timesteps.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9f12b99565a7b2bdc24a8e9c6e3d2b38a439d3b273f73df6af514f1bee2c7905
|
4
|
+
data.tar.gz: e2680119ef10f30ea98803e89e9dd2e6f0b9d0b9291939100896ce3c192d0b86
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
|
data/lib/timesteps/timestep.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
51
|
+
start = start.ceil
|
52
52
|
else
|
53
|
-
|
53
|
+
start = start.floor + 1
|
54
54
|
end
|
55
55
|
|
56
56
|
if include_last
|
57
|
-
|
57
|
+
last = last.floor
|
58
58
|
else
|
59
|
-
|
59
|
+
last = last.ceil - 1
|
60
60
|
end
|
61
61
|
|
62
|
-
@timestep
|
63
|
-
@
|
64
|
-
|
65
|
-
|
66
|
-
@
|
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
|
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
|
137
|
+
(@start..@last).each do |k|
|
136
138
|
y << @timestep.time_at(k)
|
137
139
|
end
|
138
140
|
}
|
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.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-
|
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
|