From 20ccc7ff6ee4e5a1524bf509ca58e88f37be5f7f Mon Sep 17 00:00:00 2001 From: raphasampaio Date: Mon, 11 Nov 2024 11:33:23 -0300 Subject: [PATCH 1/2] Project updates --- README.md | 2 ++ src/calendar.jl | 6 ++-- src/calendars/christian.jl | 64 +++++++++++++++++----------------- src/calendars/gregorian.jl | 2 +- src/calendars/international.jl | 4 +-- src/calendars/islamic.jl | 10 +++--- src/countries/united_states.jl | 20 +++++------ src/holiday.jl | 4 +-- 8 files changed, 57 insertions(+), 55 deletions(-) diff --git a/README.md b/README.md index b9af011..ef232cc 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,7 @@ julia> ] add Holidays ```julia using Holidays +using Dates usa_holidays = Holidays.UnitedStates() @@ -45,6 +46,7 @@ usa_holidays = Holidays.UnitedStates() ```julia using Holidays +using Dates # check if april 23rd is a holiday in brazil brazil_holidays = Holidays.Brazil() diff --git a/src/calendar.jl b/src/calendar.jl index 28bc52c..a85cd93 100644 --- a/src/calendar.jl +++ b/src/calendar.jl @@ -4,7 +4,7 @@ function fetch_holidays(::Type{AbstractHolidayCalendar})::Vector{Holiday} return Vector{Holiday}() end -function find_holidays(calendar::AbstractHolidayCalendar, date::Date)::Vector{Holiday} +function find_holidays(calendar::AbstractHolidayCalendar, date::TimeType)::Vector{Holiday} found = Vector{Holiday}() for holiday in calendar.holidays @@ -33,10 +33,10 @@ function find_holidays(calendar::AbstractHolidayCalendar; years::AbstractVector{ return holidays end -function is_holiday(calendar::AbstractHolidayCalendar, date::Date)::Bool +function is_holiday(calendar::AbstractHolidayCalendar, date::TimeType)::Bool return length(find_holidays(calendar, date)) > 0 end -function Base.in(date::Date, calendar::AbstractHolidayCalendar)::Bool +function Base.in(date::TimeType, calendar::AbstractHolidayCalendar)::Bool return is_holiday(calendar, date) end diff --git a/src/calendars/christian.jl b/src/calendars/christian.jl index e46561e..e8b8944 100644 --- a/src/calendars/christian.jl +++ b/src/calendars/christian.jl @@ -2,28 +2,28 @@ module Christian using Dates -is_shrove_sunday(x::Date) = x == shrove_sunday(Dates.year(x)) -function shrove_sunday(year::Integer)::Date +is_shrove_sunday(x::TimeType) = x == shrove_sunday(Dates.year(x)) +function shrove_sunday(year::Integer) return easter(year) - Dates.Day(49) end -is_shrove_monday(x::Date) = x == shrove_monday(Dates.year(x)) -function shrove_monday(year::Integer)::Date +is_shrove_monday(x::TimeType) = x == shrove_monday(Dates.year(x)) +function shrove_monday(year::Integer) return easter(year) - Dates.Day(48) end -is_shrove_tuesday(x::Date) = x == shrove_tuesday(Dates.year(x)) -function shrove_tuesday(year::Integer)::Date +is_shrove_tuesday(x::TimeType) = x == shrove_tuesday(Dates.year(x)) +function shrove_tuesday(year::Integer) return easter(year) - Dates.Day(47) end -is_ash_wednesday(x::Date) = x == ash_wednesday(Dates.year(x)) -function ash_wednesday(year::Integer)::Date +is_ash_wednesday(x::TimeType) = x == ash_wednesday(Dates.year(x)) +function ash_wednesday(year::Integer) return easter(year) - Dates.Day(46) end -is_easter(x::Date) = x == easter(Dates.year(x)) -function easter(year::Integer)::Date +is_easter(x::TimeType) = x == easter(Dates.year(x)) +function easter(year::Integer) g = year % 19 c = div(year, 100) h = (c - div(c, 4) - div(8 * c + 13, 25) + 19 * g + 15) % 30 @@ -36,48 +36,48 @@ function easter(year::Integer)::Date return Date(year, month, day) end -is_good_friday(x::Date) = x == good_friday(Dates.year(x)) -function good_friday(year::Integer)::Date +is_good_friday(x::TimeType) = x == good_friday(Dates.year(x)) +function good_friday(year::Integer) return easter(year) - Dates.Day(2) end -is_easter_monday(x::Date) = x == easter_monday(Dates.year(x)) -function easter_monday(year::Integer)::Date +is_easter_monday(x::TimeType) = x == easter_monday(Dates.year(x)) +function easter_monday(year::Integer) return easter(year) + Dates.Day(1) end -is_chorus_christi(x::Date) = x == chorus_christi(Dates.year(x)) -function chorus_christi(year::Integer)::Date +is_chorus_christi(x::TimeType) = x == chorus_christi(Dates.year(x)) +function chorus_christi(year::Integer) return easter(year) + Dates.Day(60) end -is_ascension_day(x::Date) = x == ascension_day(Dates.year(x)) -function ascension_day(year::Integer)::Date +is_ascension_day(x::TimeType) = x == ascension_day(Dates.year(x)) +function ascension_day(year::Integer) return easter(year) + Dates.Day(39) end -is_whit_monday(x::Date) = x == whit_monday(Dates.year(x)) -function whit_monday(year::Integer)::Date +is_whit_monday(x::TimeType) = x == whit_monday(Dates.year(x)) +function whit_monday(year::Integer) return easter(year) + Dates.Day(50) end -is_assumption_day(x::Date) = x == assumption_day(Dates.year(x)) -function assumption_day(year::Integer)::Date +is_assumption_day(x::TimeType) = x == assumption_day(Dates.year(x)) +function assumption_day(year::Integer) return Date(year, 8, 15) end -is_all_saints_day(x::Date) = x == all_saints_day(Dates.year(x)) -function all_saints_day(year::Integer)::Date +is_all_saints_day(x::TimeType) = x == all_saints_day(Dates.year(x)) +function all_saints_day(year::Integer) return Date(year, 11, 1) end -is_all_souls_day(x::Date) = x == all_souls_day(Dates.year(x)) -function all_souls_day(year::Integer)::Date +is_all_souls_day(x::TimeType) = x == all_souls_day(Dates.year(x)) +function all_souls_day(year::Integer) return Date(year, 11, 2) end -is_advent_sunday(x::Date) = x == advent_sunday(Dates.year(x)) -function advent_sunday(year::Integer)::Date +is_advent_sunday(x::TimeType) = x == advent_sunday(Dates.year(x)) +function advent_sunday(year::Integer) christmas = christmas_day(year) # find the fourth Sunday before Christmas @@ -88,13 +88,13 @@ function advent_sunday(year::Integer)::Date return first_advent - Dates.Day(day_of_week % 7) end -is_christmas_day(x::Date) = x == christmas_day(Dates.year(x)) -function christmas_day(year::Integer)::Date +is_christmas_day(x::TimeType) = x == christmas_day(Dates.year(x)) +function christmas_day(year::Integer) return Date(year, 12, 25) end -is_boxing_day(x::Date) = x == boxing_day(Dates.year(x)) -function boxing_day(year::Integer)::Date +is_boxing_day(x::TimeType) = x == boxing_day(Dates.year(x)) +function boxing_day(year::Integer) return Date(year, 12, 26) end diff --git a/src/calendars/gregorian.jl b/src/calendars/gregorian.jl index 6de73a7..1fcff41 100644 --- a/src/calendars/gregorian.jl +++ b/src/calendars/gregorian.jl @@ -2,7 +2,7 @@ module Gregorian using Dates -function is_new_years_day(x::Date) +function is_new_years_day(x::TimeType) return Dates.month(x) == 1 && Dates.day(x) == 1 end diff --git a/src/calendars/international.jl b/src/calendars/international.jl index 10ceb01..e0206bf 100644 --- a/src/calendars/international.jl +++ b/src/calendars/international.jl @@ -2,11 +2,11 @@ module International using Dates -function is_womens_day(x::Date) +function is_womens_day(x::TimeType) return Dates.month(x) == Dates.Mar && Dates.day(x) == 8 end -function is_workers_day(x::Date) +function is_workers_day(x::TimeType) return Dates.month(x) == Dates.May && Dates.day(x) == 1 end diff --git a/src/calendars/islamic.jl b/src/calendars/islamic.jl index dbcdf70..d81c1d5 100644 --- a/src/calendars/islamic.jl +++ b/src/calendars/islamic.jl @@ -3707,14 +3707,14 @@ const TASUA_DATES = Set{Date}([ Date(2076, 12, 05), ]) -is_eid_al_fitr_day(x::Date) = x in EID_AL_FITR_DATES +is_eid_al_fitr_day(x::TimeType) = x in EID_AL_FITR_DATES -is_eid_al_fitr_day_two(x::Date) = (x - Day(1)) in EID_AL_FITR_DATES +is_eid_al_fitr_day_two(x::TimeType) = (x - Day(1)) in EID_AL_FITR_DATES -is_eid_al_fitr_day_three(x::Date) = (x - Day(2)) in EID_AL_FITR_DATES +is_eid_al_fitr_day_three(x::TimeType) = (x - Day(2)) in EID_AL_FITR_DATES -is_eid_al_adha_day(x::Date) = x in EID_AL_ADHA_DATES +is_eid_al_adha_day(x::TimeType) = x in EID_AL_ADHA_DATES -is_mawlid(x::Date) = x in MAWLID_DATES +is_mawlid(x::TimeType) = x in MAWLID_DATES end diff --git a/src/countries/united_states.jl b/src/countries/united_states.jl index 2b9e69a..fac8394 100644 --- a/src/countries/united_states.jl +++ b/src/countries/united_states.jl @@ -8,43 +8,43 @@ const Gregorian = Holidays.Gregorian const UnitedStates = Holidays.UnitedStates -function is_new_years_day(x::Date) +function is_new_years_day(x::TimeType) return Dates.year(x) >= 1871 && Gregorian.is_new_years_day(x) end -function is_martin_luther_king_birthday(x::Date) +function is_martin_luther_king_birthday(x::TimeType) return Dates.year(x) >= 1986 && Dates.month(x) == Dates.Jan && Dates.dayofweekofmonth(x) == 3 && Dates.dayofweek(x) == Dates.Mon end -function is_washington_birthday(x::Date) +function is_washington_birthday(x::TimeType) return Dates.year(x) >= 1971 && Dates.month(x) == Dates.Feb && Dates.dayofweekofmonth(x) == 3 && Dates.dayofweek(x) == Dates.Mon end -function is_columbus_day(x::Date) +function is_columbus_day(x::TimeType) return Dates.year(x) >= 1971 && Dates.month(x) == Dates.Oct && Dates.dayofweekofmonth(x) == 2 && Dates.dayofweek(x) == Dates.Mon end -function is_memorial_day(x::Date) +function is_memorial_day(x::TimeType) return Dates.year(x) >= 1971 && Dates.month(x) == Dates.May && Dates.dayofweek(x) == Dates.Mon && Dates.dayofweekofmonth(x) == Dates.daysofweekinmonth(x) end -function is_indenpendence_day(x::Date) +function is_indenpendence_day(x::TimeType) return Dates.year(x) >= 1871 && Dates.month(x) == Dates.Jul && Dates.day(x) == 4 end -function is_labor_day(x::Date) +function is_labor_day(x::TimeType) return Dates.year(x) >= 1894 && Dates.month(x) == Dates.Sep && Dates.dayofweekofmonth(x) == 1 && Dates.dayofweek(x) == Dates.Mon end -function is_thanksgiving_day(x::Date) +function is_thanksgiving_day(x::TimeType) return Dates.year(x) >= 1871 && Dates.month(x) == Dates.Nov && Dates.dayofweekofmonth(x) == 4 && Dates.dayofweek(x) == Dates.Thu end -function is_veterans_day(x::Date) +function is_veterans_day(x::TimeType) return Dates.year(x) >= 1954 && Dates.month(x) == Dates.Nov && Dates.day(x) == 11 end -function is_juneteenth_national_independence_day(x::Date) +function is_juneteenth_national_independence_day(x::TimeType) return Dates.year(x) >= 2021 && Dates.month(x) == Dates.Jun && Dates.day(x) == 19 end diff --git a/src/holiday.jl b/src/holiday.jl index 5820e06..fe2b797 100644 --- a/src/holiday.jl +++ b/src/holiday.jl @@ -3,10 +3,10 @@ struct Holiday handler::Function end -function is_holiday(holiday::Holiday, date::Date) +function is_holiday(holiday::Holiday, date::TimeType) return holiday.handler(date) end -function Base.in(date::Date, holiday::Holiday)::Bool +function Base.in(date::TimeType, holiday::Holiday)::Bool return is_holiday(holiday, date) end From 866e53cbe7c6da25ff2eba43c4b2e18e7cd756d4 Mon Sep 17 00:00:00 2001 From: raphasampaio Date: Mon, 11 Nov 2024 11:33:42 -0300 Subject: [PATCH 2/2] Project updates --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index f58ff78..a2e9376 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "Holidays" uuid = "6a61c59e-0e35-4be2-9181-ca44005fb204" -version = "0.1.2" +version = "0.1.3" [deps] Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"