tempus 1.0.1 → 1.0.2
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/.hound.yml +1 -1
- data/.rubocop.yml +5 -0
- data/.travis.yml +2 -3
- data/CODE_OF_CONDUCT.md +3 -3
- data/Gemfile.lock +30 -28
- data/README.md +4 -3
- data/lib/tempus.rb +17 -45
- data/lib/tempus/parser.rb +39 -0
- data/lib/tempus/tempus_helper.rb +1 -1
- data/lib/tempus/version.rb +1 -1
- data/tempus.gemspec +12 -14
- metadata +15 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3a87552c97756fad29ee94fd1f92a21f9fd1cc3f5992ea0cff9cc3d7c142f901
|
4
|
+
data.tar.gz: cbb553cd446f654d7337876d0838fe8cd0349fc4928852a181f0c706c2d3b8e9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dc27715ac6f21750df4ec9b04a80411428e2e003b16c1e72b2e35c15f69692963bc5f145fe1b64e4d6020643a6ecf756e97b7ce5fa54867ea2a37ea64708180c
|
7
|
+
data.tar.gz: 4793c0892203ec2ded2bd084c412ec9b3c325ed35160a1bff251aa6c1c431def8c8e83a7cb103e0bd32478f5f263fa92a11c00aefb29be1e79c3f00b4e0d20c3
|
data/.hound.yml
CHANGED
data/.rubocop.yml
CHANGED
data/.travis.yml
CHANGED
data/CODE_OF_CONDUCT.md
CHANGED
@@ -68,7 +68,7 @@ members of the project's leadership.
|
|
68
68
|
## Attribution
|
69
69
|
|
70
70
|
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
-
available at [
|
71
|
+
available at [https://contributor-covenant.org/version/1/4][version]
|
72
72
|
|
73
|
-
[homepage]:
|
74
|
-
[version]:
|
73
|
+
[homepage]: https://contributor-covenant.org
|
74
|
+
[version]: https://contributor-covenant.org/version/1/4/
|
data/Gemfile.lock
CHANGED
@@ -1,19 +1,19 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
tempus (1.0.
|
4
|
+
tempus (1.0.2)
|
5
5
|
activesupport (> 5)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
activesupport (6.0.
|
10
|
+
activesupport (6.0.2.1)
|
11
11
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
12
12
|
i18n (>= 0.7, < 2)
|
13
13
|
minitest (~> 5.1)
|
14
14
|
tzinfo (~> 1.1)
|
15
|
-
zeitwerk (~> 2.
|
16
|
-
concurrent-ruby (1.1.
|
15
|
+
zeitwerk (~> 2.2)
|
16
|
+
concurrent-ruby (1.1.6)
|
17
17
|
coveralls (0.8.23)
|
18
18
|
json (>= 1.8, < 3)
|
19
19
|
simplecov (~> 0.16.1)
|
@@ -22,48 +22,50 @@ GEM
|
|
22
22
|
tins (~> 1.6)
|
23
23
|
diff-lcs (1.3)
|
24
24
|
docile (1.3.2)
|
25
|
-
i18n (1.
|
25
|
+
i18n (1.8.2)
|
26
26
|
concurrent-ruby (~> 1.0)
|
27
|
-
json (2.
|
28
|
-
minitest (5.
|
29
|
-
rake (
|
30
|
-
rspec (3.
|
31
|
-
rspec-core (~> 3.
|
32
|
-
rspec-expectations (~> 3.
|
33
|
-
rspec-mocks (~> 3.
|
34
|
-
rspec-core (3.
|
35
|
-
rspec-support (~> 3.
|
36
|
-
rspec-expectations (3.
|
27
|
+
json (2.3.0)
|
28
|
+
minitest (5.14.0)
|
29
|
+
rake (13.0.1)
|
30
|
+
rspec (3.9.0)
|
31
|
+
rspec-core (~> 3.9.0)
|
32
|
+
rspec-expectations (~> 3.9.0)
|
33
|
+
rspec-mocks (~> 3.9.0)
|
34
|
+
rspec-core (3.9.1)
|
35
|
+
rspec-support (~> 3.9.1)
|
36
|
+
rspec-expectations (3.9.1)
|
37
37
|
diff-lcs (>= 1.2.0, < 2.0)
|
38
|
-
rspec-support (~> 3.
|
39
|
-
rspec-mocks (3.
|
38
|
+
rspec-support (~> 3.9.0)
|
39
|
+
rspec-mocks (3.9.1)
|
40
40
|
diff-lcs (>= 1.2.0, < 2.0)
|
41
|
-
rspec-support (~> 3.
|
42
|
-
rspec-support (3.
|
41
|
+
rspec-support (~> 3.9.0)
|
42
|
+
rspec-support (3.9.2)
|
43
43
|
simplecov (0.16.1)
|
44
44
|
docile (~> 1.1)
|
45
45
|
json (>= 1.8, < 3)
|
46
46
|
simplecov-html (~> 0.10.0)
|
47
47
|
simplecov-html (0.10.2)
|
48
|
+
sync (0.5.0)
|
48
49
|
term-ansicolor (1.7.1)
|
49
50
|
tins (~> 1.0)
|
50
|
-
thor (0.
|
51
|
+
thor (1.0.1)
|
51
52
|
thread_safe (0.3.6)
|
52
|
-
tins (1.
|
53
|
-
|
53
|
+
tins (1.24.1)
|
54
|
+
sync
|
55
|
+
tzinfo (1.2.6)
|
54
56
|
thread_safe (~> 0.1)
|
55
|
-
zeitwerk (2.
|
57
|
+
zeitwerk (2.3.0)
|
56
58
|
|
57
59
|
PLATFORMS
|
58
60
|
ruby
|
59
61
|
|
60
62
|
DEPENDENCIES
|
61
|
-
bundler (~> 1
|
63
|
+
bundler (~> 2.1)
|
62
64
|
coveralls (~> 0.8)
|
63
|
-
rake (~>
|
64
|
-
rspec (~> 3.
|
65
|
-
simplecov (~> 0.
|
65
|
+
rake (~> 13.0)
|
66
|
+
rspec (~> 3.9)
|
67
|
+
simplecov (~> 0.9)
|
66
68
|
tempus!
|
67
69
|
|
68
70
|
BUNDLED WITH
|
69
|
-
1.
|
71
|
+
2.1.4
|
data/README.md
CHANGED
@@ -16,7 +16,7 @@ gem 'tempus'
|
|
16
16
|
|
17
17
|
And then execute:
|
18
18
|
|
19
|
-
$ bundle
|
19
|
+
$ bundle install
|
20
20
|
|
21
21
|
Or install it yourself as:
|
22
22
|
|
@@ -61,7 +61,8 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
61
61
|
|
62
62
|
## Contributing
|
63
63
|
|
64
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/dannnylo/tempus. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [
|
64
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/dannnylo/tempus. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/dannnylo/tempus/blob/master/CODE_OF_CONDUCT.md).
|
65
|
+
|
65
66
|
|
66
67
|
## License
|
67
68
|
|
@@ -69,4 +70,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
69
70
|
|
70
71
|
## Code of Conduct
|
71
72
|
|
72
|
-
Everyone interacting in the Tempus project
|
73
|
+
Everyone interacting in the Tempus project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/dannnylo/tempus/blob/master/CODE_OF_CONDUCT.md).
|
data/lib/tempus.rb
CHANGED
@@ -4,6 +4,7 @@ require 'active_support'
|
|
4
4
|
require 'active_support/core_ext'
|
5
5
|
|
6
6
|
require 'tempus/version'
|
7
|
+
require 'tempus/parser'
|
7
8
|
require 'tempus/tempus_helper'
|
8
9
|
|
9
10
|
# Class to manipulate efficiently time
|
@@ -16,39 +17,20 @@ class Tempus
|
|
16
17
|
HOURS_REGEX = /(\%h|\%hh|\%H|\%HH)/.freeze
|
17
18
|
MINUTES_REGEX = /(\%m|\%mm|\%M|\%MM)/.freeze
|
18
19
|
SECONDS_REGEX = /(\%s|\%ss|\%S|\%SS)/.freeze
|
20
|
+
OPERATIONS = %i[+ - * /].freeze
|
19
21
|
|
20
22
|
attr_reader :data
|
21
23
|
|
22
24
|
delegate :to_i, :to_f, :negative?, :positive?, to: :data
|
23
25
|
|
24
26
|
def initialize(value = 0, only_hours = true)
|
25
|
-
@
|
26
|
-
end
|
27
|
-
|
28
|
-
def set(value, only_hours = true)
|
29
|
-
@data = transform(value, only_hours)
|
30
|
-
end
|
27
|
+
@parser = Parser.new(only_hours)
|
31
28
|
|
32
|
-
|
33
|
-
return from_string(value).to_f if value.is_a?(String)
|
34
|
-
return from_time(value, only_hours).to_f if value.is_a?(Time)
|
35
|
-
|
36
|
-
value.to_f
|
29
|
+
set(value)
|
37
30
|
end
|
38
31
|
|
39
|
-
def
|
40
|
-
|
41
|
-
value = 0
|
42
|
-
|
43
|
-
%i[hours minutes seconds].each_with_index do |m, i|
|
44
|
-
value += str.at(i).to_i.abs.send(m.to_s)
|
45
|
-
end
|
46
|
-
|
47
|
-
str.to_s.include?('-') ? value * -1 : value
|
48
|
-
end
|
49
|
-
|
50
|
-
def from_time(value, only_hours = true)
|
51
|
-
(only_hours ? value - value.beginning_of_day : value).to_f
|
32
|
+
def set(value)
|
33
|
+
@data = @parser.parse(value)
|
52
34
|
end
|
53
35
|
|
54
36
|
# Format the duration to para HH:MM:SS .
|
@@ -78,7 +60,7 @@ class Tempus
|
|
78
60
|
alias to_string to_s
|
79
61
|
|
80
62
|
def format_number_abs(number)
|
81
|
-
format('%
|
63
|
+
format('%02<number>d', number: number.to_i.abs)
|
82
64
|
end
|
83
65
|
|
84
66
|
def seconds
|
@@ -111,26 +93,6 @@ class Tempus
|
|
111
93
|
|
112
94
|
alias to_xls_time value_in_days
|
113
95
|
|
114
|
-
# Sum values of instance
|
115
|
-
def +(other)
|
116
|
-
Tempus.new(data + transform(other))
|
117
|
-
end
|
118
|
-
|
119
|
-
# Subtract values of instance
|
120
|
-
def -(other)
|
121
|
-
Tempus.new(data - transform(other))
|
122
|
-
end
|
123
|
-
|
124
|
-
# Multiplication values of instance
|
125
|
-
def *(other)
|
126
|
-
Tempus.new(data * transform(other))
|
127
|
-
end
|
128
|
-
|
129
|
-
# Division values of instance
|
130
|
-
def /(other)
|
131
|
-
Tempus.new(data / transform(other))
|
132
|
-
end
|
133
|
-
|
134
96
|
def human
|
135
97
|
[
|
136
98
|
('menos' if negative?),
|
@@ -150,4 +112,14 @@ class Tempus
|
|
150
112
|
|
151
113
|
data == other.data
|
152
114
|
end
|
115
|
+
|
116
|
+
def method_missing(method_name, *args, &block)
|
117
|
+
return super unless OPERATIONS.include?(method_name)
|
118
|
+
|
119
|
+
@data.send(method_name, @parser.parse(args.first)).to_tempus
|
120
|
+
end
|
121
|
+
|
122
|
+
def respond_to_missing?(method_name, include_private = false)
|
123
|
+
OPERATIONS.include?(method_name.to_sym) || super
|
124
|
+
end
|
153
125
|
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Parser others types to value
|
4
|
+
class Parser
|
5
|
+
def initialize(only_hours = true)
|
6
|
+
@only_hours = only_hours
|
7
|
+
end
|
8
|
+
|
9
|
+
def parse(value)
|
10
|
+
@value = value
|
11
|
+
|
12
|
+
if @value.is_a?(String)
|
13
|
+
from_string.to_f
|
14
|
+
elsif @value.is_a?(Time)
|
15
|
+
from_time.to_f
|
16
|
+
else
|
17
|
+
@value.to_f
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def from_time
|
24
|
+
return @value.to_f unless @only_hours
|
25
|
+
|
26
|
+
(@value - @value.beginning_of_day).to_f
|
27
|
+
end
|
28
|
+
|
29
|
+
def from_string
|
30
|
+
str = @value.to_s.split(':')
|
31
|
+
value = 0
|
32
|
+
|
33
|
+
%i[hours minutes seconds].each_with_index do |m, i|
|
34
|
+
value += str.at(i).to_i.abs.send(m.to_s)
|
35
|
+
end
|
36
|
+
|
37
|
+
str.to_s.include?('-') ? value * -1 : value
|
38
|
+
end
|
39
|
+
end
|
data/lib/tempus/tempus_helper.rb
CHANGED
data/lib/tempus/version.rb
CHANGED
data/tempus.gemspec
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
-
require 'tempus/version'
|
3
|
+
require_relative 'lib/tempus/version'
|
6
4
|
|
7
5
|
Gem::Specification.new do |spec|
|
8
6
|
spec.name = 'tempus'
|
@@ -18,21 +16,21 @@ Gem::Specification.new do |spec|
|
|
18
16
|
|
19
17
|
spec.homepage = 'https://github.com/dannnylo/tempus'
|
20
18
|
spec.license = 'MIT'
|
19
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
|
21
20
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
spec.files
|
26
|
-
|
27
|
-
files.reject { |f| f.match(%r{^(test|spec|features)/}) }
|
21
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
22
|
+
spec.metadata['source_code_uri'] = spec.homepage
|
23
|
+
|
24
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
25
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
28
26
|
end
|
29
27
|
spec.bindir = 'exe'
|
30
28
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
31
|
-
spec.require_paths = ['lib'
|
29
|
+
spec.require_paths = ['lib']
|
32
30
|
spec.add_runtime_dependency 'activesupport', '> 5'
|
33
|
-
spec.add_development_dependency 'bundler', '~> 1
|
31
|
+
spec.add_development_dependency 'bundler', '~> 2.1'
|
34
32
|
spec.add_development_dependency 'coveralls', '~> 0.8'
|
35
|
-
spec.add_development_dependency 'rake', '~>
|
36
|
-
spec.add_development_dependency 'rspec', '~> 3.
|
37
|
-
spec.add_development_dependency 'simplecov', '~> 0.
|
33
|
+
spec.add_development_dependency 'rake', '~> 13.0'
|
34
|
+
spec.add_development_dependency 'rspec', '~> 3.9'
|
35
|
+
spec.add_development_dependency 'simplecov', '~> 0.9'
|
38
36
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tempus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Danilo Jeremias da Silva
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-03-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '1
|
33
|
+
version: '2.1'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '1
|
40
|
+
version: '2.1'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: coveralls
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -58,42 +58,42 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '13.0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '13.0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rspec
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '3.
|
75
|
+
version: '3.9'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '3.
|
82
|
+
version: '3.9'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: simplecov
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: '0.
|
89
|
+
version: '0.9'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: '0.
|
96
|
+
version: '0.9'
|
97
97
|
description: |2
|
98
98
|
Gem to efficiently manipulate the time.
|
99
99
|
Adding, subtracting and converting more than 24 hours easy.'
|
@@ -118,23 +118,25 @@ files:
|
|
118
118
|
- bin/console
|
119
119
|
- bin/setup
|
120
120
|
- lib/tempus.rb
|
121
|
+
- lib/tempus/parser.rb
|
121
122
|
- lib/tempus/tempus_helper.rb
|
122
123
|
- lib/tempus/version.rb
|
123
124
|
- tempus.gemspec
|
124
125
|
homepage: https://github.com/dannnylo/tempus
|
125
126
|
licenses:
|
126
127
|
- MIT
|
127
|
-
metadata:
|
128
|
+
metadata:
|
129
|
+
homepage_uri: https://github.com/dannnylo/tempus
|
130
|
+
source_code_uri: https://github.com/dannnylo/tempus
|
128
131
|
post_install_message:
|
129
132
|
rdoc_options: []
|
130
133
|
require_paths:
|
131
134
|
- lib
|
132
|
-
- lib/tempus
|
133
135
|
required_ruby_version: !ruby/object:Gem::Requirement
|
134
136
|
requirements:
|
135
137
|
- - ">="
|
136
138
|
- !ruby/object:Gem::Version
|
137
|
-
version:
|
139
|
+
version: 2.3.0
|
138
140
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
139
141
|
requirements:
|
140
142
|
- - ">="
|