easy_time 0.2.2 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +2 -2
- data/.rubocop.yml +26 -1
- data/CHANGELOG.md +11 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +5 -1
- data/Guardfile +3 -1
- data/Rakefile +17 -2
- data/easy_time.gemspec +7 -4
- data/lib/easy_time/convert.rb +1 -1
- data/lib/easy_time/version.rb +3 -1
- data/lib/easy_time.rb +11 -10
- metadata +21 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d4f0fb3fb88ee686970dd45f050f0552c21a5cbfa172d47a4e6efcdf49d315a1
|
4
|
+
data.tar.gz: bfd9fd1bf295831fa16c9aede647b3f8390af002937542a60b332893bf03f817
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 00bc14c61c2759891507a8b777708b5fd667353adbcff8255c91870f85d6479fabef87fad4f30bd47d8ead3459173ae979f767b958e20f809fe6d455f6c08bcc
|
7
|
+
data.tar.gz: 1468b0315071178981d7013485c6dca6304a6165d4372c632f722644e3b1864de0c825a1d6356cda2fef07048dbbff0bfc6f0f2ed57f77c2d542778a3df7ec03
|
data/.circleci/config.yml
CHANGED
@@ -5,7 +5,7 @@ orbs:
|
|
5
5
|
defaults: &DEFAULTS
|
6
6
|
resource_class: small
|
7
7
|
docker:
|
8
|
-
- image: cimg/ruby:2.7.
|
8
|
+
- image: cimg/ruby:2.7.8
|
9
9
|
|
10
10
|
environment:
|
11
11
|
BUNDLE_JOBS: 3
|
@@ -17,7 +17,7 @@ defaults: &DEFAULTS
|
|
17
17
|
jobs:
|
18
18
|
build:
|
19
19
|
docker:
|
20
|
-
- image: cimg/ruby:2.7.
|
20
|
+
- image: cimg/ruby:2.7.8
|
21
21
|
executor: ruby/default
|
22
22
|
steps:
|
23
23
|
- checkout
|
data/.rubocop.yml
CHANGED
@@ -5,6 +5,9 @@ Metrics/AbcSize:
|
|
5
5
|
Metrics/CyclomaticComplexity:
|
6
6
|
Enabled: false
|
7
7
|
|
8
|
+
Metrics/BlockLength:
|
9
|
+
Enabled: false
|
10
|
+
|
8
11
|
Metrics/MethodLength:
|
9
12
|
Enabled: false
|
10
13
|
|
@@ -18,10 +21,17 @@ Metrics/ClassLength:
|
|
18
21
|
Layout/ExtraSpacing:
|
19
22
|
Enabled: false
|
20
23
|
|
24
|
+
Layout/HashAlignment:
|
25
|
+
Exclude:
|
26
|
+
- 'Guardfile'
|
27
|
+
|
21
28
|
Layout/LineLength:
|
22
29
|
Enabled: false
|
23
30
|
|
24
|
-
Layout/
|
31
|
+
Layout/SpaceAroundOperators:
|
32
|
+
Enabled: false
|
33
|
+
|
34
|
+
Layout/SpaceInsideArrayLiteralBrackets:
|
25
35
|
Enabled: false
|
26
36
|
|
27
37
|
# Styles
|
@@ -36,3 +46,18 @@ Style/StringLiterals:
|
|
36
46
|
|
37
47
|
Style/RescueModifier:
|
38
48
|
Enabled: false
|
49
|
+
|
50
|
+
Style/TrailingCommaInArrayLiteral:
|
51
|
+
Enabled: false
|
52
|
+
|
53
|
+
Style/FrozenStringLiteralComment:
|
54
|
+
Exclude:
|
55
|
+
- 'bin/*'
|
56
|
+
|
57
|
+
# Lint
|
58
|
+
Lint/ConstantDefinitionInBlock:
|
59
|
+
Enabled: false
|
60
|
+
|
61
|
+
# Naming
|
62
|
+
Naming/BinaryOperatorParameterName:
|
63
|
+
Enabled: false
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,16 @@
|
|
1
1
|
# Change Log for EasyTime
|
2
2
|
|
3
|
+
## [1.0.0] - 2024-02-26
|
4
|
+
|
5
|
+
### Changed
|
6
|
+
|
7
|
+
Changed `convert` to use a named `coerce:` keyword parameter.
|
8
|
+
Updated and modernized the specs.
|
9
|
+
Rubocop complaints satisfied.
|
10
|
+
Bypassed '/specs/' for SimplCov
|
11
|
+
|
12
|
+
###
|
13
|
+
|
3
14
|
## [0.2.2] - 2024-01-18
|
4
15
|
|
5
16
|
### Added
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
easy_time (0.
|
4
|
+
easy_time (1.0.0)
|
5
5
|
activesupport
|
6
6
|
|
7
7
|
GEM
|
@@ -116,6 +116,8 @@ GEM
|
|
116
116
|
unicode-display_width (>= 2.4.0, < 3.0)
|
117
117
|
rubocop-ast (1.30.0)
|
118
118
|
parser (>= 3.2.1.0)
|
119
|
+
rubocop-rake (0.6.0)
|
120
|
+
rubocop (~> 1.0)
|
119
121
|
ruby-progressbar (1.13.0)
|
120
122
|
ruby2_keywords (0.0.5)
|
121
123
|
shellany (0.0.1)
|
@@ -134,6 +136,7 @@ GEM
|
|
134
136
|
|
135
137
|
PLATFORMS
|
136
138
|
ruby
|
139
|
+
x86_64-linux
|
137
140
|
|
138
141
|
DEPENDENCIES
|
139
142
|
activesupport (>= 6.1.4)
|
@@ -150,6 +153,7 @@ DEPENDENCIES
|
|
150
153
|
rspec_junit
|
151
154
|
rspec_junit_formatter
|
152
155
|
rubocop (>= 0.82.0)
|
156
|
+
rubocop-rake
|
153
157
|
simplecov
|
154
158
|
terminal-notifier-guard
|
155
159
|
yard (>= 0.9.24)
|
data/Guardfile
CHANGED
data/Rakefile
CHANGED
@@ -1,8 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "bundler/gem_tasks"
|
2
4
|
require "rspec/core/rake_task"
|
5
|
+
require "rubocop-rake"
|
6
|
+
require "rubocop/rake_task"
|
3
7
|
require 'yard'
|
4
8
|
|
5
9
|
RSpec::Core::RakeTask.new(:spec)
|
10
|
+
RuboCop::RakeTask.new
|
6
11
|
|
7
12
|
namespace :spec do
|
8
13
|
desc "run tests with code coverage"
|
@@ -11,9 +16,19 @@ namespace :spec do
|
|
11
16
|
end
|
12
17
|
end
|
13
18
|
|
19
|
+
task default: %i[spec rubocop]
|
20
|
+
task build: %i[bundle:add_linux]
|
21
|
+
task install: %i[build spec bundle:add_linux]
|
22
|
+
task release: %i[build spec install bundle:add_linux]
|
23
|
+
|
24
|
+
namespace :bundle do
|
25
|
+
desc 'add linux platform to Gemfile.lock'
|
26
|
+
task :add_linux do
|
27
|
+
sh 'bundle lock --add-platform x86_64-linux'
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
14
31
|
YARD::Rake::YardocTask.new do |t|
|
15
32
|
t.options += ['--title', "EasyTime #{EasyTime::VERSION} Documentation"]
|
16
33
|
t.stats_options = ['--list-undoc']
|
17
34
|
end
|
18
|
-
|
19
|
-
task :default => :spec
|
data/easy_time.gemspec
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative 'lib/easy_time/version'
|
2
4
|
|
3
5
|
Gem::Specification.new do |spec|
|
@@ -6,7 +8,7 @@ Gem::Specification.new do |spec|
|
|
6
8
|
spec.authors = ["Alan Stebbens"]
|
7
9
|
spec.email = ["aks@stebbens.org"]
|
8
10
|
|
9
|
-
spec.summary =
|
11
|
+
spec.summary = "Easy auto-conversion of most date and time values with tolerant-comparisons"
|
10
12
|
spec.description =
|
11
13
|
<<~'DESC'
|
12
14
|
|
@@ -26,7 +28,7 @@ Gem::Specification.new do |spec|
|
|
26
28
|
DESC
|
27
29
|
spec.homepage = 'https://github.com/aks/easy_time'
|
28
30
|
spec.license = "MIT"
|
29
|
-
spec.required_ruby_version = Gem::Requirement.new(">= 2.
|
31
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.7")
|
30
32
|
|
31
33
|
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
32
34
|
# spec.metadata["allowed_push_host"] = "https://rubygems.pkg.github.com/aks"
|
@@ -38,7 +40,7 @@ Gem::Specification.new do |spec|
|
|
38
40
|
|
39
41
|
# Specify which files should be added to the gem when it is released.
|
40
42
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
41
|
-
spec.files = Dir.chdir(File.expand_path(
|
43
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
42
44
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
43
45
|
end
|
44
46
|
spec.bindir = "bin"
|
@@ -53,11 +55,12 @@ Gem::Specification.new do |spec|
|
|
53
55
|
spec.add_development_dependency "guard-yard"
|
54
56
|
spec.add_development_dependency "pry-byebug"
|
55
57
|
spec.add_development_dependency "rake"
|
58
|
+
spec.add_development_dependency "redcarpet"
|
56
59
|
spec.add_development_dependency "rspec"
|
57
60
|
spec.add_development_dependency "rspec_junit"
|
58
61
|
spec.add_development_dependency "rspec_junit_formatter"
|
59
|
-
spec.add_development_dependency "redcarpet"
|
60
62
|
spec.add_development_dependency "rubocop", ">= 0.82.0"
|
63
|
+
spec.add_development_dependency "rubocop-rake"
|
61
64
|
spec.add_development_dependency "simplecov"
|
62
65
|
spec.add_development_dependency "terminal-notifier-guard" if /Darwin/.match?(`uname -a`.strip)
|
63
66
|
spec.add_development_dependency "yard", ">= 0.9.24"
|
data/lib/easy_time/convert.rb
CHANGED
@@ -41,7 +41,7 @@ class EasyTime
|
|
41
41
|
# various kinds of date and time values
|
42
42
|
# @param coerce [Boolean] if true, coerce the `arg` into a Time object _(default: true)_
|
43
43
|
# @return [Time]
|
44
|
-
def convert(arg, coerce
|
44
|
+
def convert(arg, coerce: true)
|
45
45
|
case arg
|
46
46
|
when String
|
47
47
|
parse_string(arg) # parse the string value into an EasyTime object
|
data/lib/easy_time/version.rb
CHANGED
data/lib/easy_time.rb
CHANGED
@@ -138,7 +138,6 @@ class EasyTime
|
|
138
138
|
compare(time1, time2, tolerance: tolerance).zero?
|
139
139
|
end
|
140
140
|
|
141
|
-
|
142
141
|
# @overload between?(time1, t_min, t_max, tolerance: nil)
|
143
142
|
# @param time1 [Date,Time,DateTime,EasyTime,Duration,String,Array<Integer>] a time value
|
144
143
|
# @param t_min [Date,Time,DateTime,EasyTime,Duration,String,Array<Integer>] the minimum time
|
@@ -150,7 +149,7 @@ class EasyTime
|
|
150
149
|
# @param time_range [Range] a range `(t_min..t_max)` of time values
|
151
150
|
# @return [Boolean] true if `time_range.min <= time1 <= time_range.max`, using tolerant comparisons
|
152
151
|
|
153
|
-
def between?(time1, t_arg, t_max=nil, tolerance: nil)
|
152
|
+
def between?(time1, t_arg, t_max = nil, tolerance: nil)
|
154
153
|
if t_arg.is_a?(Range)
|
155
154
|
t_min = t_arg.min
|
156
155
|
t_max = t_arg.max
|
@@ -221,13 +220,13 @@ class EasyTime
|
|
221
220
|
end
|
222
221
|
end
|
223
222
|
|
224
|
-
def respond_to_missing?(symbol, include_all=false)
|
223
|
+
def respond_to_missing?(symbol, include_all = false)
|
225
224
|
Time.respond_to?(symbol, include_all)
|
226
225
|
end
|
227
226
|
|
228
227
|
# @param value [Anything] value to test as a time-like object
|
229
228
|
# @return [Boolean] true if value is one the known Time classes, or responds to :acts_like_time?
|
230
|
-
def
|
229
|
+
def a_time?(value)
|
231
230
|
case value
|
232
231
|
when Integer, ActiveSupport::Duration
|
233
232
|
false
|
@@ -237,6 +236,7 @@ class EasyTime
|
|
237
236
|
value.respond_to?(:acts_like_time?) && value.acts_like_time?
|
238
237
|
end
|
239
238
|
end
|
239
|
+
alias is_a_time? a_time?
|
240
240
|
end
|
241
241
|
|
242
242
|
attr_accessor :time
|
@@ -318,7 +318,7 @@ class EasyTime
|
|
318
318
|
# @return [Integer] one of [-1, 0, 1] or nil
|
319
319
|
|
320
320
|
def <=>(other)
|
321
|
-
diff = self - other #
|
321
|
+
diff = self - other # NOTE: this has a side-effect of setting @other_time
|
322
322
|
if diff && diff.to_i.abs <= comparison_tolerance.to_i
|
323
323
|
0
|
324
324
|
elsif diff
|
@@ -362,7 +362,7 @@ class EasyTime
|
|
362
362
|
# a date/time value, a duration, or an Integer
|
363
363
|
# @return [EasyTime,Integer] updated time _(time - duration)_ or duration _(time - time)_
|
364
364
|
def -(other)
|
365
|
-
@other_time = convert(other, false)
|
365
|
+
@other_time = convert(other, coerce: false)
|
366
366
|
if is_a_time?(other_time)
|
367
367
|
time - other_time
|
368
368
|
elsif other_time
|
@@ -376,8 +376,8 @@ class EasyTime
|
|
376
376
|
|
377
377
|
private
|
378
378
|
|
379
|
-
def convert(datetime, coerce
|
380
|
-
self.class.convert(datetime, coerce)
|
379
|
+
def convert(datetime, coerce: true)
|
380
|
+
self.class.convert(datetime, coerce: coerce)
|
381
381
|
end
|
382
382
|
|
383
383
|
# intercept any time methods so they can wrap the time-like result in a new EasyTime object.
|
@@ -390,13 +390,14 @@ class EasyTime
|
|
390
390
|
end
|
391
391
|
end
|
392
392
|
|
393
|
-
def respond_to_missing?(symbol, include_all=false)
|
393
|
+
def respond_to_missing?(symbol, include_all = false)
|
394
394
|
time.respond_to?(symbol, include_all)
|
395
395
|
end
|
396
396
|
|
397
|
-
def
|
397
|
+
def a_time?(value)
|
398
398
|
self.class.is_a_time?(value)
|
399
399
|
end
|
400
|
+
alias is_a_time? a_time?
|
400
401
|
end
|
401
402
|
|
402
403
|
# Extend the known date and time classes _(including EasyTime itself!)_
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: easy_time
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alan Stebbens
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-02-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -123,7 +123,7 @@ dependencies:
|
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
|
-
name:
|
126
|
+
name: redcarpet
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
128
128
|
requirements:
|
129
129
|
- - ">="
|
@@ -137,7 +137,7 @@ dependencies:
|
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '0'
|
139
139
|
- !ruby/object:Gem::Dependency
|
140
|
-
name:
|
140
|
+
name: rspec
|
141
141
|
requirement: !ruby/object:Gem::Requirement
|
142
142
|
requirements:
|
143
143
|
- - ">="
|
@@ -151,7 +151,7 @@ dependencies:
|
|
151
151
|
- !ruby/object:Gem::Version
|
152
152
|
version: '0'
|
153
153
|
- !ruby/object:Gem::Dependency
|
154
|
-
name:
|
154
|
+
name: rspec_junit
|
155
155
|
requirement: !ruby/object:Gem::Requirement
|
156
156
|
requirements:
|
157
157
|
- - ">="
|
@@ -165,7 +165,7 @@ dependencies:
|
|
165
165
|
- !ruby/object:Gem::Version
|
166
166
|
version: '0'
|
167
167
|
- !ruby/object:Gem::Dependency
|
168
|
-
name:
|
168
|
+
name: rspec_junit_formatter
|
169
169
|
requirement: !ruby/object:Gem::Requirement
|
170
170
|
requirements:
|
171
171
|
- - ">="
|
@@ -192,6 +192,20 @@ dependencies:
|
|
192
192
|
- - ">="
|
193
193
|
- !ruby/object:Gem::Version
|
194
194
|
version: 0.82.0
|
195
|
+
- !ruby/object:Gem::Dependency
|
196
|
+
name: rubocop-rake
|
197
|
+
requirement: !ruby/object:Gem::Requirement
|
198
|
+
requirements:
|
199
|
+
- - ">="
|
200
|
+
- !ruby/object:Gem::Version
|
201
|
+
version: '0'
|
202
|
+
type: :development
|
203
|
+
prerelease: false
|
204
|
+
version_requirements: !ruby/object:Gem::Requirement
|
205
|
+
requirements:
|
206
|
+
- - ">="
|
207
|
+
- !ruby/object:Gem::Version
|
208
|
+
version: '0'
|
195
209
|
- !ruby/object:Gem::Dependency
|
196
210
|
name: simplecov
|
197
211
|
requirement: !ruby/object:Gem::Requirement
|
@@ -306,7 +320,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
306
320
|
requirements:
|
307
321
|
- - ">="
|
308
322
|
- !ruby/object:Gem::Version
|
309
|
-
version: 2.
|
323
|
+
version: '2.7'
|
310
324
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
311
325
|
requirements:
|
312
326
|
- - ">="
|