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

Implemented subdivisions for US & DE #16

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

AD4MANTIS
Copy link
Contributor

#9
I implemented subdivisions as their own 'Country' value.
Currently I only implemented the subdivisions for US and DE.

I also refactored the code a bit in the process.

I used this command to generate the code:
python3 gen.py; rustfmt src/**/*.rs

TODO

  • Should we add crate features for each subdivision, a single feature to enable subdivisions, ...?

Copy link
Member

@yukinarit yukinarit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the work!

however, I am concern about the increase of compile time. Is it possible to have only region-specific public holidays in the source code (e.g. us_ca.rs), and merge them (e.g. us + us_ca) at runtime? 🤔

return;
}

let m = national_holidays
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if it is possible to have a national and a subdivision holiday on the same day, but they could be merged into one with this code instead:

    let mut m = national_holidays.remove(&year).unwrap_or_default();

    for (date, name) in subdivision_holidays {
        let national_holiday_name = m.remove(&date).map(|h| h.name + ", ").unwrap_or_default();

        m.insert(
            date,
            Holiday::new(country, national_holiday_name + county_name, date, name),
        );
    }

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this approach is still using big memory size.

Your approach is merge national holiday + subidivsion holiday at "build" time. My suggestion is to do the merge at runtime, i.e. "get", "iter" or "contains". Could you consider this approach?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry it took so long. Let me know if you are happy with my implementation

@AD4MANTIS
Copy link
Contributor Author

Thanks for the work!

however, I am concern about the increase of compile time. Is it possible to have only region-specific public holidays in the source code (e.g. us_ca.rs), and merge them (e.g. us + us_ca) at runtime? 🤔

I wasn't sure how to implement this at first, but the code works out pretty well.
I've added a new function build_subdivision_year that takes a subdivision_holidays iterator and builds a map of holidays for a specific subdivision on top of the national holidays map.

return;
}

let m = national_holidays
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this approach is still using big memory size.

Your approach is merge national holiday + subidivsion holiday at "build" time. My suggestion is to do the merge at runtime, i.e. "get", "iter" or "contains". Could you consider this approach?


let mut national_holidays = de::build(years)?;

build_year(years, 2000, [], &mut map, COUNTY_CODE, COUNTY_NAME);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this because of no regional public holidays in the year 2000?

@yukinarit yukinarit linked an issue Aug 2, 2024 that may be closed by this pull request
pub fn build(years: Option<&std::ops::Range<Year>>) -> Result<HolidayPerYearMap> {
let mut map = HashMap::new();

let mut national_holidays = de::build(years)?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where is this used?

);

Ok(())
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a test case where hholidays retrieved from subdivision contains all national holidays?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support subdivisions
3 participants