interest_days 0.5.2 → 0.5.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +1 -1
- data/interest_days.gemspec +0 -1
- data/lib/interest_days/calculation/icma_act_act.rb +9 -7
- data/lib/interest_days/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 10512ef2d8b56d0c8110707011f3b9588a2fdd11bea9c5ba2efbf28f4f898da5
|
4
|
+
data.tar.gz: 5d5eceafc7ef04cb73e07828d28cd9345f6b6bc065682d8da8d770f6ab64ed9c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6ecb400209fb903908d8e3c1bf9be08f81ca2b8dd58543b87a301b167b1f875faf6831f52d31da9862cb071a2852ef797dd00b2478918771cdb99aab3d803daa
|
7
|
+
data.tar.gz: 381edf8b7bf4ee0dce7ed7c0ef288ebbf2ddf617da4cfc5980254b46826a48035267bc901734e1c78eceebe7e7ae46ae0247df1cb5165a4c18ea858136927ce5
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/interest_days.gemspec
CHANGED
@@ -14,7 +14,6 @@ Gem::Specification.new do |spec|
|
|
14
14
|
spec.license = "MIT"
|
15
15
|
spec.required_ruby_version = ">= 2.7.0"
|
16
16
|
|
17
|
-
|
18
17
|
spec.metadata["homepage_uri"] = spec.homepage
|
19
18
|
spec.metadata["source_code_uri"] = "https://github.com/eugenmueller/interest_days"
|
20
19
|
spec.metadata["changelog_uri"] = "https://github.com/eugenmueller/interest_days/blob/v0.2.0/CHANGELOG.md"
|
@@ -8,17 +8,14 @@ module InterestDays
|
|
8
8
|
DAYS_IN_LEAP_YEAR = 366
|
9
9
|
|
10
10
|
def day_count_factor
|
11
|
-
return
|
12
|
-
|
13
|
-
if years_in_between_factor.positive?
|
14
|
-
return start_date_period_factor + years_in_between_factor + end_date_period_factor
|
15
|
-
end
|
11
|
+
return multiple_years_day_count_factor if years_in_between_factor.positive?
|
16
12
|
|
17
13
|
days.fdiv(year_days_in_period)
|
18
14
|
end
|
19
15
|
|
20
16
|
private
|
21
17
|
|
18
|
+
# calculate for periods smaller than a year
|
22
19
|
def year_days_in_period
|
23
20
|
period_contains_leap_day? ? DAYS_IN_LEAP_YEAR : DAYS_IN_YEAR
|
24
21
|
end
|
@@ -35,6 +32,11 @@ module InterestDays
|
|
35
32
|
end
|
36
33
|
end
|
37
34
|
|
35
|
+
# claculate for period span more than a year
|
36
|
+
def multiple_years_day_count_factor
|
37
|
+
start_date_period_factor + years_in_between_factor + end_date_period_factor
|
38
|
+
end
|
39
|
+
|
38
40
|
def start_date_period_factor
|
39
41
|
(start_date_days_in_year - start_date.yday).fdiv(start_date_days_in_year)
|
40
42
|
end
|
@@ -48,11 +50,11 @@ module InterestDays
|
|
48
50
|
end
|
49
51
|
|
50
52
|
def start_date_period_with_leap_date?
|
51
|
-
start_date.leap? && start_date.
|
53
|
+
start_date.leap? && Date.new(start_date.year, 2, 29)&.between?(start_date, Date.new(start_date.year, 12, 31))
|
52
54
|
end
|
53
55
|
|
54
56
|
def end_date_period_with_leap_date?
|
55
|
-
end_date.leap? && end_date
|
57
|
+
end_date.leap? && Date.new(end_date.year, 2, 29)&.between?(Date.new(end_date.year, 1, 1), end_date)
|
56
58
|
end
|
57
59
|
|
58
60
|
def start_date_and_end_date_in_same_year?
|