Primitives

RDates is designed to allow complex date operations to be completed using basic primitive types. Each of these primitive types and operations are explained in more detail in subsequent sections.

We now go through each of the primitive types, from which we can combine together using compounding operations. Also take note of the examples and the associated short-hand that we can use to define them with the rd"" macro.

RDates.DayType
Day(days::Int64)

Provides us with the ability to add or subtract days from a date. This is equivalent to the Dates.Day struct.

Examples

julia> RDates.Day(3) + Date(2019,1,1)
2019-01-04
julia> rd"3d" + Date(2019,1,1)
2019-01-04
julia> RDates.Day(-2) + Date(2019,1,1)
2018-12-30
source
RDates.WeekType
Week(weeks::Int64)

Provides us with the ability to add or subtract weeks from a date. This is equivalent to the Dates.Week struct.

Examples

julia> RDates.Week(3) + Date(2019,1,1)
2019-01-22
julia> rd"3w" + Date(2019,1,1)
2019-01-22
julia> RDates.Week(-2) + Date(2019,1,1)
2018-12-18
source
RDates.FDOMType
FDOM()
FDOM(calendars)

Calculate the first day of the month. Optionally can also take calendar names to determine the first business day of the month.

Examples

julia> RDates.FDOM() + Date(2019,1,13)
2019-01-01
julia> rd"FDOM" + Date(2019,1,13)
2019-01-01

julia> cals = SimpleCalendarManager()
julia> setcalendar!(cals, "WEEKEND", WeekendCalendar())
julia> apply(RDates.FDOM("WEEKEND"), Date(2017,1,13), cals)
2017-01-02
julia> apply(rd"FDOM@WEEKEND", Date(2017,1,13), cals)
2017-01-02
source
RDates.LDOMType
LDOM()
LDOM(calendars)

Calculate the last day of the month. Optionally can also take calendar names to determine the last business day of the month.

Examples

julia> RDates.LDOM() + Date(2019,1,13)
2019-01-31
julia> rd"LDOM" + Date(2019,1,13)
2019-01-31
julia> cals = SimpleCalendarManager()
julia> setcalendar!(cals, "WEEKEND", WeekendCalendar())
julia> apply(RDates.LDOM("WEEKEND"), Date(2021,1,13), cals)
2021-01-29
julia> apply(rd"LDOM@WEEKEND", Date(2021,1,13), cals)
2021-01-29
source
RDates.EasterType
Easter(yearδ::Int64)

A date that is well known from hunting eggs and pictures of bunnies, it's a rather tricky calculation to perform. We provide a simple method to allow you to get the Easter for the given year (plus some delta).

Note

0E will get the Easter of the current year, so it could be before or after the date you've provided.

Examples

julia> RDates.Easter(0) + Date(2019,1,1)
2019-04-21
julia> rd"0E" + Date(2019,1,1)
2019-04-21
julia> RDates.Easter(0) + Date(2019,8,1)
2019-04-21
julia> RDates.Easter(10) + Date(2019,8,1)
2029-04-01
source
RDates.DayMonthType
DayMonth(day::Int64, month::Int64)
DayMonth(day::Int64, month::Symbol)

Provides us with the ability to move to a specific day and month in the provided year.

Note

1MAR will get the 1st of March of the current year, so it could be before or after the date you've provided.

Examples

julia> RDates.DayMonth(23, 10) + Date(2019,1,1)
2019-10-23
julia> RDates.DayMonth(23, :OCT) + Date(2019,1,1)
2019-10-23
julia> rd"23OCT" + Date(2019,1,1)
2019-10-23
source
RDates.DateType
Date(date::Dates.Date)
Date(year::Int64, month::Int64, day::Int64)

Provides us with the ability to move to a specific date, irrespective of the date passed in. This is primarily used when you want to provide a pivot point for ranges which doesn't relate to the start or end.

Examples

julia> RDates.Date(Dates.Date(2017,10,23)) + Date(2019,1,1)
2017-10-23
julia> RDates.Date(2017,10,23) + Date(2019,1,1)
2017-10-23
julia> rd"23OCT2017" + Date(2019,1,1)
2017-10-23
source
RDates.NthWeekdaysType
NthWeekdays(dayofweek::Int64, period::Int64)
NthWeekdays(dayofweek::Symbol, period::Int64)

Move to the nth weekday in the given month and year. This is commonly used for holiday calendars, such as Thanksgiving which in the U.S. falls on the 4th Thursday in November.

Note

It's possible that a given period (such as the 5th weekday) may exist for only a subsection of dates. While it's a valid RDate it may not produce valid results when applied (and will throw an exception)

Examples

julia> RDates.NthWeekdays(:MON, 2) + Date(2019,1,1)
2019-01-14
julia> RDates.NthWeekdays(1, 2) + Date(2019,1,1)
2019-01-14
julia> rd"2nd MON" + Date(2019,1,1)
2019-01-14
julia> RDates.NthWeekdays(:MON, 5) + Date(2019,1,1)
ERROR: ArgumentError: Day: 35 out of range (1:31)
source
RDates.NthLastWeekdaysType
NthLastWeekdays(dayofweek::Int64, period::Int64)
NthLastWeekdays(dayofweek::Symbol, period::Int64)

Move to the nth last weekday in the given month and year. This is commonly used for holiday calendars, such as the Spring Bank Holiday in the UK, which is the last Monday in May.

Note

It's possible that a given period (such as the 5th Last weekday) may exist for only a subsection of dates. While it's a valid RDate it may not produce valid results when applied (and will throw an exception)

Examples

julia> RDates.NthLastWeekdays(:MON, 2) + Date(2019,1,1)
2019-01-21
julia> RDates.NthLastWeekdays(1, 2) + Date(2019,1,1)
2019-01-21
julia> rd"2nd Last MON" + Date(2019,1,1)
2019-01-21
julia> RDates.NthLastWeekdays(:MON, 5) + Date(2019,1,1)
ERROR: ArgumentError: Day: 0 out of range (1:31)
source
RDates.WeekdaysType
Weekdays(dayofweek::Int64, count::Int64, inclusive::Bool = false)
Weekdays(dayofweek::Symbol, count::Int64, inclusive::Bool = false)

Provides a mechanism to ask for the next Saturday or the last Tuesday. The count specifies what we're looking for. Weekdays(:MON, 1) will ask for the next Monday, exclusive of the date started from. You can make it inclusive by passing the inclusive parameter with Weekdays(:MON, 1, true).

Note

A count of 0 is not supported as it doesn't specify what you're actually looking for!

Incrementing the count will then be additional weeks (forward or backwards) from the single count point.

Examples

julia> RDates.Weekdays(:WED, 1) + Date(2019,9,24) # Tuesday
2019-09-25
julia> RDates.Weekdays(3, 1) + Date(2019,9,24)
2019-09-25
julia> rd"1WED" + Date(2019,9,24)
2019-09-25
julia> RDates.Weekdays(:WED, 1) + Date(2019,9,25)
2019-10-02
julia> RDates.Weekdays(:WED, 1, true) + Date(2019,9,25)
2019-09-25
julia> rd"1WED!" + Date(2019,9,25)
2019-09-25
julia> RDates.Weekdays(:WED, -1) + Date(2019,9,24)
2019-09-18
source