seconds 0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/GPLv2-LICENSE +18 -0
- data/README +28 -0
- data/lib/seconds.rb +136 -0
- metadata +58 -0
data/GPLv2-LICENSE
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
Seconds is a utility for Numeric Time conversion.
|
2
|
+
Copyright (C) 2012 Ethan Stryker
|
3
|
+
|
4
|
+
This program is free software; you can redistribute it and/or
|
5
|
+
modify it under the terms of the GNU General Public License
|
6
|
+
as published by the Free Software Foundation; either version 2
|
7
|
+
of the License, or (at your option) any later version.
|
8
|
+
|
9
|
+
This program is distributed in the hope that it will be useful,
|
10
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
GNU General Public License for more details.
|
13
|
+
|
14
|
+
You should have received a copy of the GNU General Public License
|
15
|
+
along with this program; if not, write to the Free Software
|
16
|
+
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
17
|
+
|
18
|
+
Questions/Comments on OptSimple can be mailed to Ethan Stryker, e.stryker@gmail.com
|
data/README
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
== Seconds adds active_support/core_ext/numeric like methods to the Numeric class
|
2
|
+
|
3
|
+
== Documentation
|
4
|
+
Read the rdocs for the Numeric class in seconds.rb
|
5
|
+
|
6
|
+
== Installation
|
7
|
+
|
8
|
+
It is recommended to install seconds using RubyGems:
|
9
|
+
|
10
|
+
$ sudo gem install seconds
|
11
|
+
|
12
|
+
== Examples
|
13
|
+
|
14
|
+
1.second
|
15
|
+
=> 1
|
16
|
+
|
17
|
+
1.minute
|
18
|
+
=> 60
|
19
|
+
|
20
|
+
1.hour
|
21
|
+
=> 3600
|
22
|
+
|
23
|
+
1.hour.ago # (where Time.now is 2012-03-23 03:34:52 +0100)
|
24
|
+
=> 2012-03-23 02:34:52 +0100
|
25
|
+
|
26
|
+
|
27
|
+
2.days.from_now
|
28
|
+
=> 2012-03-25 03:34:52 +0100
|
data/lib/seconds.rb
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
=begin rdoc
|
2
|
+
Adds active_support/core_ext/numeric like methods to the Numeric class
|
3
|
+
|
4
|
+
e.g. 15.minutes returns 15 * 60
|
5
|
+
e.g. 15.minutes.ago returns a Time object whose value is 15 minutes less than Time.now
|
6
|
+
=end
|
7
|
+
class Numeric
|
8
|
+
|
9
|
+
=begin rdoc
|
10
|
+
Returns the number of seconds in +self+ seconds. Intended to be used with the +ago+ method.
|
11
|
+
|
12
|
+
---
|
13
|
+
1.second
|
14
|
+
=> 1
|
15
|
+
---
|
16
|
+
=end
|
17
|
+
def second
|
18
|
+
self
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
=begin rdoc
|
23
|
+
Returns the number of seconds in +self+ minutes. Intended to be used with the +ago+ method.
|
24
|
+
|
25
|
+
---
|
26
|
+
1.minute
|
27
|
+
=> 60
|
28
|
+
---
|
29
|
+
=end
|
30
|
+
def minute
|
31
|
+
60*second
|
32
|
+
end
|
33
|
+
|
34
|
+
=begin rdoc
|
35
|
+
Returns the number of seconds in +self+ hours. Intended to be used with the +ago+ method.
|
36
|
+
|
37
|
+
---
|
38
|
+
1.hour
|
39
|
+
=> 3600
|
40
|
+
---
|
41
|
+
=end
|
42
|
+
def hour
|
43
|
+
60*minute
|
44
|
+
end
|
45
|
+
|
46
|
+
=begin rdoc
|
47
|
+
Returns the number of seconds in +self+ days. Intended to be used with the +ago+ method.
|
48
|
+
|
49
|
+
---
|
50
|
+
1.day
|
51
|
+
=> 86400
|
52
|
+
---
|
53
|
+
=end
|
54
|
+
def day
|
55
|
+
24*hour
|
56
|
+
end
|
57
|
+
|
58
|
+
=begin rdoc
|
59
|
+
Returns the number of seconds in +self+ weeks. Intended to be used with the +ago+ method.
|
60
|
+
|
61
|
+
---
|
62
|
+
1.week
|
63
|
+
=> 604800
|
64
|
+
---
|
65
|
+
=end
|
66
|
+
def week
|
67
|
+
7*day
|
68
|
+
end
|
69
|
+
|
70
|
+
=begin rdoc
|
71
|
+
Returns the number of seconds in +self+ months. Assumes a month is 28 days. Intended to be used with the +ago+ method.
|
72
|
+
|
73
|
+
---
|
74
|
+
1.month
|
75
|
+
=> 2419200
|
76
|
+
---
|
77
|
+
=end
|
78
|
+
def month
|
79
|
+
4*week
|
80
|
+
end
|
81
|
+
|
82
|
+
=begin rdoc
|
83
|
+
Returns a Time object +self+ seconds before Time.now.
|
84
|
+
|
85
|
+
---
|
86
|
+
1.day.ago
|
87
|
+
---
|
88
|
+
=end
|
89
|
+
|
90
|
+
def ago
|
91
|
+
Time.now - self
|
92
|
+
end
|
93
|
+
|
94
|
+
=begin rdoc
|
95
|
+
Returns a Time object +self+ seconds before the given time.
|
96
|
+
|
97
|
+
---
|
98
|
+
1.hour.until(some_time)
|
99
|
+
---
|
100
|
+
=end
|
101
|
+
def until time
|
102
|
+
time - self
|
103
|
+
end
|
104
|
+
|
105
|
+
=begin rdoc
|
106
|
+
Returns a Time object +self+ seconds after the given time.
|
107
|
+
|
108
|
+
---
|
109
|
+
1.hour.from(some_time)
|
110
|
+
---
|
111
|
+
|
112
|
+
=end
|
113
|
+
|
114
|
+
def from time
|
115
|
+
time + self
|
116
|
+
end
|
117
|
+
|
118
|
+
=begin rdoc
|
119
|
+
Returns a Time object +self+ seconds from now.
|
120
|
+
|
121
|
+
---
|
122
|
+
in_an_hour = 1.hour.from_now
|
123
|
+
---
|
124
|
+
=end
|
125
|
+
def from_now
|
126
|
+
self.from Time.now
|
127
|
+
end
|
128
|
+
|
129
|
+
#some pluralization aliases
|
130
|
+
alias :seconds :second
|
131
|
+
alias :minutes :minute
|
132
|
+
alias :hours :hour
|
133
|
+
alias :days :day
|
134
|
+
alias :weeks :week
|
135
|
+
alias :minutes :minute
|
136
|
+
end
|
metadata
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: seconds
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: "0.2"
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Ethan Stryker
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2012-03-23 00:00:00 +00:00
|
14
|
+
default_executable:
|
15
|
+
dependencies: []
|
16
|
+
|
17
|
+
description: " An extension of the Numeric class that provides Time object unit conversion similar to ActiveSupport's numeric extension.\n"
|
18
|
+
email: e.stryker@gmail.com
|
19
|
+
executables: []
|
20
|
+
|
21
|
+
extensions: []
|
22
|
+
|
23
|
+
extra_rdoc_files: []
|
24
|
+
|
25
|
+
files:
|
26
|
+
- lib/seconds.rb
|
27
|
+
- README
|
28
|
+
- GPLv2-LICENSE
|
29
|
+
has_rdoc: true
|
30
|
+
homepage: http://seconds.rubyforge.org/
|
31
|
+
licenses: []
|
32
|
+
|
33
|
+
post_install_message:
|
34
|
+
rdoc_options: []
|
35
|
+
|
36
|
+
require_paths:
|
37
|
+
- lib
|
38
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: "0"
|
44
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
45
|
+
none: false
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: "0"
|
50
|
+
requirements: []
|
51
|
+
|
52
|
+
rubyforge_project: seconds
|
53
|
+
rubygems_version: 1.6.2
|
54
|
+
signing_key:
|
55
|
+
specification_version: 3
|
56
|
+
summary: An extension of the Numeric class that provides Time object unit conversion
|
57
|
+
test_files: []
|
58
|
+
|