time_math2 0.1.0 → 0.1.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
  SHA1:
3
- metadata.gz: f2e42b79bda1365a78f8c74b1b2d41af59f4c5c0
4
- data.tar.gz: b2dcd6572c88be32bfbff1f9a3f15cda929551b9
3
+ metadata.gz: 30696230b69ae5862c132f959e9fbdf1d09e4b70
4
+ data.tar.gz: ad25e2782956da2d458dd2ee26fbcf2a896c6a23
5
5
  SHA512:
6
- metadata.gz: 987ddc51e856db1f2f9baa77d68beb189b7a2f6193a82d5839cf11b3e4b9f989d8fe676d4539087a60bbda75e4779f90a7c8d0b706a5d2cef1c85123c8fd9f6b
7
- data.tar.gz: 0d5a36c6e120c1244ae40a768b13f499455e855890a46013674464e9d6939b7797ef14aed268a05491e29e98be4249467bb112d5b29381611606be7346f4632e
6
+ metadata.gz: 1950a184a7fb2cdf739ef3ac750744c651cafc17bc052f88f9f3a339f749aa7236e29257fee11be21c71f50859d1185073cd2f5c5e3ecdfd45247645616a2410
7
+ data.tar.gz: 120cd89814db9cee542846bc4eb86372f01bf5942cd54b714cd772c0273eed58fcaeaf5791d27bc5c444169de69e704fe669225954cd7d61508dec3e9b047696
@@ -1,5 +1,9 @@
1
1
  # TimeMath Changelog
2
2
 
3
+ # 0.1.1 (2019-03-15)
4
+
5
+ * Ruby 2.6 compatibility, thanks @flash-gordon.
6
+
3
7
  # 0.1.0 (2017-07-30)
4
8
 
5
9
  * Update sequences logic to be, well... More logical (Thanks @kenn again for meaningful discussion!);
data/README.md CHANGED
@@ -73,7 +73,7 @@ $ gem install time_math2
73
73
  or add to your Gemfile
74
74
 
75
75
  ```ruby
76
- gem 'time_math2'
76
+ gem 'time_math2', require: 'time_math'
77
77
  ```
78
78
 
79
79
  and `bundle install` it.
@@ -19,7 +19,6 @@ require 'time'
19
19
  # See also `TimeMath()` method in global namespace, it is lot of fun!
20
20
  #
21
21
  module TimeMath
22
- require_relative './time_math/backports'
23
22
  require_relative './time_math/units'
24
23
  require_relative './time_math/op'
25
24
  require_relative './time_math/sequence'
@@ -127,12 +126,12 @@ end
127
126
  # ```
128
127
  #
129
128
  # See also {TimeMath::Op} for list of operations available, but basically
130
- # they are all same you can call on {TimeMath::Unit}, just pass unit symbol
129
+ # they are all same you can call on {TimeMath::Units::Base}, just pass unit symbol
131
130
  # as a first argument.
132
131
  #
133
132
  # @param arguments time-y value, or list of them, or nothing
134
133
  #
135
134
  # @return [TimeMath::Op]
136
- def TimeMath(*arguments) # rubocop:disable Style/MethodName
135
+ def TimeMath(*arguments) # rubocop:disable Naming/MethodName
137
136
  TimeMath::Op.new(*arguments)
138
137
  end
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module TimeMath
4
2
  # @private
5
3
  module Measure
@@ -197,6 +197,7 @@ module TimeMath
197
197
 
198
198
  def inspect_args
199
199
  return ' ' if @arguments.empty?
200
+
200
201
  '(' + [*@arguments].map(&:inspect).join(', ') + ').'
201
202
  end
202
203
 
@@ -31,6 +31,7 @@ module TimeMath
31
31
  class ArrayResampler < Resampler
32
32
  def self.try(unit, array)
33
33
  return nil unless array.is_a?(Array) && array.all?(&Util.method(:timey?))
34
+
34
35
  new(unit, array)
35
36
  end
36
37
 
@@ -53,7 +54,8 @@ module TimeMath
53
54
  # @private
54
55
  class HashResampler < Resampler
55
56
  def self.try(unit, hash)
56
- return nil unless hash.is_a?(Hash) && hash.keys.all?(&Util.method(:timey?))
57
+ return unless hash.is_a?(Hash) && hash.keys.all?(&Util.method(:timey?))
58
+
57
59
  new(unit, hash)
58
60
  end
59
61
 
@@ -138,6 +138,7 @@ module TimeMath
138
138
  # of origin would be preserved.
139
139
  def advance(tm, amount = 1)
