timesteps 0.9.9 → 1.0.0

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: b5e250a6b62bd9f9ac48c4a23390fd8dbc50a887c65c020a8e5a31c34231699c
4
- data.tar.gz: b0e3d2bd61e0ca504eb904398092f575a0e75ac12e2b34b7c5e52afc97a97749
3
+ metadata.gz: 8ec2401e1d32acce3ddb048864c34b37de56ad5f83066fa617baeea8c65abc3a
4
+ data.tar.gz: '083c51a6c6fd1f295e7d2359960f5fe893ccc0847bcf014b7928f629c21e1a8e'
5
5
  SHA512:
6
- metadata.gz: 4b41b5827d9535d55a86b30e2bf8e64d95ea7d9db62282af44b2b0bc6ed89c640f6261232cab56e294355b65b6092db40ba32397681b99d38b9c591ef2dd6a68
7
- data.tar.gz: 349f595b0f3d10c5babdc26aec689b7cf0826de7e1a4cd879af7a6cdf3ccbc6cb77ad86bf983cfa6913ac4595bed076efd4ec7fc5dd0774f6476054d27b7bba8
6
+ metadata.gz: e242891a7aed17ea1a3c0c138e80382b55422b5d6c9cbeec0c32e0b5725d5979a1e7631b110eb136ca4942c16023b93b325390f28be30792aa15f637a736c09b
7
+ data.tar.gz: 4da60d62efce29eeb13b1fe93d2621cdc616c6d8fe4d421922257bbb5e28c5695504d6804806430feb1dd42adbba7870de37b41758cf3df121dae59b57c1d3bf
File without changes
data/README.md CHANGED
@@ -2,13 +2,13 @@ timesteps
2
2
  ================
3
3
 
4
4
  A library for handling discrete time series in constant increments.
5
- The primary purpose of this library is to describe the time axis
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
8
  Features
9
9
  --------
10
10
 
11
- * TimeStep holds an origin time and an unit time interval.
11
+ * TimeStep holds an origin time and a unit time interval.
12
12
  * Parsing a time step expression like "hours since 2001-01-01 00:00:00" (originate from udunits library)
13
13
  * Obtaining time value for the index value (0 for the origin time)
14
14
  * Obtaining index value for the time value
@@ -0,0 +1,14 @@
1
+ require 'date'
2
+
3
+ class Time
4
+ def to_datetime
5
+ # Convert seconds + microseconds into a fractional number of seconds
6
+ seconds = sec + Rational(usec, 10**6)
7
+
8
+ # Convert a UTC offset measured in minutes to one measured in a
9
+ # fraction of a day.
10
+ offset = Rational(utc_offset, 60 * 60 * 24)
11
+
12
+ DateTime.new(year, month, day, hour, min, seconds, offset)
13
+ end
14
+ end
@@ -451,6 +451,7 @@ class TimeStep
451
451
  def index_at (*times, format: nil)
452
452
  if times.size == 1
453
453
  time = times.first
454
+ time = time.to_datetime if time.is_a?(Time)
454
455
  time = @calendar.parse(time, format: format, offset: @origin.offset) if time.is_a?(String)
455
456
  case @symbol
456
457
  when :years
@@ -4,11 +4,11 @@ class TimeStep::Query
4
4
 
5
5
  def initialize (timestep, format: nil)
6
6
  @timestep = timestep
7
- @format = foramt
7
+ @format = format
8
8
  end
9
9
 
10
10
  def __format__ (time)
11
- return ( @template.nil? ) ? time : time.strftime(@template)
11
+ return ( @format.nil? ) ? time : time.strftime(@format)
12
12
  end
13
13
 
14
14
  private :__format__
@@ -19,7 +19,7 @@ class TimeStep::Query
19
19
 
20
20
  def just_before_time_of (time)
21
21
  idx = @timestep.index_at(time)
22
- if idx.denomiator == 1
22
+ if idx.denominator == 1
23
23
  time0 = time
