time_sugar 0.0.1
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 +7 -0
- data/.gitignore +17 -0
- data/.travis.yml +5 -0
- data/Gemfile +2 -0
- data/LICENSE +22 -0
- data/README.md +69 -0
- data/Rakefile +10 -0
- data/lib/time_sugar.rb +24 -0
- data/spec/fixnum_spec.rb +102 -0
- data/spec/minitest_helper.rb +5 -0
- data/spec/time_sugar_spec.rb +32 -0
- data/time_sugar.gemspec +24 -0
- metadata +100 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 53a9add318ffb1fda078a2f14bf47c6d03044d78
|
|
4
|
+
data.tar.gz: a63a5f73b730f991793e732891fe5a55918efee0
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: c8efbc28680f97a4960a01ff8525e05a80c2c2f8524f40c0903351eb146363e2d788e0ddaece2a3f77074651a953bb6fc67f31ab5cf5eae2ead5d01167702231
|
|
7
|
+
data.tar.gz: 368a219ab7b7856faa7884e6215f932c7b70eeb74c442421a14260cb3b5e16ae467080cf451bdafd789dc707aacdf5f08f8892c4db28947c687bbbf5599e3b12
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2014 Patricio Mac Adden
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# TimeSugar
|
|
2
|
+
|
|
3
|
+
Syntactic sugar for handling time. If you are familiar with [Active Support](https://github.com/rails/rails/tree/master/activesupport),
|
|
4
|
+
but you don't want to add the whole library for just handling time,
|
|
5
|
+
`time_sugar` may be helpful.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
Add this line to your application's Gemfile:
|
|
10
|
+
|
|
11
|
+
```ruby
|
|
12
|
+
gem 'time_sugar'
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
And then execute:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
$ bundle
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Or install it yourself as:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
$ gem install time_sugar
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Usage
|
|
28
|
+
|
|
29
|
+
Time sugar add some utility methods to Fixnum, which are useful for doing
|
|
30
|
+
stuff like this:
|
|
31
|
+
|
|
32
|
+
```ruby
|
|
33
|
+
1.second #=> 1
|
|
34
|
+
1.minute #=> 60
|
|
35
|
+
1.hour #=> 3600
|
|
36
|
+
1.day #=> 86400
|
|
37
|
+
1.week #=> 604800
|
|
38
|
+
|
|
39
|
+
Time.now #=> 2014-02-11 23:55:47 -0300
|
|
40
|
+
1.minute.ago #=> 2014-02-11 23:55:46 -0300
|
|
41
|
+
|
|
42
|
+
Time.now #=> 2014-02-11 23:55:47 -0300
|
|
43
|
+
1.minute.ago #=> 2014-02-11 23:54:47 -0300
|
|
44
|
+
|
|
45
|
+
Time.now #=> 2014-02-11 23:55:47 -0300
|
|
46
|
+
1.hour.ago #=> 2014-02-11 22:55:47 -0300
|
|
47
|
+
|
|
48
|
+
Time.now #=> 2014-02-11 23:55:47 -0300
|
|
49
|
+
1.day.ago #=> 2014-02-10 23:55:47 -0300
|
|
50
|
+
|
|
51
|
+
Time.now #=> 2014-02-11 23:55:47 -0300
|
|
52
|
+
1.week.ago #=> 2014-02-04 23:55:47 -0300
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Is it any good?
|
|
56
|
+
|
|
57
|
+
I don't know!
|
|
58
|
+
|
|
59
|
+
## Contributing
|
|
60
|
+
|
|
61
|
+
1. Fork it
|
|
62
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
63
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
64
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
|
65
|
+
5. Create new Pull Request
|
|
66
|
+
|
|
67
|
+
## License
|
|
68
|
+
|
|
69
|
+
See the [LICENSE](https://github.com/patriciomacadden/time_sugar/blob/master/LICENSE).
|
data/Rakefile
ADDED
data/lib/time_sugar.rb
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
module TimeSugar
|
|
2
|
+
VERSION = '0.0.1'
|
|
3
|
+
|
|
4
|
+
SECOND = 1
|
|
5
|
+
MINUTE = SECOND * 60
|
|
6
|
+
HOUR = MINUTE * 60
|
|
7
|
+
DAY = HOUR * 24
|
|
8
|
+
WEEK = DAY * 7
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
class Fixnum
|
|
12
|
+
%w(SECOND MINUTE HOUR DAY WEEK).each do |verb|
|
|
13
|
+
define_method(verb.downcase) { self * TimeSugar.const_get(verb) }
|
|
14
|
+
alias_method "#{verb.downcase}s", verb.downcase
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def ago
|
|
18
|
+
Time.now - self
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def from_now
|
|
22
|
+
Time.now + self
|
|
23
|
+
end
|
|
24
|
+
end
|
data/spec/fixnum_spec.rb
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
require 'minitest_helper'
|
|
2
|
+
|
|
3
|
+
describe Fixnum do
|
|
4
|
+
describe '#second(s)' do
|
|
5
|
+
it 'must return self expressed in seconds' do
|
|
6
|
+
1.second.must_equal 1
|
|
7
|
+
10.seconds.must_equal 10
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
describe '#minute(s)' do
|
|
12
|
+
it 'must return self expressed in minutes' do
|
|
13
|
+
1.minute.must_equal 60.seconds
|
|
14
|
+
10.minutes.must_equal 600.seconds
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
describe '#hour(s)' do
|
|
19
|
+
it 'must return self expressed in hours' do
|
|
20
|
+
1.hour.must_equal 60.minutes
|
|
21
|
+
10.hours.must_equal 600.minutes
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
describe '#day(s)' do
|
|
26
|
+
it 'must return self expressed in days' do
|
|
27
|
+
1.day.must_equal 24.hours
|
|
28
|
+
10.days.must_equal 240.hours
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
describe '#week(s)' do
|
|
33
|
+
it 'must return self expressed in weeks' do
|
|
34
|
+
1.week.must_equal 7.days
|
|
35
|
+
10.weeks.must_equal 70.days
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
describe '#ago' do
|
|
40
|
+
it 'must subtract seconds' do
|
|
41
|
+
Time.stub :now, Time.at(1) do
|
|
42
|
+
1.second.ago.must_equal Time.at 0
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it 'must subtract minutes' do
|
|
47
|
+
Time.stub :now, Time.at(60) do
|
|
48
|
+
1.minute.ago.must_equal Time.at 0
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
it 'must subtract hours' do
|
|
53
|
+
Time.stub :now, Time.at(3600) do
|
|
54
|
+
1.hour.ago.must_equal Time.at 0
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
it 'must subtract days' do
|
|
59
|
+
Time.stub :now, Time.at(86400) do
|
|
60
|
+
1.day.ago.must_equal Time.at 0
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
it 'must subtract weeks' do
|
|
65
|
+
Time.stub :now, Time.at(604800) do
|
|
66
|
+
1.week.ago.must_equal Time.at 0
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
describe '#from_now' do
|
|
72
|
+
it 'must add seconds' do
|
|
73
|
+
Time.stub :now, Time.at(0) do
|
|
74
|
+
1.second.from_now.must_equal Time.at 1
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
it 'must add minutes' do
|
|
79
|
+
Time.stub :now, Time.at(0) do
|
|
80
|
+
1.minute.from_now.must_equal Time.at 60
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
it 'must add hours' do
|
|
85
|
+
Time.stub :now, Time.at(0) do
|
|
86
|
+
1.hour.from_now.must_equal Time.at 3600
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
it 'must add days' do
|
|
91
|
+
Time.stub :now, Time.at(0) do
|
|
92
|
+
1.day.from_now.must_equal Time.at 86400
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
it 'must add weeks' do
|
|
97
|
+
Time.stub :now, Time.at(0) do
|
|
98
|
+
1.week.from_now.must_equal Time.at 604800
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
require 'minitest_helper'
|
|
2
|
+
|
|
3
|
+
describe TimeSugar do
|
|
4
|
+
it 'must define the VERSION constant' do
|
|
5
|
+
TimeSugar::VERSION.wont_be_nil
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
it 'must define the SECOND constant' do
|
|
9
|
+
TimeSugar::SECOND.wont_be_nil
|
|
10
|
+
TimeSugar::SECOND.must_equal 1
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it 'must define the MINUTE constant' do
|
|
14
|
+
TimeSugar::MINUTE.wont_be_nil
|
|
15
|
+
TimeSugar::MINUTE.must_equal 60
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it 'must define the HOUR constant' do
|
|
19
|
+
TimeSugar::HOUR.wont_be_nil
|
|
20
|
+
TimeSugar::HOUR.must_equal 3600
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it 'must define the DAY constant' do
|
|
24
|
+
TimeSugar::DAY.wont_be_nil
|
|
25
|
+
TimeSugar::DAY.must_equal 86400
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it 'must define the WEEK constant' do
|
|
29
|
+
TimeSugar::WEEK.wont_be_nil
|
|
30
|
+
TimeSugar::WEEK.must_equal 604800
|
|
31
|
+
end
|
|
32
|
+
end
|
data/time_sugar.gemspec
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'time_sugar'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = 'time_sugar'
|
|
8
|
+
spec.version = TimeSugar::VERSION
|
|
9
|
+
spec.authors = ['Patricio Mac Adden']
|
|
10
|
+
spec.email = ['patriciomacadden@gmail.com']
|
|
11
|
+
spec.summary = 'Syntactic sugar for handling time.'
|
|
12
|
+
spec.description = 'Syntactic sugar for handling time.'
|
|
13
|
+
spec.homepage = 'https://github.com/patriciomacadden/time_sugar'
|
|
14
|
+
spec.license = 'MIT'
|
|
15
|
+
|
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
19
|
+
spec.require_paths = ['lib']
|
|
20
|
+
|
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.5'
|
|
22
|
+
spec.add_development_dependency 'minitest'
|
|
23
|
+
spec.add_development_dependency 'rake'
|
|
24
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: time_sugar
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Patricio Mac Adden
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2014-02-12 00:00:00.000000000 Z
|
|
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.5'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.5'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: minitest
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - ">="
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '0'
|
|
34
|
+
type: :development
|
|
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: rake
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - ">="
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - ">="
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '0'
|
|
55
|
+
description: Syntactic sugar for handling time.
|
|
56
|
+
email:
|
|
57
|
+
- patriciomacadden@gmail.com
|
|
58
|
+
executables: []
|
|
59
|
+
extensions: []
|
|
60
|
+
extra_rdoc_files: []
|
|
61
|
+
files:
|
|
62
|
+
- ".gitignore"
|
|
63
|
+
- ".travis.yml"
|
|
64
|
+
- Gemfile
|
|
65
|
+
- LICENSE
|
|
66
|
+
- README.md
|
|
67
|
+
- Rakefile
|
|
68
|
+
- lib/time_sugar.rb
|
|
69
|
+
- spec/fixnum_spec.rb
|
|
70
|
+
- spec/minitest_helper.rb
|
|
71
|
+
- spec/time_sugar_spec.rb
|
|
72
|
+
- time_sugar.gemspec
|
|
73
|
+
homepage: https://github.com/patriciomacadden/time_sugar
|
|
74
|
+
licenses:
|
|
75
|
+
- MIT
|
|
76
|
+
metadata: {}
|
|
77
|
+
post_install_message:
|
|
78
|
+
rdoc_options: []
|
|
79
|
+
require_paths:
|
|
80
|
+
- lib
|
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
82
|
+
requirements:
|
|
83
|
+
- - ">="
|
|
84
|
+
- !ruby/object:Gem::Version
|
|
85
|
+
version: '0'
|
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
87
|
+
requirements:
|
|
88
|
+
- - ">="
|
|
89
|
+
- !ruby/object:Gem::Version
|
|
90
|
+
version: '0'
|
|
91
|
+
requirements: []
|
|
92
|
+
rubyforge_project:
|
|
93
|
+
rubygems_version: 2.2.0
|
|
94
|
+
signing_key:
|
|
95
|
+
specification_version: 4
|
|
96
|
+
summary: Syntactic sugar for handling time.
|
|
97
|
+
test_files:
|
|
98
|
+
- spec/fixnum_spec.rb
|
|
99
|
+
- spec/minitest_helper.rb
|
|
100
|
+
- spec/time_sugar_spec.rb
|