checkoff 0.151.0 → 0.152.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/Gemfile.lock +1 -1
- data/lib/checkoff/timing.rb +25 -0
- data/lib/checkoff/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: 84672143c6f2b9e08cd8be54cd4cf20d0bce2f56e72e9f2c98a7db3b48b690a3
|
4
|
+
data.tar.gz: 9e4cb2b6e73615e510cc169797d17f3d5552f5abb89be6a329b370219c79f647
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f2b491d76c73456868a98511e2653842480cad9505fa844bdccfc75e71263305c1c68d7b5a178762fbfb25fedd55861249670e0ac273ccd1605cb47f6db78b36
|
7
|
+
data.tar.gz: e7acaa05c794fcf15e346eb95fb881fafa1f295e685687ec0425bc00561dc5c5d8d0eb9ebfad2c957af01d6ed387171c83f9f4c508e180d1e46ac2609e2ce2cc
|
data/Gemfile.lock
CHANGED
data/lib/checkoff/timing.rb
CHANGED
@@ -40,6 +40,9 @@ module Checkoff
|
|
40
40
|
def in_period?(date_or_time, period)
|
41
41
|
return this_week?(date_or_time) if period == :this_week
|
42
42
|
|
43
|
+
return day_of_week?(date_or_time, period) if %i[monday tuesday wednesday thursday friday saturday
|
44
|
+
sunday].include?(period)
|
45
|
+
|
43
46
|
return true if period == :indefinite
|
44
47
|
|
45
48
|
return now_or_before?(date_or_time) if period == :now_or_before
|
@@ -117,6 +120,28 @@ module Checkoff
|
|
117
120
|
date >= beginning_of_week && date <= end_of_week
|
118
121
|
end
|
119
122
|
|
123
|
+
# @type [Hash<Symbol,Integer>]
|
124
|
+
WDAY_FROM_DAY_OF_WEEK = {
|
125
|
+
monday: 1,
|
126
|
+
tuesday: 2,
|
127
|
+
wednesday: 3,
|
128
|
+
thursday: 4,
|
129
|
+
friday: 5,
|
130
|
+
saturday: 6,
|
131
|
+
sunday: 0,
|
132
|
+
}.freeze
|
133
|
+
|
134
|
+
# @param date_or_time [Date,Time,nil]
|
135
|
+
# @param day_of_week [Symbol]
|
136
|
+
def day_of_week?(date_or_time, day_of_week)
|
137
|
+
return false if date_or_time.nil?
|
138
|
+
|
139
|
+
wday = WDAY_FROM_DAY_OF_WEEK.fetch(day_of_week)
|
140
|
+
today = @today_getter.today
|
141
|
+
date = date_or_time.to_date
|
142
|
+
date_or_time.wday == wday && date >= today && date < today + 7
|
143
|
+
end
|
144
|
+
|
120
145
|
# @param date_or_time [Date,Time,nil]
|
121
146
|
def now_or_before?(date_or_time)
|
122
147
|
return true if date_or_time.nil?
|
data/lib/checkoff/version.rb
CHANGED