24
24
  else
25
25
  time0 = @timestep.time_at(idx.floor)
@@ -29,7 +29,7 @@ class TimeStep::Query
29
29
 
30
30
  def just_after_time_of (time)
31
31
  idx = @timestep.index_at(time)
32
- if idx.denomiator == 1
32
+ if idx.denominator == 1
33
33
  time0 = time
34
34
  else
35
35
  time0 = @timestep.time_at(idx.ceil)
@@ -47,3 +47,11 @@ class TimeStep::Query
47
47
 
48
48
  end
49
49
 
50
+ class TimeStep
51
+
52
+ def query (format = nil)
53
+ return TimeStep::Query.new(self, format: format)
54
+ end
55
+
56
+ end
57
+
@@ -13,6 +13,8 @@ class TimeStep::Range
13
13
  if last
14
14
  case start
15
15
  when Numeric
16
+ when Time
17
+ start = timestep.index_at(start.to_datetime)
16
18
  when DateTime, DateTimeLike, String
17
19
  start = timestep.index_at(start)
18
20
  else
@@ -20,6 +22,8 @@ class TimeStep::Range
20
22
  end
21
23
  case last
22
24
  when Numeric
25
+ when Time
26
+ last = timestep.index_at(last.to_datetime)
23
27
  when DateTime, DateTimeLike, String
24
28
  last = timestep.index_at(last)
25
29
  else
data/lib/timesteps.rb CHANGED
@@ -1,5 +1,6 @@
1
1
 
2
2
  require "date"
3
+ require "timesteps/time"
3
4
  require "timesteps/datetimelike"
4
5
  require "timesteps/datetimelike_format"
5
6
  require "timesteps/datetime_noleap"
@@ -14,3 +15,4 @@ require "timesteps/timestep_converter"
14
15
  require "timesteps/timeperiod"
15
16
  require "timesteps/timestep_range"
16
17
  require "timesteps/datetime_timestep"
18
+ require "timesteps/timestep_query"
data/timesteps.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
 
2
2
  Gem::Specification::new do |s|
3
- version = "0.9.9"
3
+ version = "1.0.0"
4
4
 
5
5
  files = Dir.glob("**/*") + [".yardopts"] - [
6
6
  Dir.glob("timesteps-*.gem"),
@@ -20,7 +20,7 @@ Gem::Specification::new do |s|
20
20
  describe the time axis when dealing with time series of observational data and climate data.
21
21
  HERE
22
22
  s.version = version
23
- s.licenses = ['MIT']
23
+ s.license = 'MIT'
24
24
  s.author = "Hiroki Motoyoshi"
25
25
  s.email = ""
26
26
  s.homepage = 'https://github.com/himotoyoshi/timesteps'
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: 0.9.9
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hiroki Motoyoshi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-23 00:00:00.000000000 Z
11
+ date: 2021-10-27 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
@@ -23,7 +23,7 @@ extensions: []
23
23
  extra_rdoc_files: []
24
24
  files:
25
25
  - ".yardopts"
26
- - LICENSES
26
+ - LICENSE
27
27
  - NEWS.md
28
28
  - Note.ja.md
29
29
  - README.md
@@ -37,6 +37,7 @@ files:
37
37
  - lib/timesteps/datetimelike.rb
38
38
  - lib/timesteps/datetimelike_format.rb
39
39
  - lib/timesteps/grads.rb
40
+ - lib/timesteps/time.rb
40
41
  - lib/timesteps/timeperiod.rb
41
42
  - lib/timesteps/timestep.rb
42
43
  - lib/timesteps/timestep_calendar.rb
@@ -70,7 +71,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
70
71
  - !ruby/object:Gem::Version
71
72
  version: '0'
72
73
  requirements: []
73
- rubygems_version: 3.0.3
74
+ rubygems_version: 3.1.2
74
75
  signing_key:
75
76
  specification_version: 4
76
77
  summary: A library for handling discrete time series in constant increments