time_interval 0.1.0 → 0.1.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.
- data/VERSION +1 -1
- data/lib/time_interval.rb +12 -2
- data/test/test_time_interval.rb +7 -0
- data/time_interval.gemspec +49 -0
- metadata +4 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
data/lib/time_interval.rb
CHANGED
@@ -87,16 +87,26 @@ class TimeInterval
|
|
87
87
|
def self.scale_name
|
88
88
|
DEFAULT_SCALE_NAME
|
89
89
|
end
|
90
|
+
|
91
|
+
def self.size(at_scale = nil)
|
92
|
+
scale_details = scale[at_scale || scale_name[0]]
|
93
|
+
|
94
|
+
scale_details and scale_details[1]
|
95
|
+
end
|
96
|
+
|
97
|
+
def self.now
|
98
|
+
new(nil)
|
99
|
+
end
|
90
100
|
|
91
101
|
# == Instance Methods =====================================================
|
92
102
|
|
93
103
|
def initialize(value = nil)
|
94
|
-
@time = self.class.interval_to_i(value || Time.now)
|
104
|
+
@time = self.class.interval_to_i(value || Time.now.utc)
|
95
105
|
end
|
96
106
|
|
97
107
|
def to_i(at_scale = nil)
|
98
108
|
case (at_scale)
|
99
|
-
when nil
|
109
|
+
when nil
|
100
110
|
@time
|
101
111
|
else
|
102
112
|
scale_details = self.class.scale[at_scale]
|
data/test/test_time_interval.rb
CHANGED
@@ -20,6 +20,13 @@ class TestTimeInterval < Test::Unit::TestCase
|
|
20
20
|
)
|
21
21
|
|
22
22
|
assert_equal 5, interval_type.scale.length
|
23
|
+
|
24
|
+
assert_equal 1, interval_type.size
|
25
|
+
assert_equal 1, interval_type.size(:second)
|
26
|
+
assert_equal 60, interval_type.size(:minute)
|
27
|
+
assert_equal 60 * 60, interval_type.size(:hour)
|
28
|
+
assert_equal 24 * 60 * 60, interval_type.size(:day)
|
29
|
+
assert_equal 7 * 24 * 60 * 60, interval_type.size(:week)
|
23
30
|
|
24
31
|
# Construct a series of expectations by multiplying out into the
|
25
32
|
# required numbre of seconds.
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{time_interval}
|
8
|
+
s.version = "0.1.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["tadman"]
|
12
|
+
s.date = %q{2010-08-26}
|
13
|
+
s.description = %q{Useful for dividing up linear time into nested intervals}
|
14
|
+
s.email = %q{github@tadman.ca}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"README.rdoc"
|
17
|
+
]
|
18
|
+
s.files = [
|
19
|
+
".document",
|
20
|
+
".gitignore",
|
21
|
+
"README.rdoc",
|
22
|
+
"Rakefile",
|
23
|
+
"VERSION",
|
24
|
+
"lib/time_interval.rb",
|
25
|
+
"test/helper.rb",
|
26
|
+
"test/test_time_interval.rb",
|
27
|
+
"time_interval.gemspec"
|
28
|
+
]
|
29
|
+
s.homepage = %q{http://github.com/tadman/time_interval}
|
30
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
31
|
+
s.require_paths = ["lib"]
|
32
|
+
s.rubygems_version = %q{1.3.7}
|
33
|
+
s.summary = %q{Calculates time interval subsets}
|
34
|
+
s.test_files = [
|
35
|
+
"test/helper.rb",
|
36
|
+
"test/test_time_interval.rb"
|
37
|
+
]
|
38
|
+
|
39
|
+
if s.respond_to? :specification_version then
|
40
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
41
|
+
s.specification_version = 3
|
42
|
+
|
43
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
44
|
+
else
|
45
|
+
end
|
46
|
+
else
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 1
|
9
|
+
version: 0.1.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- tadman
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-08-
|
17
|
+
date: 2010-08-26 00:00:00 -04:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|
@@ -35,6 +35,7 @@ files:
|
|
35
35
|
- lib/time_interval.rb
|
36
36
|
- test/helper.rb
|
37
37
|
- test/test_time_interval.rb
|
38
|
+
- time_interval.gemspec
|
38
39
|
has_rdoc: true
|
39
40
|
homepage: http://github.com/tadman/time_interval
|
40
41
|
licenses: []
|