R/after-mday-in-month.R
, R/before-mday-in-month.R
, R/between-mday-in-month.R
event-mday-in-month.Rd
before_mday_in_month()
: Is the date before the day of the month mday
in month month
?
after_mday_in_month()
: Is the date after the day of the month mday
in month month
?
between_mdays_in_months()
: Is the date between the day of the month
x_mday
in month x_month
and y_mday
in month y_month
?
These functions are convenient helpers for defining events such as "before January 24th". They are constructed from lower level event creators, but are common enough to stand alone.
after_mday_in_month(month, mday, inclusive = FALSE) before_mday_in_month(month, mday, inclusive = FALSE) between_mdays_in_months(x_month, x_mday, y_month, y_mday)
month, x_month, y_month |
A month of the year. Combined with |
---|---|
mday, x_mday, y_mday |
A day of the month. |
inclusive |
Should the date defined by |
# Any day before Feb 25th before_feb_25 <- before_mday_in_month("Feb", 25) event_in("2019-01-01", before_feb_25)#> [1] TRUE#> [1] TRUE# You might think that you could construct this helper # from these two lower level event helpers bad_before_feb_25 <- before_mday(25) & before_month("Feb") # But the logic isn't right! It works when both conditions are true, # but Jan-26 is before Feb-25, but registers as a non-event with this logic # because 26 > 25. event_in("2019-01-01", bad_before_feb_25)#> [1] TRUE#> [1] FALSE# The actual condition is more like: strictly_before_feb <- before_month("Feb", inclusive = FALSE) in_feb_and_before_25th <- on_month("Feb") & before_mday(25) good_before_feb_25 <- strictly_before_feb | in_feb_and_before_25th event_in("2019-01-01", good_before_feb_25)#> [1] TRUE#> [1] TRUE# This pattern can be used to construct other similar helpers that # we have chosen not to export, but still might be useful. For example: # "After the 15th day in the 2nd quarter" strictly_after_q2 <- after_quarter(2, inclusive = FALSE) in_q2_and_after_15th_qday <- on_quarter(2) & after_qday(15) after_15th_day_in_q2 <- strictly_after_q2 | in_q2_and_after_15th_qday event_in(as.Date("2019-04-01") + days(14), after_15th_day_in_q2)#> [1] FALSE#> [1] TRUE