fat_date 0.2.0 → 0.3.0
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/.envrc +1 -0
- data/lib/fat_date/date.rb +20 -16
- data/lib/fat_date/date_time.rb +18 -5
- data/lib/fat_date/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 02b7395e6d488e21ee9697e6a8b2188406dc6a6280a62f0fa13cb0c05e0d76d8
|
|
4
|
+
data.tar.gz: 4c4d7bceb4e4ab030a9428f387f94511ee2295ab3b79f13ef4533cc74e09c79d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 65f8a88294822810432919b8fbcddd4193e47108878401e235cf9e873dc002c346bdcbfcfbf907f0a0ce5badfd94dcebc69ad41e1ef3ba383bd07d8b6a2e2e76
|
|
7
|
+
data.tar.gz: beb437f20882349eb2eb6fafa6d28ca669fb72a9e12145d8926090247b840ed9f1bcf3f6d5bbddd3d7979d75998cae123be1d0f1d616afaf9336b891d69d4b5f
|
data/.envrc
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
PATH_add .bundle/bin
|
data/lib/fat_date/date.rb
CHANGED
|
@@ -925,7 +925,7 @@ module FatDate
|
|
|
925
925
|
end
|
|
926
926
|
|
|
927
927
|
# Holidays decreed by Presidential proclamation
|
|
928
|
-
|
|
928
|
+
FED_DECREED_HOLIDAYS =
|
|
929
929
|
[
|
|
930
930
|
# Obama decree extra day before Christmas See
|
|
931
931
|
# http://www.whitehouse.gov/the-press-office/2012/12/21
|
|
@@ -1292,7 +1292,7 @@ module FatDate
|
|
|
1292
1292
|
# rigged to fall on Monday except Thanksgiving
|
|
1293
1293
|
|
|
1294
1294
|
# No moveable feasts in certain months
|
|
1295
|
-
return false if [
|
|
1295
|
+
return false if [7, 8, 10, 12].include?(month)
|
|
1296
1296
|
|
|
1297
1297
|
case month
|
|
1298
1298
|
when 1
|
|
@@ -1327,13 +1327,13 @@ module FatDate
|
|
|
1327
1327
|
if year < 2022
|
|
1328
1328
|
false
|
|
1329
1329
|
else
|
|
1330
|
-
jun19 = Date.new(year, 6, 19)
|
|
1331
|
-
if jun19.saturday?
|
|
1332
|
-
|
|
1330
|
+
jun19 = ::Date.new(year, 6, 19)
|
|
1331
|
+
day == if jun19.saturday?
|
|
1332
|
+
18
|
|
1333
1333
|
elsif jun19.sunday?
|
|
1334
|
-
|
|
1334
|
+
20
|
|
1335
1335
|
else
|
|
1336
|
-
|
|
1336
|
+
19
|
|
1337
1337
|
end
|
|
1338
1338
|
end
|
|
1339
1339
|
when 9
|
|
@@ -2022,7 +2022,8 @@ module FatDate
|
|
|
2022
2022
|
|
|
2023
2023
|
# Ensure that date is of class Date based either on a string or Date
|
|
2024
2024
|
# object or an object that responds to #to_date or #to_datetime. If the
|
|
2025
|
-
# given object is a String, use Date.parse
|
|
2025
|
+
# given object is a String, use Date.parse unless it contains time
|
|
2026
|
+
# components, in which case use DateTime.parse.
|
|
2026
2027
|
#
|
|
2027
2028
|
# If given a DateTime, it returns the unrounded DateTime; if given a
|
|
2028
2029
|
# Time, it converts it to a DateTime.
|
|
@@ -2034,16 +2035,21 @@ module FatDate
|
|
|
2034
2035
|
dat
|
|
2035
2036
|
elsif dat.is_a?(Time)
|
|
2036
2037
|
dat.to_datetime
|
|
2037
|
-
elsif dat.respond_to?(:to_datetime)
|
|
2038
|
-
dat.to_datetime
|
|
2039
|
-
elsif dat.respond_to?(:to_date)
|
|
2040
|
-
dat.to_date
|
|
2041
2038
|
elsif dat.is_a?(String)
|
|
2042
2039
|
begin
|
|
2043
|
-
::Date.
|
|
2040
|
+
parts = ::Date._parse(dat)
|
|
2041
|
+
if %i[hour min sec sec_fraction].any? { |part| parts.key?(part) }
|
|
2042
|
+
::DateTime.parse(dat)
|
|
2043
|
+
else
|
|
2044
|
+
::Date.parse(dat)
|
|
2045
|
+
end
|
|
2044
2046
|
rescue ::Date::Error
|
|
2045
2047
|
raise ArgumentError, "cannot convert string '#{dat}' to a Date or DateTime"
|
|
2046
2048
|
end
|
|
2049
|
+
elsif dat.respond_to?(:to_datetime)
|
|
2050
|
+
dat.to_datetime
|
|
2051
|
+
elsif dat.respond_to?(:to_date)
|
|
2052
|
+
dat.to_date
|
|
2047
2053
|
else
|
|
2048
2054
|
raise ArgumentError, "cannot convert class '#{dat.class}' to a Date or DateTime"
|
|
2049
2055
|
end
|
|
@@ -2061,6 +2067,4 @@ module FatDate
|
|
|
2061
2067
|
end
|
|
2062
2068
|
|
|
2063
2069
|
# Include the FatDate methods in Date.
|
|
2064
|
-
|
|
2065
|
-
include FatDate::Date
|
|
2066
|
-
end
|
|
2070
|
+
Date.include(FatDate::Date)
|
data/lib/fat_date/date_time.rb
CHANGED
|
@@ -7,11 +7,24 @@ module FatDate
|
|
|
7
7
|
def iso
|
|
8
8
|
strftime('%Y-%m-%dT%H:%M:%S.%3N%:%z')
|
|
9
9
|
end
|
|
10
|
+
|
|
11
|
+
module ClassMethods
|
|
12
|
+
# Convert a date-like object to DateTime, using midnight for date-only
|
|
13
|
+
# inputs and preserving time components and offsets when present.
|
|
14
|
+
# @param dat [String, Date, DateTime, Time] the object to be converted
|
|
15
|
+
# @return [DateTime]
|
|
16
|
+
def ensure(dat)
|
|
17
|
+
::Date.ensure(dat).to_datetime
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
alias_method :ensure_datetime, :ensure
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def self.included(base)
|
|
24
|
+
base.extend(ClassMethods)
|
|
25
|
+
end
|
|
10
26
|
end
|
|
11
27
|
end
|
|
12
28
|
|
|
13
|
-
# Include the FatDate
|
|
14
|
-
|
|
15
|
-
class DateTime
|
|
16
|
-
include FatDate::DateTime
|
|
17
|
-
end
|
|
29
|
+
# Include the FatDate instance and class methods in DateTime.
|
|
30
|
+
DateTime.include(FatDate::DateTime)
|
data/lib/fat_date/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: fat_date
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Daniel E. Doherty
|
|
8
8
|
bindir: bin
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date: 2026-06
|
|
10
|
+
date: 2026-11-06 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
12
|
- !ruby/object:Gem::Dependency
|
|
13
13
|
name: activesupport
|
|
@@ -49,6 +49,7 @@ executables: []
|
|
|
49
49
|
extensions: []
|
|
50
50
|
extra_rdoc_files: []
|
|
51
51
|
files:
|
|
52
|
+
- ".envrc"
|
|
52
53
|
- ".rspec"
|
|
53
54
|
- ".rubocop.yml"
|
|
54
55
|
- ".ruby-version"
|