delta_t 0.0.1 → 0.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.
@@ -30,7 +30,7 @@ module DeltaT
30
30
  sum += @diff[i].send UNITS[i]
31
31
  i += 1
32
32
  end
33
- sum / 1.send(UNITS[index])
33
+ sum.to_i / 1.send(UNITS[index]).to_i
34
34
  end
35
35
  end
36
36
  end
@@ -45,6 +45,22 @@ module DeltaT
45
45
  eql
46
46
  end
47
47
 
48
+ def < other
49
+ to_f < other.to_f
50
+ end
51
+
52
+ def > other
53
+ other < self
54
+ end
55
+
56
+ def <= other
57
+ !(self > other)
58
+ end
59
+
60
+ def >= other
61
+ !(self < other)
62
+ end
63
+
48
64
  ##
49
65
  # Either adds two TimeDiffs together or advances a time by this TimeDiff
50
66
  def + other
@@ -111,6 +127,10 @@ module DeltaT
111
127
  h
112
128
  end
113
129
 
130
+ def to_s
131
+ to_f.to_s
132
+ end
133
+
114
134
  protected
115
135
 
116
136
  def apply_time_diff ending, start
@@ -1,3 +1,3 @@
1
1
  module DeltaT
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -1,16 +1,11 @@
1
1
  require File.dirname(__FILE__) + '/helper'
2
2
 
3
- class DeltaT::TimeDiff
4
- # exposing internals for better testing
5
- # nano secs are ignored cause they are just implemented for compatibility with old play time diff
6
- # current implementation: [y,m,d,h,m,s]
7
- def diff
8
- @diff.reverse[0..-2]
9
- end
10
- end
11
-
12
3
  class DeltaTTest < Test::Unit::TestCase
13
4
 
5
+ def assert_components expected, actual
6
+ assert_equal expected, [actual.years, actual.months, actual.days, actual.hours, actual.minutes, actual.seconds]
7
+ end
8
+
14
9
  # caution - depends on current time so if buggy non deterministic
15
10
  def test_simple_difference
16
11
  now = Time.now
@@ -24,19 +19,19 @@ class DeltaTTest < Test::Unit::TestCase
24
19
  end
25
20
 
26
21
  def test_overlapping_difference
27
- assert_equal [0,0,0,0,0,2], DeltaT::TimeDiff.new(Time.new(2000, 1, 1, 0, 1 , 1), Time.new(2000, 1, 1, 0, 0, 59)).diff
28
- assert_equal [0,0,2,0,0,0], DeltaT::TimeDiff.new(Time.new(2000, 2, 1), Time.new(2000, 1, 30)).diff
22
+ assert_components [0,0,0,0,0,2], DeltaT::TimeDiff.new(Time.new(2000, 1, 1, 0, 1 , 1), Time.new(2000, 1, 1, 0, 0, 59))
23
+ assert_components [0,0,2,0,0,0], DeltaT::TimeDiff.new(Time.new(2000, 2, 1), Time.new(2000, 1, 30))
29
24
  end
30
25
 
31
26
  def test_negative_difference
32
- assert_equal [1, 2, 10, 0, 3, 2], DeltaT::TimeDiff.new(Time.new(2001, 6, 15, 10, 4, 1), Time.new(2000, 4, 5, 10, 0, 59)).diff
33
- assert_equal [-1, -2, -10, 0, -3, -2], DeltaT::TimeDiff.new(Time.new(2000, 4, 5, 10, 0, 59), Time.new(2001, 6, 15, 10, 4, 1)).diff
27
+ assert_components [1, 2, 10, 0, 3, 2], DeltaT::TimeDiff.new(Time.new(2001, 6, 15, 10, 4, 1), Time.new(2000, 4, 5, 10, 0, 59))
28
+ assert_components [-1, -2, -10, 0, -3, -2], DeltaT::TimeDiff.new(Time.new(2000, 4, 5, 10, 0, 59), Time.new(2001, 6, 15, 10, 4, 1))
34
29
  end
35
30
 
36
31
  def test_init
