time-duration 0.1.1 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/dependabot.yml +7 -0
- data/.github/workflows/ruby.yml +22 -0
- data/Gemfile.lock +15 -16
- data/README.md +9 -3
- data/lib/time_duration/duration.rb +50 -0
- data/lib/time_duration/version.rb +1 -1
- data/lib/time_duration.rb +10 -46
- data/time_duration.gemspec +1 -2
- metadata +11 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9a26a627502171812a05f09fee9c25d42774f827b296206090a0a559b653cfe2
|
4
|
+
data.tar.gz: 4317eb5b20a7c18a8ece93eb37579d893a2fc641ce920866f566e10a11357aca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4bdfc52761ab4f60bb788cda44955a7017e743cf332d0fa572e6164bca51082ed899b3b2f370c3b3d93b125d12cff7c4fc1e7dc34d81f28f9db9b57b7c102e7a
|
7
|
+
data.tar.gz: f6803e8c7a572b45c2dbdd5b3c0171702568d648106392c8b55968bb7577e135f3f07267ff04da69334353f680c215634264dc1ba52fa96aaaeb823ec6d218d4
|
@@ -0,0 +1,22 @@
|
|
1
|
+
name: Ruby
|
2
|
+
|
3
|
+
on: [push]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
build:
|
7
|
+
runs-on: ubuntu-latest
|
8
|
+
strategy:
|
9
|
+
matrix:
|
10
|
+
ruby: ['2.5.x', '2.6.x', '2.7.x', '3.0.x']
|
11
|
+
steps:
|
12
|
+
- uses: actions/checkout@v1
|
13
|
+
- name: Set up Ruby
|
14
|
+
uses: actions/setup-ruby@v1
|
15
|
+
with:
|
16
|
+
ruby-version: ${{ matrix.ruby }}
|
17
|
+
- name: Build and test with Rake
|
18
|
+
run: |
|
19
|
+
gem install bundler
|
20
|
+
bundle update --bundler
|
21
|
+
bundle install --jobs 4 --retry 3
|
22
|
+
bundle exec rake
|
data/Gemfile.lock
CHANGED
@@ -1,35 +1,34 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
time-duration (0.1.
|
4
|
+
time-duration (0.1.3)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
9
|
diff-lcs (1.3)
|
10
|
-
rake (
|
11
|
-
rspec (3.
|
12
|
-
rspec-core (~> 3.
|
13
|
-
rspec-expectations (~> 3.
|
14
|
-
rspec-mocks (~> 3.
|
15
|
-
rspec-core (3.
|
16
|
-
rspec-support (~> 3.
|
17
|
-
rspec-expectations (3.
|
10
|
+
rake (13.0.1)
|
11
|
+
rspec (3.9.0)
|
12
|
+
rspec-core (~> 3.9.0)
|
13
|
+
rspec-expectations (~> 3.9.0)
|
14
|
+
rspec-mocks (~> 3.9.0)
|
15
|
+
rspec-core (3.9.0)
|
16
|
+
rspec-support (~> 3.9.0)
|
17
|
+
rspec-expectations (3.9.0)
|
18
18
|
diff-lcs (>= 1.2.0, < 2.0)
|
19
|
-
rspec-support (~> 3.
|
20
|
-
rspec-mocks (3.
|
19
|
+
rspec-support (~> 3.9.0)
|
20
|
+
rspec-mocks (3.9.0)
|
21
21
|
diff-lcs (>= 1.2.0, < 2.0)
|
22
|
-
rspec-support (~> 3.
|
23
|
-
rspec-support (3.
|
22
|
+
rspec-support (~> 3.9.0)
|
23
|
+
rspec-support (3.9.0)
|
24
24
|
|
25
25
|
PLATFORMS
|
26
26
|
ruby
|
27
27
|
|
28
28
|
DEPENDENCIES
|
29
|
-
|
30
|
-
rake (~> 10.0)
|
29
|
+
rake (~> 13.0)
|
31
30
|
rspec (~> 3.0)
|
32
31
|
time-duration!
|
33
32
|
|
34
33
|
BUNDLED WITH
|
35
|
-
1.
|
34
|
+
2.1.4
|
data/README.md
CHANGED
@@ -34,9 +34,15 @@ duration.to_s # => "2:10"
|
|
34
34
|
|
35
35
|
```ruby
|
36
36
|
TimeDuration::Duration.new # => 0:00
|
37
|
-
TimeDuration::Duration.new(
|
38
|
-
TimeDuration::Duration.new(
|
39
|
-
TimeDuration::Duration.new(
|
37
|
+
TimeDuration::Duration.new(minute: 10) # => 0:10
|
38
|
+
TimeDuration::Duration.new(hour: 1) # => 1:00
|
39
|
+
TimeDuration::Duration.new(hour: 1, minute: 10) # => 1:10
|
40
|
+
```
|
41
|
+
|
42
|
+
#### Shorthands
|
43
|
+
```ruby
|
44
|
+
TimeDuration.hour(8) # => 8:00
|
45
|
+
TimeDuration.minute(8) # => 0:08
|
40
46
|
```
|
41
47
|
|
42
48
|
### Operations
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module TimeDuration
|
2
|
+
class Duration
|
3
|
+
include Comparable
|
4
|
+
|
5
|
+
attr_reader :second
|
6
|
+
|
7
|
+
# TODO: format指定できるようにする
|
8
|
+
def self.parse(time_as_string, format: '%H:%M')
|
9
|
+
hour, minute = time_as_string.split(':').map(&:to_i)
|
10
|
+
new(hour: hour, minute: minute)
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize(hour: 0, minute: 0, second: 0)
|
14
|
+
hour = hour.to_i
|
15
|
+
minute = minute.to_i
|
16
|
+
second = second.to_i
|
17
|
+
@second = hour * 3600 + minute * 60 + second
|
18
|
+
end
|
19
|
+
|
20
|
+
def hour
|
21
|
+
minute / 60 + second.abs / 3600
|
22
|
+
end
|
23
|
+
|
24
|
+
def minute
|
25
|
+
(second.abs / 60) % 60
|
26
|
+
end
|
27
|
+
|
28
|
+
# TODO: format指定できるようにする
|
29
|
+
def to_s
|
30
|
+
"#{'-' if second < 0}%d:%02d" % [hour, minute]
|
31
|
+
end
|
32
|
+
|
33
|
+
def +(time_duration)
|
34
|
+
self.class.new(second: second + time_duration.second)
|
35
|
+
end
|
36
|
+
|
37
|
+
def -(time_duration)
|
38
|
+
self.class.new(second: second - time_duration.second)
|
39
|
+
end
|
40
|
+
|
41
|
+
def <=>(time_duration)
|
42
|
+
self.second <=> time_duration.second
|
43
|
+
end
|
44
|
+
|
45
|
+
# override
|
46
|
+
def inspect
|
47
|
+
to_s
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/lib/time_duration.rb
CHANGED
@@ -1,56 +1,20 @@
|
|
1
|
-
require
|
1
|
+
require 'time_duration/version'
|
2
|
+
require 'time_duration/duration'
|
2
3
|
|
3
4
|
module TimeDuration
|
4
5
|
def self.parse(args)
|
5
6
|
Duration.parse(args)
|
6
7
|
end
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
attr_accessor :seconds
|
12
|
-
|
13
|
-
# TODO: format指定できるようにする
|
14
|
-
def self.parse(time_as_string)
|
15
|
-
hours, minutes = time_as_string.split(':').map(&:to_i)
|
16
|
-
new(hours: hours, minutes: minutes)
|
17
|
-
end
|
18
|
-
|
19
|
-
def initialize(hours: 0, minutes: 0, seconds: 0)
|
20
|
-
hours = hours.to_i
|
21
|
-
minutes = minutes.to_i
|
22
|
-
seconds = seconds.to_i
|
23
|
-
@seconds = hours * 3600 + minutes * 60 + seconds
|
24
|
-
end
|
25
|
-
|
26
|
-
def hours
|
27
|
-
minutes / 60 + seconds / 3600
|
28
|
-
end
|
29
|
-
|
30
|
-
def minutes
|
31
|
-
(seconds / 60) % 60
|
32
|
-
end
|
33
|
-
|
34
|
-
# TODO: format指定できるようにする
|
35
|
-
def to_s
|
36
|
-
"%d:%02d" % [hours, minutes]
|
37
|
-
end
|
38
|
-
|
39
|
-
def +(time_duration)
|
40
|
-
self.class.new(seconds: seconds + time_duration.seconds)
|
41
|
-
end
|
42
|
-
|
43
|
-
def -(time_duration)
|
44
|
-
self.class.new(seconds: seconds - time_duration.seconds)
|
45
|
-
end
|
9
|
+
def self.hour(hour)
|
10
|
+
Duration.new(hour: hour)
|
11
|
+
end
|
46
12
|
|
47
|
-
|
48
|
-
|
49
|
-
|
13
|
+
def self.minute(minute)
|
14
|
+
Duration.new(minute: minute)
|
15
|
+
end
|
50
16
|
|
51
|
-
|
52
|
-
|
53
|
-
to_s
|
54
|
-
end
|
17
|
+
def self.second(second)
|
18
|
+
Duration.new(second: second)
|
55
19
|
end
|
56
20
|
end
|
data/time_duration.gemspec
CHANGED
@@ -22,7 +22,6 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
23
|
spec.require_paths = ["lib"]
|
24
24
|
|
25
|
-
spec.add_development_dependency "
|
26
|
-
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
27
26
|
spec.add_development_dependency "rspec", "~> 3.0"
|
28
27
|
end
|
metadata
CHANGED
@@ -1,43 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: time-duration
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daiki Matoba
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-03-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: bundler
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '1.17'
|
20
|
-
type: :development
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '1.17'
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: rake
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
30
16
|
requirements:
|
31
17
|
- - "~>"
|
32
18
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
19
|
+
version: '13.0'
|
34
20
|
type: :development
|
35
21
|
prerelease: false
|
36
22
|
version_requirements: !ruby/object:Gem::Requirement
|
37
23
|
requirements:
|
38
24
|
- - "~>"
|
39
25
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
26
|
+
version: '13.0'
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
28
|
name: rspec
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -59,6 +45,8 @@ executables: []
|
|
59
45
|
extensions: []
|
60
46
|
extra_rdoc_files: []
|
61
47
|
files:
|
48
|
+
- ".github/dependabot.yml"
|
49
|
+
- ".github/workflows/ruby.yml"
|
62
50
|
- ".gitignore"
|
63
51
|
- ".rspec"
|
64
52
|
- ".travis.yml"
|
@@ -69,12 +57,13 @@ files:
|
|
69
57
|
- bin/console
|
70
58
|
- bin/setup
|
71
59
|
- lib/time_duration.rb
|
60
|
+
- lib/time_duration/duration.rb
|
72
61
|
- lib/time_duration/version.rb
|
73
62
|
- time_duration.gemspec
|
74
63
|
homepage: https://github.com/d-mato/time_duration
|
75
64
|
licenses: []
|
76
65
|
metadata: {}
|
77
|
-
post_install_message:
|
66
|
+
post_install_message:
|
78
67
|
rdoc_options: []
|
79
68
|
require_paths:
|
80
69
|
- lib
|
@@ -89,8 +78,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
89
78
|
- !ruby/object:Gem::Version
|
90
79
|
version: '0'
|
91
80
|
requirements: []
|
92
|
-
rubygems_version: 3.
|
93
|
-
signing_key:
|
81
|
+
rubygems_version: 3.2.32
|
82
|
+
signing_key:
|
94
83
|
specification_version: 4
|
95
84
|
summary: This module provides functions for expressing durations
|
96
85
|
test_files: []
|