dateless_time 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +26 -4
- data/dateless_time.gemspec +2 -2
- data/lib/dateless_time.rb +10 -2
- data/lib/dateless_time/version.rb +1 -1
- data/test/comparable_test.rb +110 -0
- data/test/query_test.rb +17 -0
- metadata +7 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: beb998e71c803edaa9cc5f5a43de996a3807d73b
|
4
|
+
data.tar.gz: c3518170af494b7996b1a92b46bb2503048855e0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a07b4e6b283c8a966e9783a9bbdab7bc66ad5bbbb15132dbb1d0c4bad3977bbaa4e8c4daf495d20e83c936b85fb3cf26f7993122e140609443689c0f6e781121
|
7
|
+
data.tar.gz: 9c4e6aa1b15cbf44b3e9ba6aa18dd15270b861a3ec0140cf2bff4affd3f73eb88cc9137e06fcf7e08b520e9022f854140ec68a086d7e22c3668b50ca09665059
|
data/README.md
CHANGED
@@ -84,7 +84,7 @@ time.to_time
|
|
84
84
|
# => 2014-04-01 13:37:42 +0100
|
85
85
|
|
86
86
|
# but you can supply a base time object instead
|
87
|
-
|
87
|
+
time.to_time(Time.new(1985, 10, 25, 0, 0, 0, "-08:00"))
|
88
88
|
# => 1985-10-25 13:37:42 -0800
|
89
89
|
|
90
90
|
time.to_time.class
|
@@ -104,6 +104,29 @@ time.to_a
|
|
104
104
|
|
105
105
|
```
|
106
106
|
|
107
|
+
Comparisons:
|
108
|
+
|
109
|
+
```ruby
|
110
|
+
|
111
|
+
@time_1 = DatelessTime.new "11:22"
|
112
|
+
@time_1 = DatelessTime.new "11:30"
|
113
|
+
|
114
|
+
# all the usual suspects
|
115
|
+
|
116
|
+
@time_1 < @time_2
|
117
|
+
# => true
|
118
|
+
|
119
|
+
# all the usual suspects
|
120
|
+
@time_1 == @time_2
|
121
|
+
# => false
|
122
|
+
|
123
|
+
@time_2.between? @time_1, DatelessTime.new("20:30")
|
124
|
+
# => true
|
125
|
+
|
126
|
+
#etc...
|
127
|
+
|
128
|
+
```
|
129
|
+
|
107
130
|
## Installation
|
108
131
|
|
109
132
|
Add this line to your application's Gemfile:
|
@@ -143,9 +166,8 @@ end
|
|
143
166
|
## To Do
|
144
167
|
|
145
168
|
|
146
|
-
1.
|
147
|
-
2.
|
148
|
-
3. nice to have: other methods from `Time`'s public interface
|
169
|
+
1. implement the `+` and `-` artimetic operators, in a way consistent with Ruby's `Time`
|
170
|
+
2. nice to have: other methods from `Time`'s public interface
|
149
171
|
|
150
172
|
|
151
173
|
|
data/dateless_time.gemspec
CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.name = "dateless_time"
|
9
9
|
spec.version = DatelessTime::VERSION
|
10
10
|
spec.author = "Tommaso Pavese"
|
11
|
-
spec.description = %q{A class to handle dateless time values.}
|
12
|
-
spec.summary = %q{A class to handle dateless time values.
|
11
|
+
spec.description = %q{A class to handle dateless time values. DatelessTime objects are a lightweight alternative to Ruby's default Time class, and don't care about timezones and DST.}
|
12
|
+
spec.summary = %q{A class to handle dateless time values.}
|
13
13
|
spec.homepage = "https://github.com/tompave/dateless_time"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
data/lib/dateless_time.rb
CHANGED
@@ -2,6 +2,8 @@ require "dateless_time/version"
|
|
2
2
|
|
3
3
|
class DatelessTime
|
4
4
|
|
5
|
+
include Comparable
|
6
|
+
|
5
7
|
SECONDS_IN_24_HOURS = 86400
|
6
8
|
|
7
9
|
MAX_HOURS = 24
|
@@ -30,8 +32,8 @@ class DatelessTime
|
|
30
32
|
|
31
33
|
|
32
34
|
def to_time(base = Time.now)
|
33
|
-
@time_value
|
34
|
-
|
35
|
+
@time_value = Time.new(base.year, base.month, base.day,
|
36
|
+
@hours, @minutes, @seconds, base.utc_offset)
|
35
37
|
rescue
|
36
38
|
nil
|
37
39
|
end
|
@@ -68,6 +70,12 @@ class DatelessTime
|
|
68
70
|
end
|
69
71
|
|
70
72
|
|
73
|
+
def <=>(other)
|
74
|
+
raise TypeError unless other.is_a?(DatelessTime)
|
75
|
+
to_i <=> other.to_i
|
76
|
+
end
|
77
|
+
|
78
|
+
|
71
79
|
|
72
80
|
private
|
73
81
|
|
@@ -0,0 +1,110 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ComparableTest < Minitest::Test
|
4
|
+
|
5
|
+
def test_base_compare
|
6
|
+
@t1 = DatelessTime.new "10:30:00"
|
7
|
+
@t2 = DatelessTime.new "15:45:10"
|
8
|
+
|
9
|
+
assert_equal 1, @t2 <=> @t1
|
10
|
+
assert_equal -1, @t1 <=> @t2
|
11
|
+
assert_equal 0, @t1 <=> @t1
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
def test_base_compare_2
|
16
|
+
@t1 = DatelessTime.new [11, 15]
|
17
|
+
@t2 = DatelessTime.new [21]
|
18
|
+
|
19
|
+
assert_equal 1, @t2 <=> @t1
|
20
|
+
assert_equal -1, @t1 <=> @t2
|
21
|
+
assert_equal 0, @t1 <=> @t1
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
def test_less_than
|
26
|
+
@t1 = DatelessTime.new "10:30:00"
|
27
|
+
@t2 = DatelessTime.new "15:45:10"
|
28
|
+
|
29
|
+
assert @t1 < @t2
|
30
|
+
refute @t1 == @t2
|
31
|
+
refute @t2 < @t1
|
32
|
+
refute @t1 < @t1
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
def test_less_or_equal_to
|
37
|
+
@t1 = DatelessTime.new "10:30:00"
|
38
|
+
@t2 = DatelessTime.new "15:45:10"
|
39
|
+
@t3 = DatelessTime.new "10:30:00"
|
40
|
+
|
41
|
+
assert @t1 <= @t2
|
42
|
+
assert @t1 <= @t3
|
43
|
+
refute @t1 == @t2
|
44
|
+
assert @t1 == @t3
|
45
|
+
refute @t2 <= @t1
|
46
|
+
assert @t3 <= @t1
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
def test_greater_than
|
51
|
+
@t1 = DatelessTime.new "15:45:10"
|
52
|
+
@t2 = DatelessTime.new "10:30:00"
|
53
|
+
|
54
|
+
assert @t1 > @t2
|
55
|
+
refute @t1 == @t2
|
56
|
+
refute @t2 > @t1
|
57
|
+
refute @t1 > @t1
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
def test_greater_or_equal_to
|
62
|
+
@t1 = DatelessTime.new "15:45:10"
|
63
|
+
@t2 = DatelessTime.new "10:30:00"
|
64
|
+
@t3 = DatelessTime.new "15:45:10"
|
65
|
+
|
66
|
+
assert @t1 >= @t2
|
67
|
+
assert @t1 >= @t3
|
68
|
+
refute @t1 == @t2
|
69
|
+
assert @t1 == @t3
|
70
|
+
refute @t2 >= @t1
|
71
|
+
assert @t3 >= @t1
|
72
|
+
end
|
73
|
+
|
74
|
+
|
75
|
+
def test_equal_to
|
76
|
+
@t1 = DatelessTime.new "15:45:10"
|
77
|
+
@t2 = DatelessTime.new "10:30:00"
|
78
|
+
@t3 = DatelessTime.new "15:45:10"
|
79
|
+
|
80
|
+
refute @t1 == @t2
|
81
|
+
assert @t1 == @t3
|
82
|
+
assert @t3 == @t1
|
83
|
+
end
|
84
|
+
|
85
|
+
|
86
|
+
# != is defined on BasicObjct, not Comparable (I think)
|
87
|
+
# Oh, well.
|
88
|
+
#
|
89
|
+
def test_not_equal_to
|
90
|
+
@t1 = DatelessTime.new "15:45:10"
|
91
|
+
@t2 = DatelessTime.new "10:30:00"
|
92
|
+
@t3 = DatelessTime.new "15:45:10"
|
93
|
+
|
94
|
+
assert @t1 != @t2
|
95
|
+
refute @t1 != @t3
|
96
|
+
refute @t3 != @t1
|
97
|
+
end
|
98
|
+
|
99
|
+
|
100
|
+
def test_between
|
101
|
+
@t1 = DatelessTime.new "10:45:10"
|
102
|
+
@t2 = DatelessTime.new "13:30:00"
|
103
|
+
@t3 = DatelessTime.new "20:20:10"
|
104
|
+
|
105
|
+
assert @t2.between?(@t1, @t3)
|
106
|
+
refute @t1.between?(@t2, @t3)
|
107
|
+
refute @t3.between?(@t1, @t2)
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
data/test/query_test.rb
CHANGED
@@ -27,6 +27,23 @@ class QueryTest < Minitest::Test
|
|
27
27
|
end
|
28
28
|
|
29
29
|
|
30
|
+
def test_to_time_with_different_bases_should_change
|
31
|
+
@to_time = @dl_time.to_time
|
32
|
+
now = Time.now
|
33
|
+
expected = Time.new(now.year, now.month, now.day, 13, 37, 42, now.utc_offset)
|
34
|
+
|
35
|
+
assert_equal Time, @to_time.class
|
36
|
+
assert_equal expected, @to_time
|
37
|
+
|
38
|
+
|
39
|
+
base = Time.new(1990, 11, 10, 12, 13, 14)
|
40
|
+
@to_time = @dl_time.to_time(base)
|
41
|
+
|
42
|
+
assert_equal Time, @to_time.class
|
43
|
+
assert_equal Time.new(1990, 11, 10, 13, 37, 42), @to_time
|
44
|
+
end
|
45
|
+
|
46
|
+
|
30
47
|
def test_to_s
|
31
48
|
assert_equal "13:37:42", @dl_time.to_s
|
32
49
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dateless_time
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tommaso Pavese
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-04-
|
11
|
+
date: 2014-04-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,7 +52,8 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 5.3.1
|
55
|
-
description: A class to handle dateless time values.
|
55
|
+
description: A class to handle dateless time values. DatelessTime objects are a lightweight
|
56
|
+
alternative to Ruby's default Time class, and don't care about timezones and DST.
|
56
57
|
email:
|
57
58
|
executables: []
|
58
59
|
extensions: []
|
@@ -66,6 +67,7 @@ files:
|
|
66
67
|
- dateless_time.gemspec
|
67
68
|
- lib/dateless_time.rb
|
68
69
|
- lib/dateless_time/version.rb
|
70
|
+
- test/comparable_test.rb
|
69
71
|
- test/creation_test.rb
|
70
72
|
- test/query_test.rb
|
71
73
|
- test/test_helper.rb
|
@@ -92,9 +94,9 @@ rubyforge_project:
|
|
92
94
|
rubygems_version: 2.2.2
|
93
95
|
signing_key:
|
94
96
|
specification_version: 4
|
95
|
-
summary: A class to handle dateless time values.
|
96
|
-
alternative Ruby's default Time class, and don't care about timezones and DST.
|
97
|
+
summary: A class to handle dateless time values.
|
97
98
|
test_files:
|
99
|
+
- test/comparable_test.rb
|
98
100
|
- test/creation_test.rb
|
99
101
|
- test/query_test.rb
|
100
102
|
- test/test_helper.rb
|