fat_core 4.4.0 → 4.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/fat_core/date.rb +19 -2
- data/lib/fat_core/version.rb +1 -1
- data/spec/lib/date_spec.rb +23 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 97161dc36f0df6d27448883128611d04d79799b203402c1ab34e3d0cc23ba26d
|
4
|
+
data.tar.gz: 829c70f974d3611ba92fbae68a9027f17e77c3a6a179190c4775fb97c86edae1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5803c35e300c504651264405c57578194c815ff644d6018f6a0f76e21879e6c78f7ecefd3ebb7fc88789571c05018e7b3d30a4816aa57f21660b6a6cc1ce2276
|
7
|
+
data.tar.gz: 10757b373c5187a8f1eee6e9bc11dad73bd8965a78ea98b2225e1c459be112b7d2faa7fa21b7ff4c105c52087de1799200301714c9759367fb29debbe6965393
|
data/lib/fat_core/date.rb
CHANGED
@@ -3,6 +3,7 @@ require 'active_support/core_ext/date'
|
|
3
3
|
require 'active_support/core_ext/time'
|
4
4
|
require 'active_support/core_ext/numeric/time'
|
5
5
|
require 'active_support/core_ext/integer/time'
|
6
|
+
require 'fat_core/string'
|
6
7
|
require 'fat_core/patches'
|
7
8
|
|
8
9
|
# ## FatCore Date Extensions
|
@@ -1648,9 +1649,25 @@ module FatCore
|
|
1648
1649
|
n, p = (h + l - 7 * m + 114).divmod(31)
|
1649
1650
|
::Date.new(y, n, p + 1)
|
1650
1651
|
end
|
1651
|
-
end
|
1652
1652
|
|
1653
|
-
|
1653
|
+
# Ensure that date is of class Date based either on a string or Date
|
1654
|
+
# object.
|
1655
|
+
#
|
1656
|
+
# @param dat [String|Date|Time] the object to be converted to Date
|
1657
|
+
# @return [Date]
|
1658
|
+
def ensure_date(dat)
|
1659
|
+
case dat
|
1660
|
+
when String
|
1661
|
+
::Date.parse(dat)
|
1662
|
+
when Date, DateTime
|
1663
|
+
dat
|
1664
|
+
when Time
|
1665
|
+
dat.to_date
|
1666
|
+
else
|
1667
|
+
raise ArgumentError, 'Date.ensure_date needs String, Date, or Time'
|
1668
|
+
end
|
1669
|
+
end
|
1670
|
+
end
|
1654
1671
|
|
1655
1672
|
# @private
|
1656
1673
|
def self.included(base)
|
data/lib/fat_core/version.rb
CHANGED
data/spec/lib/date_spec.rb
CHANGED
@@ -12,6 +12,29 @@ describe Date do
|
|
12
12
|
end
|
13
13
|
|
14
14
|
describe 'class methods' do
|
15
|
+
describe 'ensure_date parsing' do
|
16
|
+
it 'should parse a String as a date' do
|
17
|
+
expect(Date.ensure_date('2018-11-12').class).to be Date
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should leave a Date as a date' do
|
21
|
+
expect(Date.ensure_date(Date.today).class).to be Date
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should convert Time as a date' do
|
25
|
+
expect(Date.ensure_date(Time.now).class).to be Date
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'raises an error for bad date string' do
|
29
|
+
expect { Date.ensure_date('2012-mm-tu') }.to raise_error /invalid date/
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'raises an error for unknown class' do
|
33
|
+
expect { Date.ensure_date([2011, 11, 12]) }
|
34
|
+
.to raise_error /needs String, Date, or Time/
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
15
38
|
describe 'date arithmetic' do
|
16
39
|
it 'should know the number of days in a month' do
|
17
40
|
expect(Date.days_in_month(2000, 1)).to eq 31
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fat_core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel E. Doherty
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-04-
|
11
|
+
date: 2019-04-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: simplecov
|