ifc_date 0.1.1 → 0.2.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/CHANGELOG.md +10 -0
- data/Gemfile.lock +1 -1
- data/lib/ifc_date/class_methods.rb +5 -4
- data/lib/ifc_date/instance_methods.rb +11 -0
- data/lib/ifc_date/version.rb +1 -1
- data/lib/ifc_date.rb +26 -10
- 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: 8ad433793e0ad036ce9c1ec24d911e51bb6c2bedd3de4bc803e80f45c6fa0816
|
4
|
+
data.tar.gz: 8b035067f852ec5af13aa02d7743e3ca4659ed0dcbfe2ba99165de1a8baac1e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 901f390a464a7d8af4f38874943a25bcae0e7c3eb0ab91ee673e851296e0a9eef5f7bf8853d6e91a54301eded36f887fbd0c3c641a52a9d7fa2a4efc22f4c3e0
|
7
|
+
data.tar.gz: 0c945503fff33804c196b06d69fca51cf6a8756c5edfa7bbd5b96da7f71752ea4f5b93b8624f578ebe41a3e75f4a954898ddfb73efd663bc2fe6f01363bf344f
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,15 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [0.2.0] - 2022-07-xx
|
4
|
+
* Add `to_s` and `inspect` method to return ISO8601 style representation
|
5
|
+
* Attach the starday to the week it attaches instead of using zero.
|
6
|
+
So '2022-12-31'.to\_date.ifc.week will be 52 instead of 0
|
7
|
+
and '2020-06-17'.to\_date.ifc.week will be 24 instead of 0
|
8
|
+
* more consistent implementation using the cleaned divmod structure
|
9
|
+
|
3
10
|
## [0.1.0] - 2022-06-08
|
4
11
|
|
5
12
|
- Initial release
|
13
|
+
|
14
|
+
|
15
|
+
|
data/Gemfile.lock
CHANGED
@@ -9,13 +9,14 @@ module IfcDateClassMethods
|
|
9
9
|
# NOTE: only use for explicitly non nil return methods, false is fine
|
10
10
|
def memoize(method_name)
|
11
11
|
unmemoized_name = "_unmemoized_#{method_name}"
|
12
|
-
|
12
|
+
cache_key = method_name.end_with?('?') ? "is_#{method_name[0..-2]}" : "#{method_name}"
|
13
13
|
alias_method unmemoized_name, method_name
|
14
14
|
define_method method_name do |*args, &block|
|
15
|
-
|
16
|
-
return
|
15
|
+
@_memoized_methods ||= {}
|
16
|
+
return @_memoized_methods[cache_key] if @_memoized_methods.has_key?(cache_key)
|
17
17
|
evaluated_result = send(unmemoized_name, *args, &block)
|
18
|
-
|
18
|
+
@_memoized_methods[cache_key] = evaluated_result
|
19
19
|
end
|
20
20
|
end
|
21
|
+
|
21
22
|
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module IfcDateInstanceMethods
|
2
|
+
# In case a crucial element of the object itself changes the memoization should be cleared.
|
3
|
+
# Note that this is not expected since the current way of reasoning assumes new object creation.
|
4
|
+
# Maybe something of the future could be:
|
5
|
+
# date = Date.today.ifc
|
6
|
+
# date.move_forward 3.days
|
7
|
+
# But this is for later consideration
|
8
|
+
def clear_memoization_results
|
9
|
+
@_memoized_methods.clear
|
10
|
+
end
|
11
|
+
end
|
data/lib/ifc_date/version.rb
CHANGED
data/lib/ifc_date.rb
CHANGED
@@ -4,12 +4,16 @@ require 'date'
|
|
4
4
|
require_relative 'ifc_date/version'
|
5
5
|
require_relative 'ifc_date/ext/to_ifc'
|
6
6
|
require_relative 'ifc_date/class_methods'
|
7
|
+
require_relative 'ifc_date/instance_methods.rb'
|
7
8
|
|
8
9
|
class IfcDate
|
9
10
|
class Error < StandardError; end
|
10
11
|
extend IfcDateClassMethods
|
12
|
+
include IfcDateInstanceMethods
|
13
|
+
|
11
14
|
attr_reader :day_of_year, :year
|
12
15
|
alias yday day_of_year
|
16
|
+
|
13
17
|
DAYNAMES = Date::DAYNAMES + ['Starday']
|
14
18
|
ABBR_DAYNAMES = Date::ABBR_DAYNAMES + ['Sta']
|
15
19
|
MONTHNAMES = Date::MONTHNAMES.dup.insert(6, 'Sol')
|
@@ -32,18 +36,26 @@ class IfcDate
|
|
32
36
|
self.class.is_leap_year?(year)
|
33
37
|
end
|
34
38
|
|
39
|
+
# This method caches the divmod result of the:
|
40
|
+
# zero based (working number starts with 1) day of the year
|
41
|
+
# where Leap day is removed. By applying the divmod on the
|
42
|
+
# 'cleaner' representation of the day of the year, other parts
|
43
|
+
# of the code become easier to reason about.
|
35
44
|
memoize def day_of_year_divmod_seven
|
36
|
-
if leap_year? && day_of_year >
|
45
|
+
if leap_year? && day_of_year > 168
|
37
46
|
(day_of_year - 2).divmod(7)
|
38
47
|
else
|
39
48
|
(day_of_year - 1).divmod(7)
|
40
49
|
end
|
41
50
|
end
|
42
51
|
|
43
|
-
#
|
44
|
-
#
|
52
|
+
# This method caches the divmod result of the:
|
53
|
+
# zero based (working number starts with 1) day of the year
|
54
|
+
# where Leap day is removed. By applying the divmod on the
|
55
|
+
# 'cleaner' representation of the day of the year, other parts
|
56
|
+
# of the code become easier to reason about.
|
45
57
|
memoize def day_of_year_divmod_twenty_eight
|
46
|
-
if leap_year? && day_of_year >
|
58
|
+
if leap_year? && day_of_year > 168
|
47
59
|
(day_of_year - 2).divmod(28)
|
48
60
|
else
|
49
61
|
(day_of_year - 1).divmod(28)
|
@@ -60,8 +72,8 @@ class IfcDate
|
|
60
72
|
end
|
61
73
|
|
62
74
|
memoize def week_of_year
|
63
|
-
|
64
|
-
day_of_year_divmod_seven[0] + 1
|
75
|
+
# The min operation if for the year day, which would be 53, but is appended to week 52
|
76
|
+
[day_of_year_divmod_seven[0] + 1, 52].min
|
65
77
|
end
|
66
78
|
alias week week_of_year
|
67
79
|
|
@@ -78,11 +90,10 @@ class IfcDate
|
|
78
90
|
alias mday day_of_month
|
79
91
|
|
80
92
|
# Return the month in index of the year.
|
81
|
-
# NOTE
|
93
|
+
# NOTE January will be 1, so different indexing thant the wday
|
82
94
|
def month_of_year
|
83
|
-
|
84
|
-
|
85
|
-
day_of_year_divmod_twenty_eight[0] + 1
|
95
|
+
# The min operation if for the year day, which would be 14, but is appended to month 13
|
96
|
+
[day_of_year_divmod_twenty_eight[0] + 1, 13].min
|
86
97
|
end
|
87
98
|
alias month month_of_year
|
88
99
|
|
@@ -101,4 +112,9 @@ class IfcDate
|
|
101
112
|
def abbr_month_name
|
102
113
|
ABBR_MONTHNAMES[month_of_year]
|
103
114
|
end
|
115
|
+
|
116
|
+
def inspect
|
117
|
+
"#{year.to_s}-#{month_of_year.to_s.rjust(2, '0')}-#{day_of_month.to_s}"
|
118
|
+
end
|
119
|
+
alias to_s inspect
|
104
120
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ifc_date
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Benjamin ter Kuile
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-07-02 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Ruby implementation of the International Fixed Calendar system. Other
|
14
14
|
name references are Cotsworth and Eastman
|
@@ -28,6 +28,7 @@ files:
|
|
28
28
|
- lib/ifc_date.rb
|
29
29
|
- lib/ifc_date/class_methods.rb
|
30
30
|
- lib/ifc_date/ext/to_ifc.rb
|
31
|
+
- lib/ifc_date/instance_methods.rb
|
31
32
|
- lib/ifc_date/version.rb
|
32
33
|
- sig/ifc_date.rbs
|
33
34
|
homepage: https://gitlab.com/benja-2/ifc_date
|