units-time 1.0.1 → 1.0.2
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 +4 -4
- data/lib/units-time/timestamp.rb +5 -1
- data/lib/units-time/version.rb +1 -1
- data/test/test_units_time.rb +3 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 85825ae67f49319633b3464c0a752a720d9a8a4c
|
4
|
+
data.tar.gz: 86166febad3c6aa8cae454ac4ca9e0e5363bf7ce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eeb084bd4553ca0f1f0f446e1832c22e3cd5a9893ffd160bee4d6b7eec2d537ee5270f61b2cbdc720bbd3fab702377be18986e69a7237b1d403fa7daf958fc02
|
7
|
+
data.tar.gz: d53de4ff638e3e0bbd527d4a8451b2aac67b8d58d60ab851f0ef1e7d0dd2df92012a3a1ce6aeb67e0d44873db249b0ca7a7e2b7b4848d7f25025d26c95694130
|
data/lib/units-time/timestamp.rb
CHANGED
@@ -3,7 +3,8 @@
|
|
3
3
|
|
4
4
|
class Timestamp
|
5
5
|
|
6
|
-
|
6
|
+
## todo: double check that Time.now.to_i always returns seconds in utc/gmt "universal" time (and not local time)
|
7
|
+
def self.now() new; end
|
7
8
|
|
8
9
|
attr_reader :seconds
|
9
10
|
|
@@ -31,6 +32,9 @@ class Timestamp
|
|
31
32
|
def -( other )
|
32
33
|
if other.is_a?( Timedelta )
|
33
34
|
self.class.new( @seconds - other.seconds )
|
35
|
+
elsif other.is_a?( Timestamp ) ## note: returns Timedelta class/object!!!
|
36
|
+
## todo: check how to deal with negative timedelta - allow !? - why? why not?
|
37
|
+
Timedelta.new( @seconds - other.seconds )
|
34
38
|
else
|
35
39
|
raise TypeError.new( "[Timestamp] sub(straction) - wrong type >#{other.inspect}< #{other.class.name} - Timedelta expected" )
|
36
40
|
end
|
data/lib/units-time/version.rb
CHANGED
data/test/test_units_time.rb
CHANGED
@@ -97,6 +97,9 @@ def test_timedelta_ops
|
|
97
97
|
assert_equal Timedelta, (100 * 1.hour).class
|
98
98
|
assert_equal now+100*3600.secs, now + (100 * 1.hour)
|
99
99
|
assert_equal Timestamp, (now + (100 * 1.hour)).class
|
100
|
+
|
101
|
+
assert_equal 2.weeks, (now+2.weeks) - now
|
102
|
+
assert_equal Timedelta, ((now+2.weeks) - now).class
|
100
103
|
end
|
101
104
|
|
102
105
|
def test_conv
|