date_diff 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -9,29 +9,29 @@ class Date
9
9
  common_year_days_in_month = [ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
10
10
  start_date, end_date = end_date, start_date if start_date > end_date
11
11
 
12
- start_date_month, start_date_day = start_date.month, start_date.day
13
- end_date_month, end_date_day = end_date.month, end_date.day
12
+ start_date_year, start_date_month, start_date_day = start_date.year, start_date.month, start_date.day
13
+ end_date_year, end_date_month, end_date_day = end_date.year, end_date.month, end_date.day
14
14
 
15
15
  day_difference = end_date_day - start_date_day
16
16
 
17
17
  if (day_difference < 0)
18
18
  day_difference = common_year_days_in_month[start_date_month-1] - start_date_day + end_date_day
19
- end_date_month = end_date_month -1
19
+ end_date_month -= 1
20
20
  end
21
21
 
22
22
  if (end_date_month < 0)
23
- end_date_month = end_date_month + 12
24
- end_date.year = end_date.year -1
23
+ end_date_month += 12
24
+ end_date_year -= 1
25
25
  end
26
26
 
27
27
  month_difference = end_date_month - start_date_month
28
28
 
29
29
  if (month_difference < 0)
30
- month_difference = month_difference + 12
31
- end_date.year = end_date.year -1
30
+ month_difference += 12
31
+ end_date_year -= 1
32
32
  end
33
33
 
34
- year_difference = end_date.year - start_date.year
34
+ year_difference = end_date_year - start_date_year
35
35
 
36
36
  difference_hash = { :year => year_difference, :month => month_difference, :day => day_difference }
37
37
 
@@ -1,3 +1,3 @@
1
1
  module DateDiff
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -4,6 +4,7 @@ require 'date'
4
4
  class TestDateDiff < MiniTest::Unit::TestCase
5
5
 
6
6
  def test_date_diff_method
7
+
7
8
  [
8
9
  [Date.parse('2013-01-01'), Date.parse('2013-01-01'), {:year => 0, :month => 0, :day => 0, :difference => ""}],
9
10
  [Date.parse('2013-01-01'), Date.parse('2013-01-02'), {:year => 0, :month => 0, :day => 1, :difference => "1 day"}],
@@ -15,7 +16,11 @@ class TestDateDiff < MiniTest::Unit::TestCase
15
16
  [Date.parse('2000-01-01'), Date.parse('2013-01-01'), {:year => 13, :month => 0, :day => 0, :difference => "13 years"}],
16
17
  [Date.parse('2013-08-28'), Date.parse('2014-08-28'), {:year => 1, :month => 0, :day => 0, :difference => "1 year"}],
17
18
 
18
- [Date.parse('2000-01-01'), Date.parse('2013-06-19'), {:year => 13, :month => 5, :day => 18, :difference => "13 years 5 months 18 days"}]
19
+ [Date.parse('2000-01-01'), Date.parse('2013-06-19'), {:year => 13, :month => 5, :day => 18, :difference => "13 years 5 months 18 days"}],
20
+ [Date.parse('2013-11-19'), Date.parse('2013-11-25'), {:year => 0, :month => 0, :day => 6, :difference => "6 days"}],
21
+ [Date.parse('2012-11-27'), Date.parse('2013-11-25'), {:year => 0, :month => 11, :day => 28, :difference => "11 months 28 days"}]
22
+
23
+
19
24
  ].each do |input|
20
25
  assert_equal(Date.diff(input[0], input[1]), input[2])
21
26
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: date_diff
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
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: 2013-11-25 00:00:00.000000000 Z
12
+ date: 2013-11-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler