tempus 0.2.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.coveralls.yml +1 -0
- data/.gitignore +11 -0
- data/.hound.yml +3 -0
- data/.rspec +2 -0
- data/.rubocop.yml +3 -0
- data/.travis.yml +6 -3
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -12
- data/Gemfile.lock +61 -78
- data/LICENSE.txt +18 -17
- data/README.md +72 -0
- data/Rakefile +4 -44
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/tempus/tempus_helper.rb +10 -0
- data/lib/tempus/version.rb +5 -0
- data/lib/tempus.rb +95 -171
- data/tempus.gemspec +32 -65
- metadata +43 -52
- data/.document +0 -5
- data/README.rdoc +0 -38
- data/VERSION +0 -1
- data/spec/spec_helper.rb +0 -16
- data/spec/tempus_spec.rb +0 -113
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: cb484b5639a9056346df03f032edb5a4b760cb8f95038e63a14b8addfb4e3870
|
4
|
+
data.tar.gz: fd6fb864680e411abec1319a1a29d275a73471ffacecfd6fa2e0287d0c8b6f1e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8c9eb435c0b25fc7a19e65976b5c174e9ac50491dbcbffda56bcb648177f13ed686d5b384891e0cfb7e68d04f4d747dd8cc66a8705580d02ab93f988c6730f6b
|
7
|
+
data.tar.gz: 9f7fc113198a35d68619263fc42735a79d5fe7818693bc942dbb70fef577b6541aaa8530ab3f7385edb1cb89c8071e995e01e707758a1c6787ebd27999082eb1
|
data/.coveralls.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
repo_token: ELpdfYjCf7cMiE663I70rR0V4mcZwmeia
|
data/.gitignore
ADDED
data/.hound.yml
ADDED
data/.rspec
CHANGED
data/.rubocop.yml
ADDED
data/.travis.yml
CHANGED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at daniloj.dasilva@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
CHANGED
@@ -1,14 +1,8 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
gem "i18n"
|
3
|
+
source 'https://rubygems.org'
|
5
4
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
gem "rdoc", "~> 3.12"
|
11
|
-
gem "bundler", "~> 1.0"
|
12
|
-
gem "jeweler", "~> 2.0.0"
|
13
|
-
gem "simplecov", ">= 0"
|
14
|
-
end
|
5
|
+
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
|
6
|
+
|
7
|
+
# Specify your gem's dependencies in tempus.gemspec
|
8
|
+
gemspec
|
data/Gemfile.lock
CHANGED
@@ -1,86 +1,69 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
tempus (1.0.0)
|
5
|
+
activesupport (> 5)
|
6
|
+
|
1
7
|
GEM
|
2
|
-
remote:
|
8
|
+
remote: https://rubygems.org/
|
3
9
|
specs:
|
4
|
-
activesupport (
|
5
|
-
|
6
|
-
|
7
|
-
|
10
|
+
activesupport (6.0.0)
|
11
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
12
|
+
i18n (>= 0.7, < 2)
|
13
|
+
minitest (~> 5.1)
|
14
|
+
tzinfo (~> 1.1)
|
15
|
+
zeitwerk (~> 2.1, >= 2.1.8)
|
16
|
+
concurrent-ruby (1.1.5)
|
17
|
+
coveralls (0.8.23)
|
18
|
+
json (>= 1.8, < 3)
|
19
|
+
simplecov (~> 0.16.1)
|
20
|
+
term-ansicolor (~> 1.3)
|
21
|
+
thor (>= 0.19.4, < 2.0)
|
22
|
+
tins (~> 1.6)
|
23
|
+
diff-lcs (1.3)
|
24
|
+
docile (1.3.2)
|
25
|
+
i18n (1.6.0)
|
26
|
+
concurrent-ruby (~> 1.0)
|
27
|
+
json (2.2.0)
|
28
|
+
minitest (5.11.3)
|
29
|
+
rake (10.5.0)
|
30
|
+
rspec (3.8.0)
|
31
|
+
rspec-core (~> 3.8.0)
|
32
|
+
rspec-expectations (~> 3.8.0)
|
33
|
+
rspec-mocks (~> 3.8.0)
|
34
|
+
rspec-core (3.8.2)
|
35
|
+
rspec-support (~> 3.8.0)
|
36
|
+
rspec-expectations (3.8.4)
|
37
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
38
|
+
rspec-support (~> 3.8.0)
|
39
|
+
rspec-mocks (3.8.1)
|
40
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
41
|
+
rspec-support (~> 3.8.0)
|
42
|
+
rspec-support (3.8.2)
|
43
|
+
simplecov (0.16.1)
|
44
|
+
docile (~> 1.1)
|
45
|
+
json (>= 1.8, < 3)
|
46
|
+
simplecov-html (~> 0.10.0)
|
47
|
+
simplecov-html (0.10.2)
|
48
|
+
term-ansicolor (1.7.1)
|
49
|
+
tins (~> 1.0)
|
50
|
+
thor (0.20.3)
|
51
|
+
thread_safe (0.3.6)
|
52
|
+
tins (1.21.1)
|
53
|
+
tzinfo (1.2.5)
|
8
54
|
thread_safe (~> 0.1)
|
9
|
-
|
10
|
-
addressable (2.3.5)
|
11
|
-
atomic (1.1.14)
|
12
|
-
builder (3.2.2)
|
13
|
-
descendants_tracker (0.0.3)
|
14
|
-
diff-lcs (1.1.3)
|
15
|
-
docile (1.1.2)
|
16
|
-
faraday (0.9.0)
|
17
|
-
multipart-post (>= 1.2, < 3)
|
18
|
-
git (1.2.6)
|
19
|
-
github_api (0.11.1)
|
20
|
-
addressable (~> 2.3)
|
21
|
-
descendants_tracker (~> 0.0.1)
|
22
|
-
faraday (~> 0.8, < 0.10)
|
23
|
-
hashie (>= 1.2)
|
24
|
-
multi_json (>= 1.7.5, < 2.0)
|
25
|
-
nokogiri (~> 1.6.0)
|
26
|
-
oauth2
|
27
|
-
hashie (2.0.5)
|
28
|
-
highline (1.6.20)
|
29
|
-
i18n (0.6.9)
|
30
|
-
jeweler (2.0.0)
|
31
|
-
builder
|
32
|
-
bundler (>= 1.0)
|
33
|
-
git (>= 1.2.5)
|
34
|
-
github_api
|
35
|
-
highline (>= 1.6.15)
|
36
|
-
nokogiri (>= 1.5.10)
|
37
|
-
rake
|
38
|
-
rdoc
|
39
|
-
json (1.8.1)
|
40
|
-
jwt (0.1.11)
|
41
|
-
multi_json (>= 1.5)
|
42
|
-
mini_portile (0.5.2)
|
43
|
-
minitest (4.7.5)
|
44
|
-
multi_json (1.8.4)
|
45
|
-
multi_xml (0.5.5)
|
46
|
-
multipart-post (2.0.0)
|
47
|
-
nokogiri (1.6.1)
|
48
|
-
mini_portile (~> 0.5.0)
|
49
|
-
oauth2 (0.9.3)
|
50
|
-
faraday (>= 0.8, < 0.10)
|
51
|
-
jwt (~> 0.1.8)
|
52
|
-
multi_json (~> 1.3)
|
53
|
-
multi_xml (~> 0.5)
|
54
|
-
rack (~> 1.2)
|
55
|
-
rack (1.5.2)
|
56
|
-
rake (10.1.1)
|
57
|
-
rdoc (3.12.2)
|
58
|
-
json (~> 1.4)
|
59
|
-
rspec (2.8.0)
|
60
|
-
rspec-core (~> 2.8.0)
|
61
|
-
rspec-expectations (~> 2.8.0)
|
62
|
-
rspec-mocks (~> 2.8.0)
|
63
|
-
rspec-core (2.8.0)
|
64
|
-
rspec-expectations (2.8.0)
|
65
|
-
diff-lcs (~> 1.1.2)
|
66
|
-
rspec-mocks (2.8.0)
|
67
|
-
simplecov (0.8.2)
|
68
|
-
docile (~> 1.1.0)
|
69
|
-
multi_json
|
70
|
-
simplecov-html (~> 0.8.0)
|
71
|
-
simplecov-html (0.8.0)
|
72
|
-
thread_safe (0.1.3)
|
73
|
-
atomic
|
74
|
-
tzinfo (0.3.38)
|
55
|
+
zeitwerk (2.1.9)
|
75
56
|
|
76
57
|
PLATFORMS
|
77
58
|
ruby
|
78
59
|
|
79
60
|
DEPENDENCIES
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
61
|
+
bundler (~> 1.17)
|
62
|
+
coveralls (~> 0.8)
|
63
|
+
rake (~> 10.0)
|
64
|
+
rspec (~> 3.0)
|
65
|
+
simplecov (~> 0.1)
|
66
|
+
tempus!
|
67
|
+
|
68
|
+
BUNDLED WITH
|
69
|
+
1.17.3
|
data/LICENSE.txt
CHANGED
@@ -1,20 +1,21 @@
|
|
1
|
-
|
1
|
+
The MIT License (MIT)
|
2
2
|
|
3
|
-
|
4
|
-
a copy of this software and associated documentation files (the
|
5
|
-
"Software"), to deal in the Software without restriction, including
|
6
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
-
permit persons to whom the Software is furnished to do so, subject to
|
9
|
-
the following conditions:
|
3
|
+
Copyright (c) 2019 Danilo Jeremias da Silva
|
10
4
|
|
11
|
-
|
12
|
-
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
13
11
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
# Tempus
|
2
|
+
|
3
|
+
<a href='http://badge.fury.io/rb/tempus'>
|
4
|
+
<img src="https://badge.fury.io/rb/tempus.png" alt="Gem Version" />
|
5
|
+
</a>
|
6
|
+
|
7
|
+
Gem to efficiently manipulate the time, adding, subtracting and converting hours.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'tempus'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install tempus
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
With this gem you can manage durations of time.
|
27
|
+
|
28
|
+
### Initialize with duration
|
29
|
+
```ruby
|
30
|
+
hours = Tempus.new(30.hours + 5.minutes + 3.seconds)
|
31
|
+
=> <Tempus:8508680 seconds=108303.0, formated=30:05:03>
|
32
|
+
hours.value_in_minutes
|
33
|
+
=> 1805.05
|
34
|
+
hours.to_s("%H hours and %M minutes")
|
35
|
+
=> "30 hours and 05 minutes"
|
36
|
+
```
|
37
|
+
### Convert from other types
|
38
|
+
```ruby
|
39
|
+
hours = "35:05:01".to_tempus
|
40
|
+
=> <Tempus:7228060 seconds=126301.0, formated=35:05:01>
|
41
|
+
hours + 6.hours
|
42
|
+
=> <Tempus:6931320 seconds=147901.0, formated=41:05:01>
|
43
|
+
```
|
44
|
+
```ruby
|
45
|
+
Tempus.new(Time.now)
|
46
|
+
=> <Tempus:6578680 seconds=46455.162950918, formated=12:54:15>
|
47
|
+
```
|
48
|
+
|
49
|
+
### Sum durations
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
"1:00:00".to_tempus + "2:00"
|
53
|
+
=> <Tempus:6634700 seconds=10800.0, formated=03:00:00>
|
54
|
+
```
|
55
|
+
|
56
|
+
## Development
|
57
|
+
|
58
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
59
|
+
|
60
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
61
|
+
|
62
|
+
## Contributing
|
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 [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
65
|
+
|
66
|
+
## License
|
67
|
+
|
68
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
69
|
+
|
70
|
+
## Code of Conduct
|
71
|
+
|
72
|
+
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/Rakefile
CHANGED
@@ -1,48 +1,8 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require '
|
4
|
-
require 'bundler'
|
5
|
-
begin
|
6
|
-
Bundler.setup(:default, :development)
|
7
|
-
rescue Bundler::BundlerError => e
|
8
|
-
$stderr.puts e.message
|
9
|
-
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
-
exit e.status_code
|
11
|
-
end
|
12
|
-
require 'rake'
|
13
|
-
|
14
|
-
require 'jeweler'
|
15
|
-
Jeweler::Tasks.new do |gem|
|
16
|
-
gem.name = "tempus"
|
17
|
-
gem.homepage = "http://github.com/dannnylo/tempus"
|
18
|
-
gem.license = "MIT"
|
19
|
-
gem.summary = %Q{Gem to manipulate efficiently time}
|
20
|
-
gem.description = %Q{Gem to efficiently manipulate the time, adding, subtracting and converting hours.}
|
21
|
-
gem.email = "daniloj.dasilva@gmail.com"
|
22
|
-
gem.authors = ["Danilo Jeremias da Silva"]
|
23
|
-
end
|
24
|
-
Jeweler::RubygemsDotOrgTasks.new
|
25
|
-
|
26
|
-
require 'rspec/core'
|
3
|
+
require 'bundler/gem_tasks'
|
27
4
|
require 'rspec/core/rake_task'
|
28
|
-
RSpec::Core::RakeTask.new(:spec) do |spec|
|
29
|
-
spec.pattern = FileList['spec/**/*_spec.rb']
|
30
|
-
end
|
31
|
-
|
32
|
-
desc "Code coverage detail"
|
33
|
-
task :simplecov do
|
34
|
-
ENV['COVERAGE'] = "true"
|
35
|
-
Rake::Task['spec'].execute
|
36
|
-
end
|
37
|
-
|
38
|
-
task :default => :spec
|
39
5
|
|
40
|
-
|
41
|
-
Rake::RDocTask.new do |rdoc|
|
42
|
-
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
6
|
+
RSpec::Core::RakeTask.new(:spec)
|
43
7
|
|
44
|
-
|
45
|
-
rdoc.title = "tempus #{version}"
|
46
|
-
rdoc.rdoc_files.include('README*')
|
47
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
48
|
-
end
|
8
|
+
task default: :spec
|
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'tempus'
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require 'irb'
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/tempus.rb
CHANGED
@@ -1,219 +1,143 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
require 'active_support'
|
4
|
+
require 'active_support/core_ext'
|
5
|
+
|
6
|
+
require 'tempus/version'
|
7
|
+
require 'tempus/tempus_helper'
|
8
|
+
|
9
|
+
# Class to manipulate efficiently time
|
4
10
|
#=== Example:
|
5
|
-
## >>
|
6
|
-
## => #<Tempus:0xb7016b40 @
|
11
|
+
## >> duration = Tempus.new
|
12
|
+
## => #<Tempus:0xb7016b40 @data=0.0>
|
7
13
|
class Tempus
|
8
|
-
|
14
|
+
class Error < StandardError; end
|
9
15
|
|
10
|
-
|
11
|
-
|
12
|
-
|
16
|
+
HOURS_REGEX = /(\%h|\%hh|\%H|\%HH)/.freeze
|
17
|
+
MINUTES_REGEX = /(\%m|\%mm|\%M|\%MM)/.freeze
|
18
|
+
SECONDS_REGEX = /(\%s|\%ss|\%S|\%SS)/.freeze
|
13
19
|
|
14
|
-
|
15
|
-
## Os valores podem ser passados em inteiros/floats ou Time.
|
16
|
-
## O parâmetro count_all_time se falso serve para transformar apenas a hora de um objeto da classe Time, desconsiderando a data.
|
17
|
-
def set(value=0, count_all_time=false)
|
18
|
-
if(value.class == Time && !count_all_time)
|
19
|
-
@value = (value - value.beginning_of_day).to_f
|
20
|
-
else
|
21
|
-
@value = value.to_f
|
22
|
-
end
|
23
|
-
end
|
20
|
+
attr_accessor :data
|
24
21
|
|
25
|
-
|
26
|
-
#=== Exemplo:
|
27
|
-
## >> horas = Tempus.new(30.hours + 5.minutes + 3.seconds)
|
28
|
-
## => #<Tempus:0xb6e4b860 @value=108303.0>
|
29
|
-
## >> horas.to_s
|
30
|
-
## => "30:05:03"
|
31
|
-
## >> horas = Tempus.new(-30.hours - 5.minutes - 3.seconds)
|
32
|
-
## => #<Tempus:0xb6e4b860 @value=-108303.0>
|
33
|
-
## >> horas.to_s
|
34
|
-
## => "-30:05:03"
|
35
|
-
## >> horas.to_s("%H:%M")
|
36
|
-
## => "-30:05"
|
37
|
-
## >> horas.to_s("%H*%M*%S")
|
38
|
-
## => "-30*05*03"
|
39
|
-
def to_s(format="%H:%M:%S")
|
40
|
-
h, m, s = ("%02d" % hours.to_i.abs), ("%02d" % minutes.to_i.abs), ("%02d" % seconds.to_i.abs)
|
41
|
-
text = format.to_s
|
42
|
-
[
|
43
|
-
["%h", "%H"],
|
44
|
-
["%m", "%M"],
|
45
|
-
["%s", "%S"],
|
46
|
-
["%hh", "%H"],
|
47
|
-
["%mm", "%M"],
|
48
|
-
["%ss", "%S"],
|
49
|
-
["%H", h],
|
50
|
-
["%HH", h],
|
51
|
-
["%M", m],
|
52
|
-
["%MM", m],
|
53
|
-
["%S", s],
|
54
|
-
["%SS", s]
|
55
|
-
].each{|string, replace|text.gsub!(string,replace) }
|
56
|
-
|
57
|
-
return (negative? ? "-" : "") + text unless(text=="")
|
58
|
-
text
|
59
|
-
end
|
60
|
-
|
61
|
-
def convert
|
62
|
-
valor = @value.to_f
|
63
|
-
h = (valor.to_f / 1.hour.to_f ).to_i
|
64
|
-
valor = valor.to_f - h.hours.to_f
|
65
|
-
m = (valor.to_f / 1.minute.to_f).to_i
|
66
|
-
s = (valor.to_f - m.minutes.to_f).to_i
|
67
|
-
return h,m,s
|
68
|
-
end
|
69
|
-
|
70
|
-
#Retorna o número de minutos
|
71
|
-
def minutes
|
72
|
-
convert[1]
|
73
|
-
end
|
22
|
+
delegate :to_i, :to_f, :negative?, :positive?, to: :data
|
74
23
|
|
75
|
-
|
76
|
-
|
77
|
-
convert[2]
|
24
|
+
def initialize(value = 0, only_hours = true)
|
25
|
+
@data = transform(value, only_hours)
|
78
26
|
end
|
79
27
|
|
80
|
-
|
81
|
-
|
82
|
-
convert[0]
|
28
|
+
def set(value, only_hours = true)
|
29
|
+
@data = transform(value, only_hours)
|
83
30
|
end
|
84
31
|
|
85
|
-
def
|
86
|
-
|
87
|
-
|
32
|
+
def transform(value, only_hours = true)
|
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)
|
88
35
|
|
89
|
-
|
90
|
-
def value_in_seconds
|
91
|
-
@value.to_i
|
36
|
+
value.to_f
|
92
37
|
end
|
93
38
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
end
|
39
|
+
def from_string(value)
|
40
|
+
str = value.to_s.split(':')
|
41
|
+
value = 0
|
98
42
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
end
|
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
|
103
46
|
|
104
|
-
|
105
|
-
@value.to_i / 1.day.to_f
|
47
|
+
str.to_s.include?('-') ? value * -1 : value
|
106
48
|
end
|
107
49
|
|
108
|
-
def
|
109
|
-
|
50
|
+
def from_time(value, only_hours = true)
|
51
|
+
(only_hours ? value - value.beginning_of_day : value).to_f
|
110
52
|
end
|
111
53
|
|
112
|
-
#
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
54
|
+
# Format the duration to para HH:MM:SS .
|
55
|
+
# === Sample:
|
56
|
+
## >> duration = Tempus.new(30.hours + 5.minutes + 3.seconds)
|
57
|
+
## => #<Tempus:0xb6e4b860 @data=108303.0>
|
58
|
+
## >> duration.to_s
|
59
|
+
## => "30:05:03"
|
60
|
+
## >> duration = Tempus.new(-30.hours - 5.minutes - 3.seconds)
|
61
|
+
## => #<Tempus:0xb6e4b860 @data=-108303.0>
|
62
|
+
## >> duration.to_s
|
63
|
+
## => "-30:05:03"
|
64
|
+
## >> duration.to_s("%H:%M")
|
65
|
+
## => "-30:05"
|
66
|
+
## >> duration.to_s("%H*%M*%S")
|
67
|
+
## => "-30*05*03"
|
68
|
+
def to_s(string = '%H:%M:%S')
|
69
|
+
text = string.dup
|
124
70
|
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
self
|
131
|
-
elsif(v.class == String)
|
132
|
-
Tempus.new(@value - v.to_tempus.value_in_seconds)
|
133
|
-
else
|
134
|
-
Tempus.new(@value - v)
|
135
|
-
end
|
71
|
+
text['%'] = '-%' if text != '' && negative?
|
72
|
+
|
73
|
+
text = text.gsub(HOURS_REGEX, format_number_abs(hours))
|
74
|
+
text = text.gsub(MINUTES_REGEX, format_number_abs(minutes))
|
75
|
+
text.gsub(SECONDS_REGEX, format_number_abs(seconds))
|
136
76
|
end
|
137
77
|
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
self
|
143
|
-
elsif(v.class == String)
|
144
|
-
Tempus.new(@value - v.to_tempus.value_in_seconds)
|
145
|
-
else
|
146
|
-
Tempus.new(@value - v)
|
147
|
-
end
|
78
|
+
alias to_string to_s
|
79
|
+
|
80
|
+
def format_number_abs(number)
|
81
|
+
format('%02d', number.to_i.abs)
|
148
82
|
end
|
149
83
|
|
150
|
-
def
|
151
|
-
|
84
|
+
def seconds
|
85
|
+
((data.to_f - hours.hour - minutes.minute) / 1.second).to_i
|
152
86
|
end
|
153
87
|
|
154
|
-
def
|
155
|
-
|
88
|
+
def minutes
|
89
|
+
((data.to_f - hours.hour) / 1.minute).to_i
|
156
90
|
end
|
157
91
|
|
158
|
-
def
|
159
|
-
|
92
|
+
def hours
|
93
|
+
(data.to_f / 1.hour).to_i
|
160
94
|
end
|
161
95
|
|
162
|
-
|
163
|
-
|
96
|
+
alias value_in_seconds to_i
|
97
|
+
|
98
|
+
# Convert value to hours.
|
99
|
+
def value_in_hours
|
100
|
+
to_i / 1.hour.to_f
|
164
101
|
end
|
165
102
|
|
166
|
-
|
167
|
-
|
103
|
+
# Convert value to minutes.
|
104
|
+
def value_in_minutes
|
105
|
+
to_i / 1.minute.to_f
|
168
106
|
end
|
169
107
|
|
170
|
-
def
|
171
|
-
|
172
|
-
value == object.value
|
173
|
-
else
|
174
|
-
false
|
175
|
-
end
|
108
|
+
def value_in_days
|
109
|
+
to_i / 1.day.to_f
|
176
110
|
end
|
177
|
-
end
|
178
111
|
|
112
|
+
alias to_xls_time value_in_days
|
179
113
|
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
Tempus.new(self)
|
114
|
+
# Sum values of instance
|
115
|
+
def +(other)
|
116
|
+
Tempus.new(data + transform(other))
|
184
117
|
end
|
185
|
-
end
|
186
118
|
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
Tempus.new(self)
|
119
|
+
# Subtract values of instance
|
120
|
+
def -(other)
|
121
|
+
Tempus.new(data - transform(other))
|
191
122
|
end
|
192
|
-
end
|
193
123
|
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
124
|
+
def human
|
125
|
+
[
|
126
|
+
('menos' if negative?),
|
127
|
+
"#{hours.abs} horas",
|
128
|
+
"#{minutes.abs} minutos",
|
129
|
+
'e',
|
130
|
+
"#{seconds.abs} segundos"
|
131
|
+
].compact.join(' ')
|
198
132
|
end
|
199
|
-
end
|
200
133
|
|
201
|
-
|
202
|
-
|
203
|
-
def to_tempus
|
204
|
-
Tempus.new(self)
|
134
|
+
def inspect
|
135
|
+
"<Tempus seconds=#{data}, formated=#{self}>"
|
205
136
|
end
|
206
|
-
end
|
207
137
|
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
value = 0
|
213
|
-
[:hours, :minutes, :seconds].each_with_index do |m, i|
|
214
|
-
value += str.at(i).to_i.abs.send(m.to_s)
|
215
|
-
end
|
216
|
-
value = -value if str.to_s.include?('-')
|
217
|
-
Tempus.new(value)
|
138
|
+
def ==(other)
|
139
|
+
return false unless other.is_a?(Tempus)
|
140
|
+
|
141
|
+
data == other.data
|
218
142
|
end
|
219
143
|
end
|
data/tempus.gemspec
CHANGED
@@ -1,71 +1,38 @@
|
|
1
|
-
#
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
-
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: tempus 0.2.0 ruby lib
|
1
|
+
# frozen_string_literal: true
|
6
2
|
|
7
|
-
|
8
|
-
|
9
|
-
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'tempus/version'
|
10
6
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
s.email = "daniloj.dasilva@gmail.com"
|
17
|
-
s.extra_rdoc_files = [
|
18
|
-
"LICENSE.txt",
|
19
|
-
"README.rdoc"
|
20
|
-
]
|
21
|
-
s.files = [
|
22
|
-
".document",
|
23
|
-
".rspec",
|
24
|
-
".travis.yml",
|
25
|
-
"Gemfile",
|
26
|
-
"Gemfile.lock",
|
27
|
-
"LICENSE.txt",
|
28
|
-
"README.rdoc",
|
29
|
-
"Rakefile",
|
30
|
-
"VERSION",
|
31
|
-
"lib/tempus.rb",
|
32
|
-
"spec/spec_helper.rb",
|
33
|
-
"spec/tempus_spec.rb",
|
34
|
-
"tempus.gemspec"
|
35
|
-
]
|
36
|
-
s.homepage = "http://github.com/dannnylo/tempus"
|
37
|
-
s.licenses = ["MIT"]
|
38
|
-
s.rubygems_version = "2.2.1"
|
39
|
-
s.summary = "Gem to manipulate efficiently time"
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'tempus'
|
9
|
+
spec.version = Tempus::VERSION
|
10
|
+
spec.authors = ['Danilo Jeremias da Silva']
|
11
|
+
spec.email = ['daniloj.dasilva@gmail.com']
|
40
12
|
|
41
|
-
|
42
|
-
|
13
|
+
spec.summary = 'Gem to efficiently manipulate the time.'
|
14
|
+
spec.description = <<-DESCRIPTION
|
15
|
+
Gem to efficiently manipulate the time.
|
16
|
+
Adding, subtracting and converting more than 24 hours easy.'
|
17
|
+
DESCRIPTION
|
43
18
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
s.add_dependency(%q<activesupport>, [">= 2.3.5"])
|
54
|
-
s.add_dependency(%q<i18n>, [">= 0"])
|
55
|
-
s.add_dependency(%q<rspec>, ["~> 2.8.0"])
|
56
|
-
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
57
|
-
s.add_dependency(%q<bundler>, ["~> 1.0"])
|
58
|
-
s.add_dependency(%q<jeweler>, ["~> 2.0.0"])
|
59
|
-
s.add_dependency(%q<simplecov>, [">= 0"])
|
60
|
-
end
|
61
|
-
else
|
62
|
-
s.add_dependency(%q<activesupport>, [">= 2.3.5"])
|
63
|
-
s.add_dependency(%q<i18n>, [">= 0"])
|
64
|
-
s.add_dependency(%q<rspec>, ["~> 2.8.0"])
|
65
|
-
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
66
|
-
s.add_dependency(%q<bundler>, ["~> 1.0"])
|
67
|
-
s.add_dependency(%q<jeweler>, ["~> 2.0.0"])
|
68
|
-
s.add_dependency(%q<simplecov>, [">= 0"])
|
19
|
+
spec.homepage = 'https://github.com/dannnylo/tempus'
|
20
|
+
spec.license = 'MIT'
|
21
|
+
|
22
|
+
# Specify which files should be added to the gem when it is released.
|
23
|
+
# The `git ls-files -z` loads the files in the RubyGem
|
24
|
+
# that have been added into git.
|
25
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
26
|
+
files = `git ls-files -z`.split("\x0")
|
27
|
+
files.reject { |f| f.match(%r{^(test|spec|features)/}) }
|
69
28
|
end
|
29
|
+
spec.bindir = 'exe'
|
30
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
31
|
+
spec.require_paths = ['lib', 'lib/tempus']
|
32
|
+
spec.add_runtime_dependency 'activesupport', '> 5'
|
33
|
+
spec.add_development_dependency 'bundler', '~> 1.17'
|
34
|
+
spec.add_development_dependency 'coveralls', '~> 0.8'
|
35
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
36
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
37
|
+
spec.add_development_dependency 'simplecov', '~> 0.1'
|
70
38
|
end
|
71
|
-
|
metadata
CHANGED
@@ -1,136 +1,127 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tempus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Danilo Jeremias da Silva
|
8
8
|
autorequire:
|
9
|
-
bindir:
|
9
|
+
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-08-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: '5'
|
20
20
|
type: :runtime
|
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: '5'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ">="
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: rspec
|
28
|
+
name: bundler
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
44
30
|
requirements:
|
45
31
|
- - "~>"
|
46
32
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
33
|
+
version: '1.17'
|
48
34
|
type: :development
|
49
35
|
prerelease: false
|
50
36
|
version_requirements: !ruby/object:Gem::Requirement
|
51
37
|
requirements:
|
52
38
|
- - "~>"
|
53
39
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
40
|
+
version: '1.17'
|
55
41
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
42
|
+
name: coveralls
|
57
43
|
requirement: !ruby/object:Gem::Requirement
|
58
44
|
requirements:
|
59
45
|
- - "~>"
|
60
46
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
47
|
+
version: '0.8'
|
62
48
|
type: :development
|
63
49
|
prerelease: false
|
64
50
|
version_requirements: !ruby/object:Gem::Requirement
|
65
51
|
requirements:
|
66
52
|
- - "~>"
|
67
53
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
54
|
+
version: '0.8'
|
69
55
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
56
|
+
name: rake
|
71
57
|
requirement: !ruby/object:Gem::Requirement
|
72
58
|
requirements:
|
73
59
|
- - "~>"
|
74
60
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
61
|
+
version: '10.0'
|
76
62
|
type: :development
|
77
63
|
prerelease: false
|
78
64
|
version_requirements: !ruby/object:Gem::Requirement
|
79
65
|
requirements:
|
80
66
|
- - "~>"
|
81
67
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
68
|
+
version: '10.0'
|
83
69
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
70
|
+
name: rspec
|
85
71
|
requirement: !ruby/object:Gem::Requirement
|
86
72
|
requirements:
|
87
73
|
- - "~>"
|
88
74
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
75
|
+
version: '3.0'
|
90
76
|
type: :development
|
91
77
|
prerelease: false
|
92
78
|
version_requirements: !ruby/object:Gem::Requirement
|
93
79
|
requirements:
|
94
80
|
- - "~>"
|
95
81
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
82
|
+
version: '3.0'
|
97
83
|
- !ruby/object:Gem::Dependency
|
98
84
|
name: simplecov
|
99
85
|
requirement: !ruby/object:Gem::Requirement
|
100
86
|
requirements:
|
101
|
-
- - "
|
87
|
+
- - "~>"
|
102
88
|
- !ruby/object:Gem::Version
|
103
|
-
version: '0'
|
89
|
+
version: '0.1'
|
104
90
|
type: :development
|
105
91
|
prerelease: false
|
106
92
|
version_requirements: !ruby/object:Gem::Requirement
|
107
93
|
requirements:
|
108
|
-
- - "
|
94
|
+
- - "~>"
|
109
95
|
- !ruby/object:Gem::Version
|
110
|
-
version: '0'
|
111
|
-
description:
|
112
|
-
|
113
|
-
|
96
|
+
version: '0.1'
|
97
|
+
description: |2
|
98
|
+
Gem to efficiently manipulate the time.
|
99
|
+
Adding, subtracting and converting more than 24 hours easy.'
|
100
|
+
email:
|
101
|
+
- daniloj.dasilva@gmail.com
|
114
102
|
executables: []
|
115
103
|
extensions: []
|
116
|
-
extra_rdoc_files:
|
117
|
-
- LICENSE.txt
|
118
|
-
- README.rdoc
|
104
|
+
extra_rdoc_files: []
|
119
105
|
files:
|
120
|
-
- ".
|
106
|
+
- ".coveralls.yml"
|
107
|
+
- ".gitignore"
|
108
|
+
- ".hound.yml"
|
121
109
|
- ".rspec"
|
110
|
+
- ".rubocop.yml"
|
122
111
|
- ".travis.yml"
|
112
|
+
- CODE_OF_CONDUCT.md
|
123
113
|
- Gemfile
|
124
114
|
- Gemfile.lock
|
125
115
|
- LICENSE.txt
|
126
|
-
- README.
|
116
|
+
- README.md
|
127
117
|
- Rakefile
|
128
|
-
-
|
118
|
+
- bin/console
|
119
|
+
- bin/setup
|
129
120
|
- lib/tempus.rb
|
130
|
-
-
|
131
|
-
-
|
121
|
+
- lib/tempus/tempus_helper.rb
|
122
|
+
- lib/tempus/version.rb
|
132
123
|
- tempus.gemspec
|
133
|
-
homepage:
|
124
|
+
homepage: https://github.com/dannnylo/tempus
|
134
125
|
licenses:
|
135
126
|
- MIT
|
136
127
|
metadata: {}
|
@@ -138,6 +129,7 @@ post_install_message:
|
|
138
129
|
rdoc_options: []
|
139
130
|
require_paths:
|
140
131
|
- lib
|
132
|
+
- lib/tempus
|
141
133
|
required_ruby_version: !ruby/object:Gem::Requirement
|
142
134
|
requirements:
|
143
135
|
- - ">="
|
@@ -149,9 +141,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
149
141
|
- !ruby/object:Gem::Version
|
150
142
|
version: '0'
|
151
143
|
requirements: []
|
152
|
-
|
153
|
-
rubygems_version: 2.2.1
|
144
|
+
rubygems_version: 3.0.4
|
154
145
|
signing_key:
|
155
146
|
specification_version: 4
|
156
|
-
summary: Gem to manipulate
|
147
|
+
summary: Gem to efficiently manipulate the time.
|
157
148
|
test_files: []
|
data/.document
DELETED
data/README.rdoc
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
= tempus
|
2
|
-
{<img src="https://badge.fury.io/rb/tempus.png" alt="Gem Version" />}[http://badge.fury.io/rb/tempus]
|
3
|
-
Gem to efficiently manipulate the time, adding, subtracting and converting hours.
|
4
|
-
|
5
|
-
== EXAMPLE USAGE
|
6
|
-
|
7
|
-
hours = Tempus.new(30.hours + 5.minutes + 3.seconds)
|
8
|
-
=> <Tempus:8508680 seconds=108303.0, formated=30:05:03>
|
9
|
-
hours.value_in_minutes
|
10
|
-
=> 1805.05
|
11
|
-
hours.to_s("%H hours and %M minutes")
|
12
|
-
=> "30 hours and 05 minutes"
|
13
|
-
|
14
|
-
hours = "35:05:01".to_tempus
|
15
|
-
=> <Tempus:7228060 seconds=126301.0, formated=35:05:01>
|
16
|
-
hours + 6.hours
|
17
|
-
=> <Tempus:6931320 seconds=147901.0, formated=41:05:01>
|
18
|
-
|
19
|
-
"1:00:00".to_tempus + "2:00"
|
20
|
-
=> <Tempus:6634700 seconds=10800.0, formated=03:00:00>
|
21
|
-
|
22
|
-
Tempus.new Time.now
|
23
|
-
=> <Tempus:6578680 seconds=46455.162950918, formated=12:54:15>
|
24
|
-
|
25
|
-
== Contributing to tempus
|
26
|
-
|
27
|
-
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
28
|
-
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
29
|
-
* Fork the project.
|
30
|
-
* Start a feature/bugfix branch.
|
31
|
-
* Commit and push until you are happy with your contribution.
|
32
|
-
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
33
|
-
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
34
|
-
|
35
|
-
== Copyright
|
36
|
-
|
37
|
-
Copyright (c) 2012 Danilo Jeremias da Silva. See LICENSE.txt for
|
38
|
-
further details.
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.2.0
|
data/spec/spec_helper.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
4
|
-
require 'rspec'
|
5
|
-
require "simplecov"
|
6
|
-
SimpleCov.start do
|
7
|
-
add_filter "/spec/"
|
8
|
-
end
|
9
|
-
require 'tempus'
|
10
|
-
# Requires supporting files with custom matchers and macros, etc,
|
11
|
-
# in ./support/ and its subdirectories.
|
12
|
-
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
13
|
-
|
14
|
-
RSpec.configure do |config|
|
15
|
-
|
16
|
-
end
|
data/spec/tempus_spec.rb
DELETED
@@ -1,113 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
3
|
-
|
4
|
-
describe "Tempus" do
|
5
|
-
before do
|
6
|
-
@hours = Tempus.new(30.hours + 5.minutes + 3.seconds)
|
7
|
-
@negative_hours = Tempus.new(-30.hours - 5.minutes - 3.seconds)
|
8
|
-
end
|
9
|
-
|
10
|
-
it "validates the object creation" do
|
11
|
-
@hours.should_not == nil
|
12
|
-
@negative_hours.should_not == nil
|
13
|
-
end
|
14
|
-
|
15
|
-
it "set value" do
|
16
|
-
hours = @hours.clone
|
17
|
-
hours.object_id.should_not == @hours.object_id
|
18
|
-
hours.set(125).should == 125.0
|
19
|
-
hours.to_s.should == "00:02:05"
|
20
|
-
hours.value_in_seconds.should == 125
|
21
|
-
hours.set(Time.now.midnight).should == 0.0
|
22
|
-
hours.value_in_seconds.should == 0
|
23
|
-
hours.to_s.should == "00:00:00"
|
24
|
-
hours.set(Time.now.midnight,true).should == Time.now.midnight.to_i
|
25
|
-
hours.to_s("%M:%S").should == "00:00"
|
26
|
-
end
|
27
|
-
|
28
|
-
it "test output" do
|
29
|
-
@hours.respond_to?("to_s").should == true
|
30
|
-
@hours.to_s("").should == ""
|
31
|
-
@hours.to_s().should == "30:05:03"
|
32
|
-
@hours.to_s("%H").should == "30"
|
33
|
-
@hours.to_s("%M").should == "05"
|
34
|
-
@hours.to_s("%S").should == "03"
|
35
|
-
@hours.to_s("%Mdakhdkj$#").should == "05dakhdkj$#"
|
36
|
-
@hours.to_s("hours Utilizadas: %H:%M").should == "hours Utilizadas: 30:05"
|
37
|
-
@hours.to_s("%H:%M:%S").should == "30:05:03"
|
38
|
-
@negative_hours.to_s("").should == ""
|
39
|
-
@negative_hours.to_s().should == "-30:05:03"
|
40
|
-
@negative_hours.to_s("%H").should == "-30"
|
41
|
-
@negative_hours.to_s("%M").should == "-05"
|
42
|
-
@negative_hours.to_s("%S").should == "-03"
|
43
|
-
@negative_hours.to_s("%Mdakhdkj$#").should == "-05dakhdkj$#"
|
44
|
-
#Por enquanto existe este bug
|
45
|
-
@negative_hours.to_s("hours Utilizadas: %H:%M").should == "-hours Utilizadas: 30:05" #FIXME: Corrigir este problema.
|
46
|
-
@negative_hours.to_s("%H:%M:%S").should == "-30:05:03"
|
47
|
-
|
48
|
-
@hours.human.should == "30 horas 5 minutos e 3 segundos"
|
49
|
-
@negative_hours.human.should == "menos 30 horas 5 minutos e 3 segundos"
|
50
|
-
|
51
|
-
@hours.positive?.should == true
|
52
|
-
@hours.negative?.should == false
|
53
|
-
|
54
|
-
@negative_hours.positive?.should == false
|
55
|
-
@negative_hours.negative?.should == true
|
56
|
-
|
57
|
-
end
|
58
|
-
|
59
|
-
it "plus" do
|
60
|
-
(@hours + "00:01:00").to_s.should == "30:06:03"
|
61
|
-
(@hours + 1).to_s.should == "30:05:04"
|
62
|
-
(@hours + 1.minutes).to_s.should == "30:06:03"
|
63
|
-
(@hours + 1.hours).to_s.should == "31:05:03"
|
64
|
-
(@hours + 5.hours).to_s.should == "35:05:03"
|
65
|
-
(@hours + nil).to_s.should == "30:05:03"
|
66
|
-
(@hours + @negative_hours).to_s.should == "00:00:00"
|
67
|
-
end
|
68
|
-
|
69
|
-
it "minus" do
|
70
|
-
(@hours - "00:01:00").to_s.should == "30:04:03"
|
71
|
-
(@hours - 1).to_s.should == "30:05:02"
|
72
|
-
(@hours - 1.minutes).to_s.should == "30:04:03"
|
73
|
-
(@hours - 1.hours).to_s.should == "29:05:03"
|
74
|
-
(@hours - 5.hours).to_s.should == "25:05:03"
|
75
|
-
(@hours - nil).to_s.should == "30:05:03"
|
76
|
-
(@hours - @negative_hours ).to_s.should == "60:10:06"
|
77
|
-
end
|
78
|
-
|
79
|
-
it "validates the value in methods" do
|
80
|
-
1.day.to_tempus.value_in_days.should == 1
|
81
|
-
1.day.to_tempus.to_xls_time.should == 1
|
82
|
-
2.hours.to_tempus.value_in_hours.should == 2
|
83
|
-
30.minutes.to_tempus.value_in_hours.should == 0.5
|
84
|
-
30.minutes.to_tempus.value_in_minutes.should == 30
|
85
|
-
end
|
86
|
-
|
87
|
-
|
88
|
-
describe "Other Class" do
|
89
|
-
it "String to Tempus" do
|
90
|
-
"12:05:35".to_tempus.value.should == Tempus.new(12.hours + 5.minutes + 35.seconds).value
|
91
|
-
"01:00:01".to_tempus.value.should == Tempus.new(1.hours + 1.seconds).value
|
92
|
-
"30:5:3".to_tempus.should == @hours
|
93
|
-
"-30:5:3".to_tempus.should == @negative_hours
|
94
|
-
end
|
95
|
-
|
96
|
-
it "Fixnum to Tempus" do
|
97
|
-
3723.to_tempus.to_s.should == "01:02:03"
|
98
|
-
3723.to_tempus.inspect.should == "<Tempus seconds=3723.0, formated=01:02:03>"
|
99
|
-
end
|
100
|
-
|
101
|
-
it "Float to Tempus" do
|
102
|
-
3723.0.to_tempus.to_string.should == "01:02:03"
|
103
|
-
end
|
104
|
-
|
105
|
-
it "Time to Tempus" do
|
106
|
-
Time.parse("2014-01-01 01:02:03").to_tempus.to_i.should == 3723
|
107
|
-
end
|
108
|
-
|
109
|
-
it "nil to Tempus" do
|
110
|
-
nil.to_tempus.value.should == 0
|
111
|
-
end
|
112
|
-
end
|
113
|
-
end
|