event-mday-in-month: Events related to a specific day in a month

Description Usage Arguments Examples

Description

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.

Usage

1
2
3
4
5
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)

Arguments

month, x_month, y_month

[integer(1) / character(1)]

A month of the year. Combined with mday, this uniquely defines a specific day of a specific month, such as "January 24".

mday, x_mday, y_mday

[integer(1)]

A day of the month.

inclusive

[logical(1)]

Should the date defined by month and mday count as an event?

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# Any day before Feb 25th
before_feb_25 <- before_mday_in_month("Feb", 25)

event_in("2019-01-01", before_feb_25)
event_in("2019-01-26", before_feb_25)

# 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)
event_in("2019-01-26", bad_before_feb_25)

# 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)
event_in("2019-01-26", good_before_feb_25)

# 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)
event_in(as.Date("2019-04-01") + days(15), after_15th_day_in_q2)

DavisVaughan/almanac3 documentation built on Oct. 30, 2019, 5:59 a.m.