140
140
  return decrease(tm, -amount) if amount < 0
141
+
141
142
  _advance(tm, amount)
142
143
  end
143
144
 
@@ -151,6 +152,7 @@ module TimeMath
151
152
  # of origin would be preserved.
152
153
  def decrease(tm, amount = 1)
153
154
  return advance(tm, -amount) if amount < 0
155
+
154
156
  _decrease(tm, amount)
155
157
  end
156
158
 
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module TimeMath
4
2
  module Units
5
3
  # @private
@@ -9,7 +9,7 @@ module TimeMath
9
9
  protected
10
10
 
11
11
  def _measure(from, to)
12
- ((to.to_time - from.to_time) / to_seconds).to_i
12
+ to.to_time.-(from.to_time)./(to_seconds).to_i
13
13
  end
14
14
 
15
15
  def _advance(tm, steps)
@@ -8,10 +8,10 @@ module TimeMath
8
8
  module_function
9
9
 
10
10
  def timey?(val)
11
- [Time, DateTime, Date].any? { |cls| val.is_a?(cls) }
11
+ [Time, DateTime, Date].include?(val.class)
12
12
  end
13
13
 
14
- def merge(tm, attrs = {})
14
+ def merge(tm, **attrs)
15
15
  hash_to_tm(tm, tm_to_hash(tm).merge(attrs))
16
16
  end
17
17
 
@@ -56,6 +56,7 @@ module TimeMath
56
56
 
57
57
  def fix_month_day(components)
58
58
  return if components[2].nil? || components[1].nil?
59
+
59
60
  days_in_month =
60
61
  if components[1] == 2 && components[0] && Date.gregorian_leap?(components[0])
61
62
  29
@@ -65,17 +66,24 @@ module TimeMath
65
66
  components[2] = [components[2], days_in_month].min
66
67
  end
67
68
 
68
- private
69
-
70
- module_function
71
-
72
69
  def extract_component(tm, component)
73
70
  case component
74
71
  when :subsec, :sec_fraction
75
- tm.is_a?(Time) ? tm.subsec : tm.send(:sec_fraction)
72
+ subsec(tm)
76
73
  when *COMMON_UNITS
77
74
  tm.send(component)
78
75
  end
79
76
  end
77
+
78
+ def subsec(tm)
79
+ case tm
80
+ when Time
81
+ tm.subsec
82
+ when Date
83
+ 0
84
+ when DateTime
85
+ tm.send(:sec_fraction)
86
+ end
87
+ end
80
88
  end
81
89
  end
@@ -1,4 +1,4 @@
1
1
  module TimeMath
2
2
  # @private
3
- VERSION = '0.1.0'.freeze
3
+ VERSION = '0.1.1'.freeze
4
4
  end
@@ -31,9 +31,9 @@ Gem::Specification.new do |s|
31
31
  end
32
32
  s.require_paths = ["lib"]
33
33
 
34
- s.add_development_dependency 'rubocop', '>= 0.30'
34
+ s.add_development_dependency 'rubocop', '~> 0.65.0'
35
35
  s.add_development_dependency 'rspec', '>= 3'
36
- s.add_development_dependency 'rubocop-rspec'
36
+ s.add_development_dependency 'rubocop-rspec', '>= 1.17.1'
37
37
  s.add_development_dependency 'rspec-its', '~> 1'
38
38
  s.add_development_dependency 'simplecov', '~> 0.9'
39
39
  s.add_development_dependency 'rake'
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: time_math2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Victor Shepelev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-30 00:00:00.000000000 Z
11
+ date: 2019-03-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.30'
19
+ version: 0.65.0
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0.30'
26
+ version: 0.65.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rspec
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: 1.17.1
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: 1.17.1
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec-its
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -138,7 +138,6 @@ files:
138
138
  - LICENSE.txt
139
139
  - README.md
140
140
  - lib/time_math.rb
141
- - lib/time_math/backports.rb
142
141
  - lib/time_math/measure.rb
143
142
  - lib/time_math/op.rb
144
143
  - lib/time_math/resamplers.rb
@@ -173,7 +172,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
173
172
  version: '0'
174
173
  requirements: []
175
174
  rubyforge_project:
176
- rubygems_version: 2.6.10
175
+ rubygems_version: 2.6.14
177
176
  signing_key:
178
177
  specification_version: 4
179
178
  summary: Easy time math
@@ -1,8 +0,0 @@
1
- # @private
2
- class Array
3
- if RUBY_VERSION < '2.1'
4
- def to_h
5
- Hash[*flatten(1)]
6
- end
7
- end
8
- end