mudrat_projector 0.9.2 → 0.9.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/mudrat_projector/date_diff.rb +8 -2
- data/lib/mudrat_projector/version.rb +1 -1
- data/test/models/date_diff_test.rb +5 -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: 99cf860a7f16e297d956e8b018652994a216552c
|
4
|
+
data.tar.gz: 51de6ef4a9280d86339c5e045cd3514f6475259c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 25820eacfe06c533db174462a6cc9ae66a826751ddbeda829250ae2970fb92ed8a15ffdc3366d92b9a76b478a3996206ec074ea7f965609d24b1904435b00834
|
7
|
+
data.tar.gz: 89671345c7a2ebd2ef4513a20312d676bd1d0a023df1a066def36a6fa3c855eb6ec3400745431f375800ac7cc35240d795b84b0dff917d3f9b4d56c0c20ca0e4
|
@@ -113,8 +113,14 @@ module MudratProjector
|
|
113
113
|
end
|
114
114
|
|
115
115
|
def self.advance intervals, from: from
|
116
|
-
|
117
|
-
|
116
|
+
if intervals < 1
|
117
|
+
days_in_year = from.leap? ? 366 : 365
|
118
|
+
days = intervals * days_in_year
|
119
|
+
DayCalculator.advance days, from: from
|
120
|
+
else
|
121
|
+
method = intervals > 0 ? :next_year : :prev_year
|
122
|
+
intervals.times.inject from do |date, _| date.public_send method; end
|
123
|
+
end
|
118
124
|
end
|
119
125
|
end
|
120
126
|
|
@@ -109,6 +109,11 @@ class DateDiffTest < Minitest::Test
|
|
109
109
|
assert_equal Date.new(2001, 2, 28), advance(from: feb_29_2000, unit: :year, intervals: 1)
|
110
110
|
end
|
111
111
|
|
112
|
+
def test_advancing_one_year_and_a_day
|
113
|
+
assert_equal Date.new(2000, 1, 2), advance(from: jan_1_2000, unit: :year, intervals: (1.to_d / 366))
|
114
|
+
assert_equal Date.new(2001, 1, 2), advance(from: jan_1_2001, unit: :year, intervals: (1.to_d / 365))
|
115
|
+
end
|
116
|
+
|
112
117
|
private
|
113
118
|
|
114
119
|
def date_diff *args
|