-
Notifications
You must be signed in to change notification settings - Fork 467
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
Working days #1927
Comments
Yes, we have such methods, although they are not yet described in documentation. Here is an example: >>> from holidays.countries.united_states import US
>>> us_holidays = US(years=2024)
>>> us_holidays.is_workday("2024-01-01") # Monday, New Year's Day
False
>>> us_holidays.is_workday("2024-01-02") # Tuesday, ordinary day
True
>>> us_holidays.is_workday("2024-01-06") # Saturday, ordinary day
False
>>> us_holidays.is_workday("2024-01-15") # Monday, Martin Luther King Jr. Day
False
>>> us_holidays.get_nth_workday("2024-07-01", 5) # 5th workday after July, 1 (2, 3, 5, 8, 9 - working days, 4, 6, 7 - non-working days)
datetime.date(2024, 7, 9)
>>> us_holidays.get_nth_workday("2024-05-01", -5) # 5th workday before May, 1
datetime.date(2024, 4, 24)
>>> us_holidays.get_workdays_number("2024-04-01", "2024-06-30") # Number of working days in Q2
62 |
@KJhellico But are those holidays overlapping or non-overlapping with the weekend days? The point is that when the 1st of January falls on a Sunday, it is not a true holiday, and it is only considered a holiday if it falls between Monday and Friday. |
Sorry, I don't quite understand your question. |
@KJhellico This is probably a very silly question, but do you count holiday days when they fall on weekend days twice? For example, if January 1st falls on a Sunday, do you have 22 or 21 working days in that month? It is more about the non-overlapping weekend days with the holiday days question. |
It all depends on whether the country has rules for postponing holidays that fall on weekends ("observed" holidays). >>> import holidays
>>> zw_holidays = holidays.country_holidays("ZW", years=2023)
>>> # Zimbabwe has observed holidays rule, 2023-01-01 is Sunday, then 2023-01-02 is non-working day
>>> zw_holidays.get_workdays_number("2023-01-01", "2023-01-31")
21
>>> fr_holidays = holidays.country_holidays("FR", years=2023)
>>> # France has no observed holidays rule, so 2023-01-02 is usual working day
>>> fr_holidays.get_workdays_number("2023-01-01", "2023-01-31")
22 |
you can use param called
Example:
>>> import holidays
>>> print("\n".join(f"{date} - {name}" for date, name in holidays.country_holidays(country="HK", years=[2021, 2022], observed=False).items()))
2021-01-01 - The first day of January
2021-02-12 - Lunar New Year's Day
2021-02-13 - The second day of Lunar New Year
2021-02-14 - The third day of Lunar New Year
2021-04-04 - Ching Ming Festival
2021-04-02 - Good Friday
2021-04-03 - The day following Good Friday
2021-04-05 - Easter Monday
2021-05-19 - The Birthday of the Buddha
2021-05-01 - Labour Day
2021-06-14 - Tuen Ng Festival
2021-07-01 - Hong Kong Special Administrative Region Establishment Day
2021-09-22 - Chinese Mid-Autumn Festival
2021-10-14 - Chung Yeung Festival
2021-10-01 - National Day
2021-12-25 - Christmas Day
2021-12-26 - The first weekday after Christmas Day
2022-01-01 - The first day of January
2022-02-01 - Lunar New Year's Day
2022-02-02 - The second day of Lunar New Year
2022-02-03 - The third day of Lunar New Year
2022-04-05 - Ching Ming Festival
2022-04-15 - Good Friday
2022-04-16 - The day following Good Friday
2022-04-18 - Easter Monday
2022-05-08 - The Birthday of the Buddha
2022-05-01 - Labour Day
2022-06-03 - Tuen Ng Festival
2022-07-01 - Hong Kong Special Administrative Region Establishment Day
2022-09-11 - Chinese Mid-Autumn Festival
2022-10-04 - Chung Yeung Festival
2022-10-01 - National Day
2022-12-25 - Christmas Day
2022-12-26 - The first weekday after Christmas Day |
Is there a straightforward way to calculate working days for different countries using information about weekend days and holidays? Is there a method to do it?
The text was updated successfully, but these errors were encountered: