years_between 1.0.0 → 1.0.1
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/years_between.rb +14 -2
- metadata +6 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8413897b327fafda720e980be31682f6e04a72206a1fdb22b875071e13c43c15
|
|
4
|
+
data.tar.gz: c87f18be793c81285c30b4947fbb2c236b443bb6c61e69c025acf4600c6a9611
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6ccb87379b40e54be0dd464838002b6b5de0549f7300c03f578fdb0603f8033b3db25bcc036dc2e09999830c9edc5282efdfcd48200cda5f4f0f6d4f4ee40017
|
|
7
|
+
data.tar.gz: c9ecbac34ccbc54a234eb0aa74679be278c4702b4269c081e77ee3adeaeed91e58d88d92aa3e4b52f1fa5f3b6dc934dcbed5b60c174e86743bc926f40d9331e0
|
data/lib/years_between.rb
CHANGED
|
@@ -1,12 +1,24 @@
|
|
|
1
1
|
require 'date'
|
|
2
2
|
|
|
3
3
|
class YearsBetween
|
|
4
|
+
|
|
5
|
+
class MissingDateError < StandardError
|
|
6
|
+
def message
|
|
7
|
+
'start_date and end_date must be present'
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
class StartDateAfterEndDateError < StandardError
|
|
11
|
+
def message
|
|
12
|
+
'start_date cannot be past end_date'
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
4
16
|
def self.calculate_years_between(start_date, end_date, exclude: nil)
|
|
5
17
|
start_date += 1 if exclude.to_s == 'start_date' || exclude.to_s == 'both'
|
|
6
18
|
end_date -= 1 if exclude.to_s == 'end_date' || exclude.to_s == 'both'
|
|
7
19
|
|
|
8
|
-
raise
|
|
9
|
-
raise
|
|
20
|
+
raise MissingDateError if [start_date, end_date].any?(&:nil?)
|
|
21
|
+
raise StartDateAfterEndDateError if start_date > end_date
|
|
10
22
|
|
|
11
23
|
start_year = start_date.year
|
|
12
24
|
start_month = start_date.month
|
metadata
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: years_between
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0.
|
|
4
|
+
version: 1.0.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ivaldi
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
11
|
date: 2020-10-07 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: Calculates years between dates including decimals
|
|
14
|
-
email:
|
|
14
|
+
email:
|
|
15
15
|
executables: []
|
|
16
16
|
extensions: []
|
|
17
17
|
extra_rdoc_files: []
|
|
@@ -20,7 +20,7 @@ files:
|
|
|
20
20
|
homepage: https://rubygems.org/gems/years_between
|
|
21
21
|
licenses: []
|
|
22
22
|
metadata: {}
|
|
23
|
-
post_install_message:
|
|
23
|
+
post_install_message:
|
|
24
24
|
rdoc_options: []
|
|
25
25
|
require_paths:
|
|
26
26
|
- lib
|
|
@@ -35,9 +35,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
35
35
|
- !ruby/object:Gem::Version
|
|
36
36
|
version: '0'
|
|
37
37
|
requirements: []
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
signing_key:
|
|
38
|
+
rubygems_version: 3.1.4
|
|
39
|
+
signing_key:
|
|
41
40
|
specification_version: 4
|
|
42
41
|
summary: Calculates years between dates including decimals
|
|
43
42
|
test_files: []
|