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 +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +1 -1
- data/lib/time_math.rb +2 -3
- data/lib/time_math/measure.rb +0 -2
- data/lib/time_math/op.rb +1 -0
- data/lib/time_math/resamplers.rb +3 -1
- data/lib/time_math/units/base.rb +2 -0
- data/lib/time_math/units/month.rb +0 -2
- data/lib/time_math/units/simple.rb +1 -1
- data/lib/time_math/util.rb +15 -7
- data/lib/time_math/version.rb +1 -1
- data/time_math2.gemspec +2 -2
- metadata +9 -10
- data/lib/time_math/backports.rb +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 30696230b69ae5862c132f959e9fbdf1d09e4b70
|
4
|
+
data.tar.gz: ad25e2782956da2d458dd2ee26fbcf2a896c6a23
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1950a184a7fb2cdf739ef3ac750744c651cafc17bc052f88f9f3a339f749aa7236e29257fee11be21c71f50859d1185073cd2f5c5e3ecdfd45247645616a2410
|
7
|
+
data.tar.gz: 120cd89814db9cee542846bc4eb86372f01bf5942cd54b714cd772c0273eed58fcaeaf5791d27bc5c444169de69e704fe669225954cd7d61508dec3e9b047696
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
data/lib/time_math.rb
CHANGED
@@ -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::
|
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
|
135
|
+
def TimeMath(*arguments) # rubocop:disable Naming/MethodName
|
137
136
|
TimeMath::Op.new(*arguments)
|
138
137
|
end
|
data/lib/time_math/measure.rb
CHANGED
data/lib/time_math/op.rb
CHANGED
data/lib/time_math/resamplers.rb
CHANGED
@@ -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
|
57
|
+
return unless hash.is_a?(Hash) && hash.keys.all?(&Util.method(:timey?))
|
58
|
+
|
57
59
|
new(unit, hash)
|
58
60
|
end
|
59
61
|
|
data/lib/time_math/units/base.rb
CHANGED
@@ -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
|
|
data/lib/time_math/util.rb
CHANGED
@@ -8,10 +8,10 @@ module TimeMath
|
|
8
8
|
module_function
|
9
9
|
|
10
10
|
def timey?(val)
|
11
|
-
[Time, DateTime, Date].
|
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
|
-
|
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
|
data/lib/time_math/version.rb
CHANGED
data/time_math2.gemspec
CHANGED
@@ -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', '
|
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.
|
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:
|
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:
|
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:
|
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:
|
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:
|
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.
|
175
|
+
rubygems_version: 2.6.14
|
177
176
|
signing_key:
|
178
177
|
specification_version: 4
|
179
178
|
summary: Easy time math
|