37
- assert_equal [1,2,3,4,5,6], DeltaT::TimeDiff.new(years: 1, months: 2, days: 3, hours: 4, minutes: 5, seconds: 6).diff
38
- assert_equal [1,0,3,0,0,0], DeltaT::TimeDiff.new(years: 1, days: 3).diff
39
- assert_equal [1,0,0,0,0,0], DeltaT::TimeDiff.new(years: 1).diff
32
+ assert_components [1,2,3,4,5,6], DeltaT::TimeDiff.new(years: 1, months: 2, days: 3, hours: 4, minutes: 5, seconds: 6)
33
+ assert_components [1,0,3,0,0,0], DeltaT::TimeDiff.new(years: 1, days: 3)
34
+ assert_components [1,0,0,0,0,0], DeltaT::TimeDiff.new(years: 1)
40
35
  end
41
36
 
42
37
  def test_equals
@@ -54,9 +49,9 @@ class DeltaTTest < Test::Unit::TestCase
54
49
  end
55
50
 
56
51
  def test_normalization
57
- assert_equal [0,1,21,0,0,0], DeltaT::TimeDiff.new(days: 51).diff
58
- assert_equal [0,1,10,18,5,0], DeltaT::TimeDiff.new(minutes: 60*24*40 + 60*18 + 5).diff
59
- assert_equal [0,-1,-10,-18,-5,0], DeltaT::TimeDiff.new(minutes: -(60*24*40 + 60*18 + 5)).diff
52
+ assert_components [0,1,21,0,0,0], DeltaT::TimeDiff.new(days: 51)
53
+ assert_components [0,1,10,18,5,0], DeltaT::TimeDiff.new(minutes: 60*24*40 + 60*18 + 5)
54
+ assert_components [0,-1,-10,-18,-5,0], DeltaT::TimeDiff.new(minutes: -(60*24*40 + 60*18 + 5))
60
55
  end
61
56
 
62
57
  def test_to_hash
@@ -65,9 +60,18 @@ class DeltaTTest < Test::Unit::TestCase
65
60
  end
66
61
 
67
62
  def test_operators
68
- assert_equal [1,3,0,0,0,0], (DeltaT::TimeDiff.new(months: 11) + DeltaT::TimeDiff.new(months: 4)).diff
69
- assert_equal [0,7,0,0,0,0], (DeltaT::TimeDiff.new(months: 11) - DeltaT::TimeDiff.new(months: 4)).diff
70
- assert_equal [2,9,0,0,0,0], (DeltaT::TimeDiff.new(months: 11) * 3).diff
63
+ assert_components [1,3,0,0,0,0], (DeltaT::TimeDiff.new(months: 11) + DeltaT::TimeDiff.new(months: 4))
64
+ assert_components [0,7,0,0,0,0], (DeltaT::TimeDiff.new(months: 11) - DeltaT::TimeDiff.new(months: 4))
65
+ assert_components [2,9,0,0,0,0], (DeltaT::TimeDiff.new(months: 11) * 3)
66
+ end
67
+
68
+ def test_comparison_operators
69
+ assert DeltaT::TimeDiff.new(months: 1) < DeltaT::TimeDiff.new(days: 35)
70
+ assert DeltaT::TimeDiff.new(days: 35) > DeltaT::TimeDiff.new(months: 1)
71
+
72
+ assert DeltaT::TimeDiff.new(hours: 3) <= DeltaT::TimeDiff.new(minutes: 180)
73
+ assert DeltaT::TimeDiff.new(hours: 3) <= DeltaT::TimeDiff.new(minutes: 180, seconds: 5)
74
+ assert !(DeltaT::TimeDiff.new(hours: 3) >= DeltaT::TimeDiff.new(minutes: 180, seconds: 5))
71
75
  end
72
76
 
73
77
  def test_time_operators
@@ -83,4 +87,4 @@ class DeltaTTest < Test::Unit::TestCase
83
87
  assert_equal before, after - (after - before)
84
88
  assert_equal before, -(after - before) + after
85
89
  end
86
- end
90
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: delta_t
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-03 00:00:00.000000000 Z
12
+ date: 2012-08-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake