Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add calendars for Iceland, India, Indonesia #176

Merged
merged 4 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/time/calendars/denmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl Calendar for Denmark {
}

/// Denmark holidays:
/// - Maunday Thursday
/// - Maundy Thursday
/// - Good Friday
/// - Easter Monday
/// - General Prayer Day
Expand Down
4 changes: 2 additions & 2 deletions src/time/calendars/hungary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ mod test_hungary {
let labour_day = datetime!(2024-05-01 12:00:00 UTC);
let national_holiday = datetime!(2024-08-20 12:00:00 UTC);
let revolution_1956_day = datetime!(2024-10-23 12:00:00 UTC);
let christmas = datetime!(2023-12-25 12:00:00 UTC);
let second_christmas_day = datetime!(2023-12-26 12:00:00 UTC);
let christmas = datetime!(2024-12-25 12:00:00 UTC);
let second_christmas_day = datetime!(2024-12-26 12:00:00 UTC);

assert!(!calendar.is_business_day(new_years_day));
assert!(!calendar.is_business_day(revolution_1848_day));
Expand Down
107 changes: 101 additions & 6 deletions src/time/calendars/iceland.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,56 @@
use crate::time::Calendar;
use time::{Month, OffsetDateTime, Weekday};

/// Czech Republic calendar.
pub struct CzechRepublic;
/// Iceland calendar.
pub struct Iceland;

impl Calendar for CzechRepublic {
impl Calendar for Iceland {
fn name(&self) -> &'static str {
""
"Iceland"
}

fn country_code(&self) -> crate::iso::ISO_3166 {
crate::iso::ICELAND
}

fn market_identifier_code(&self) -> crate::iso::ISO_10383 {
crate::iso::XICE
}

fn is_business_day(&self, date: OffsetDateTime) -> bool {
let (w, d, m, y, dd) = self.unpack_date(date);
let em = Self::easter_monday(y as usize, false);

if Self::is_weekend(date) {
if Self::is_weekend(date)
// New Year's Day
|| (d == 1 && m == Month::January)
// Maundy Thursday
|| (dd == em - 4)
// Good Friday
|| (dd == em - 3)
// Easter Monday
|| (dd == em)
// First Day of Summer (first Thursday after 18th of April)
|| (w == Weekday::Thursday && (19..=25).contains(&d) && m == Month::April)
// Labor Day
|| (d == 1 && m == Month::May)
// Ascension Day
|| (dd == em + 38)
// Whit Monday
|| (dd == em + 49)
// Icelandic Republic Day
|| (d == 17 && m == Month::June)
// Commerce Day (first Monday of August)
|| (d <= 7 && w == Weekday::Monday && m == Month::August)
// Christmas Eve
|| (d == 24 && m == Month::December)
// Christmas
|| (d == 25 && m == Month::December)
// Boxing Day
|| (d == 26 && m == Month::December)
// New Year's Eve
|| (d == 31 && m == Month::December)
{
return false;
}

Expand All @@ -35,4 +72,62 @@ impl Calendar for CzechRepublic {
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

#[cfg(test)]
mod tests {}
mod test_iceland {
use super::*;
use time::macros::datetime;

// Test to verify the name() method.
#[test]
fn test_name() {
let calendar = Iceland;
assert_eq!(calendar.name(), "Iceland");
}

// Test to verify if weekends are not considered business days.
#[test]
fn test_is_weekend() {
let calendar = Iceland;
let sat = datetime!(2024-01-13 12:00:00 UTC);
let sun = datetime!(2024-01-14 12:00:00 UTC);
assert!(!calendar.is_business_day(sat));
assert!(!calendar.is_business_day(sun));
}

// Test to verify if the is_business_day() method properly accounts for public holidays.
#[test]
fn test_is_public_holiday() {
let calendar = Iceland;
let new_years_day = datetime!(2024-01-01 12:00:00 UTC);
let maudy_thursday = datetime!(2024-03-28 12:00:00 UTC);
let first_day_of_summer = datetime!(2024-04-25 12:00:00 UTC);
let labour_day = datetime!(2024-05-01 12:00:00 UTC);
let ascension_day = datetime!(2024-05-09 12:00:00 UTC);
let independence_day = datetime!(2024-06-17 12:00:00 UTC);
let commerce_day = datetime!(2024-08-05 12:00:00 UTC);
let christmas = datetime!(2024-12-25 12:00:00 UTC);
let new_years_eve = datetime!(2024-12-31 12:00:00 UTC);

assert!(!calendar.is_business_day(new_years_day));
assert!(!calendar.is_business_day(maudy_thursday));
assert!(!calendar.is_business_day(first_day_of_summer));
assert!(!calendar.is_business_day(labour_day));
assert!(!calendar.is_business_day(ascension_day));
assert!(!calendar.is_business_day(independence_day));
assert!(!calendar.is_business_day(commerce_day));
assert!(!calendar.is_business_day(christmas));
assert!(!calendar.is_business_day(new_years_eve));
}

// Test to verify if the is_business_day() method properly accounts for regular business days.
#[test]
fn test_is_regular_business_day() {
let calendar = Iceland;
let regular_day1 = datetime!(2024-01-17 12:00:00 UTC);
let regular_day2 = datetime!(2024-07-08 12:00:00 UTC);
let regular_day3 = datetime!(2024-11-18 12:00:00 UTC);

assert!(calendar.is_business_day(regular_day1));
assert!(calendar.is_business_day(regular_day2));
assert!(calendar.is_business_day(regular_day3));
}
}
Loading
Loading