### Setup virtual environment with mkvirtualenv and pip install Source: https://workalendar.github.io/workalendar/contributing.html Commands to create a virtual environment named WORKALENDAR and install workalendar in editable mode. Run these in your cloned workalendar repository. ```bash mkvirtualenv WORKALENDAR pip install -e ./ ``` -------------------------------- ### Install tox Source: https://workalendar.github.io/workalendar/contributing.html Command to install tox in the WORKALENDAR virtualenv, needed to run the test suite. ```bash workon WORKALENDAR pip install tox ``` -------------------------------- ### Get all calendars with registry.get_calendars() Source: https://workalendar.github.io/workalendar/iso-registry.html Returns a dictionary mapping country codes to calendar classes for all registered countries. The output is truncated in the example with a comment indicating continuation. ```python >>> registry.get_calendars() {'AT': , 'BE': , 'BG': , 'KY': , # ... continued } ``` -------------------------------- ### Get all calendars with subregions using registry.get_calendars(include_subregions=True) Source: https://workalendar.github.io/workalendar/iso-registry.html Returns the full dictionary of all calendars registered in the ISO Registry, including all subregions. ```python >>> registry.get_calendars(include_subregions=True) ``` -------------------------------- ### Get holidays for a given country and year Source: https://workalendar.github.io/workalendar/basic.html Import the France calendar, instantiate it, and call holidays(2012) to get a list of tuples with date and holiday label. The output shows all French holidays for 2012. ```python >>> from workalendar.europe import France >>> cal = France() >>> cal.holidays(2012) [(datetime.date(2012, 1, 1), 'New year'), (datetime.date(2012, 4, 9), 'Easter Monday'), (datetime.date(2012, 5, 1), 'Labour Day'), (datetime.date(2012, 5, 8), 'Victory in Europe Day'), (datetime.date(2012, 5, 17), 'Ascension Day'), (datetime.date(2012, 5, 28), 'Whit Monday'), (datetime.date(2012, 7, 14), 'Bastille Day'), (datetime.date(2012, 8, 15), 'Assumption of Mary to Heaven'), (datetime.date(2012, 11, 1), "All Saints' Day"), (datetime.date(2012, 11, 11), 'Armistice Day'), (datetime.date(2012, 12, 25), 'Christmas')] ``` -------------------------------- ### Find the nth weekday after a start date with Calendar.get_nth_weekday_in_month Source: https://workalendar.github.io/workalendar/advanced.html Use the start argument of Calendar.get_nth_weekday_in_month() to find the nth weekday after a specific date. The example finds the 2nd Monday after July 9, 2018. ```python >>> from datetime import date >>> from workalendar.core import Calendar, MON >>> Calendar.get_nth_weekday_in_month( 2018, # Year 7, # Month MON, # Monday 2, # The 2nd one start=date(2018, 7, 9)) datetime.date(2018, 7, 16) ``` -------------------------------- ### Define a calendar class with flags (Zhraa) Source: https://workalendar.github.io/workalendar/class-options.html Shows a calendar class with include_easter_monday and include_labour_day flags, a fixed holiday, and a variable day. This is the base example before adding optional arguments. ```python @iso_register('ZK') class Zhraa(WesternCalendar): include_easter_monday = True include_labour_day = True FIXED_HOLIDAYS = WesternCalendar.FIXED_HOLIDAYS + ( (8, 2, "King Birthday"), ) def get_variable_days(self, year): # usual variable days days = super().get_variable_days(year) days.append( (Zhraa.get_nth_weekday_in_month(year, 6, MON), 'Day of the Founder'), ) return days ``` -------------------------------- ### Find the first weekday after a date with Calendar.get_first_weekday_after Source: https://workalendar.github.io/workalendar/advanced.html Use Calendar.get_first_weekday_after() to find the first occurrence of a weekday after a given date. The example finds the first Monday after January 6, 2018. ```python >>> from workalendar.core import Calendar, MON >>> from datetime import date >>> jan_6th = date(2018, 1, 6) # It's a Saturday >>> Calendar.get_first_weekday_after(jan_6th, MON) datetime.date(2018, 1, 8) ``` -------------------------------- ### Iterate over the whole registry with registry.get_calendars() Source: https://workalendar.github.io/workalendar/iso-registry.html Use this snippet to retrieve all calendars from the global registry. It returns a dictionary where keys are ISO codes and values are calendar classes. The example prints each code and the calendar's name property, showing sample output for several countries. Note that IsoRegistry.items() has been renamed to get_calendars() as of version 9.0.0. ```python >>> from workalendar.registry import registry >>> calendars = registry.get_calendars() # This returns a dictionary >>> for code, calendar_class in calendars.items(): ... print(f"`{code}` is code for {calendar_class.name!r}") `AT` is code for 'Austria' `BE` is code for 'Belgium' `BG` is code for 'Bulgaria' `HR` is code for 'Croatia' `CY` is code for 'Cyprus' `CZ` is code for 'Czech Republic' `EE` is code for 'Estonia' `DK` is code for 'Denmark' `FI` is code for 'Finland' `FR` is code for 'France' ... continued ``` -------------------------------- ### Filter calendars by country codes with registry.get_calendars(['FR', 'CH', 'CA']) Source: https://workalendar.github.io/workalendar/iso-registry.html Returns a dictionary with only the calendars for the specified country codes. The example shows the output for France, Switzerland, and Canada. ```python >>> registry.get_calendars(['FR', 'CH', 'CA']) {'FR': , 'CH': , 'CA': } ``` -------------------------------- ### Get calendar class by ISO code and compute holidays Source: https://workalendar.github.io/workalendar/iso-registry.html Shows how to use registry.get('CH') to retrieve the Switzerland calendar class, instantiate it, and compute holidays for 2018. The output lists holiday dates and names. Note: returns None if the code is unknown. Deprecation: IsoRegistry.get_calendar_class() renamed to IsoRegistry.get() as of version 10.0.0. ```python >>> CalendarClass = registry.get('CH') >>> calendar = CalendarClass() >>> calendar.holidays(2018) [(datetime.date(2018, 1, 1), 'New year'), (datetime.date(2018, 3, 30), 'Good Friday'), (datetime.date(2018, 4, 1), 'Easter Sunday'), (datetime.date(2018, 4, 2), 'Easter Monday'), (datetime.date(2018, 5, 10), 'Ascension Thursday'), (datetime.date(2018, 5, 20), 'Whit Sunday'), (datetime.date(2018, 5, 21), 'Whit Monday'), (datetime.date(2018, 8, 1), 'National Holiday'), (datetime.date(2018, 12, 25), 'Christmas Day'), (datetime.date(2018, 12, 26), 'Boxing Day')] ``` -------------------------------- ### Know if a day is a holiday or not Source: https://workalendar.github.io/workalendar/basic.html Use is_working_day() to check if a date is a working day. The example shows Christmas (False), a Sunday (False), and a non-holiday weekday (True). ```python >>> from datetime import date >>> from workalendar.europe import France >>> cal = France() >>> cal.is_working_day(date(2012, 12, 25)) # it's Christmas False >>> cal.is_working_day(date(2012, 12, 30)) # it's a Sunday False >>> cal.is_working_day(date(2012, 12, 26)) # No Boxing day in France True ``` -------------------------------- ### Find the following working day after a date with find_following_working_day Source: https://workalendar.github.io/workalendar/advanced.html Use cal.find_following_working_day() to get the next working day after a given date. If the input date is already a working day, it returns that date. Note: this function does not account for holidays; use add_working_days() for that. ```python >>> from datetime import date, datetime >>> from workalendar.europe import France >>> cal = France() >>> cal.find_following_working_day(date(2018, 7, 6)) # It's FRI datetime.date(2018, 7, 6) >>> cal.find_following_working_day(date(2018, 7, 7)) # SAT => next MON datetime.date(2018, 7, 9) ``` -------------------------------- ### Standard date(time) types only, please! Source: https://workalendar.github.io/workalendar/basic.html Workalendar accepts datetime.date and datetime.datetime types. Passing non-standard types raises UnsupportedDateType. The example shows is_working_day and add_working_days with datetime input. ```python >>> from datetime import date, datetime >>> from workalendar.europe import France >>> cal = France() >>> cal.is_working_day(datetime(2012, 12, 25, 14, 0, 39)) False >>> cal.add_working_days(datetime(2012, 12, 23, 14, 0, 39), 5) datetime.date(2012, 12, 31) ``` -------------------------------- ### registry.get_calendars() Source: https://workalendar.github.io/workalendar/iso-registry.html Returns a dictionary mapping region codes to calendar classes. Can be called with no arguments to get all countries, with a list of codes to filter, and with include_subregions=True to include subregions of the specified codes. ```APIDOC ## registry.get_calendars() ### Description Returns a dictionary of calendar classes for the specified region codes. If no codes are provided, returns all countries in the registry. If include_subregions is True, includes subregions for the specified codes. ### Method Python method call ### Signature `registry.get_calendars(codes=None, include_subregions=False)` ### Parameters - **codes** (list of str) - Optional - List of ISO region codes (e.g., 'FR', 'CH', 'CA'). If omitted, returns all countries. - **include_subregions** (bool) - Optional - If True, includes subregions for the specified codes. Default is False. ### Return Value A dictionary mapping region codes (str) to calendar classes (class). ### Examples #### Get all countries ```python >>> registry.get_calendars() {'AT': , 'BE': , 'BG': , 'KY': , # ... continued } ``` #### Filter by specific codes ```python >>> registry.get_calendars(['FR', 'CH', 'CA']) {'FR': , 'CH': , 'CA': } ``` #### Include subregions ```python >>> registry.get_calendars(['FR', 'CH', 'CA'], include_subregions=True) {'FR': workalendar.europe.france.France, 'CH': workalendar.europe.switzerland.Switzerland, 'CH-AG': workalendar.europe.switzerland.Aargau, 'CH-AI': workalendar.europe.switzerland.AppenzellInnerrhoden, 'CH-AR': workalendar.europe.switzerland.AppenzellAusserrhoden, 'CH-BE': workalendar.europe.switzerland.Bern, 'CH-BL': workalendar.europe.switzerland.BaselLandschaft, 'CH-BS': workalendar.europe.switzerland.BaselStadt, 'CH-FR': workalendar.europe.switzerland.Fribourg, 'CH-GE': workalendar.europe.switzerland.Geneva, 'CH-GL': workalendar.europe.switzerland.Glarus, 'CH-GR': workalendar.europe.switzerland.Graubunden, 'CH-JU': workalendar.europe.switzerland.Jura, 'CH-LU': workalendar.europe.switzerland.Luzern, 'CH-NE': workalendar.europe.switzerland.Neuchatel, 'CH-NW': workalendar.europe.switzerland.Nidwalden, 'CH-OW': workalendar.europe.switzerland.Obwalden, 'CH-SG': workalendar.europe.switzerland.StGallen, 'CH-SH': workalendar.europe.switzerland.Schaffhausen, 'CH-SO': workalendar.europe.switzerland.Solothurn, 'CH-SZ': workalendar.europe.switzerland.Schwyz, 'CH-TG': workalendar.europe.switzerland.Thurgau, 'CH-TI': workalendar.europe.switzerland.Ticino, 'CH-UR': workalendar.europe.switzerland.Uri, 'CH-VD': workalendar.europe.switzerland.Vaud, 'CH-VS': workalendar.europe.switzerland.Valais, 'CH-ZG': workalendar.europe.switzerland.Zug, 'CH-ZH': workalendar.europe.switzerland.Zurich, 'CA': workalendar.america.canada.Canada, 'CA-ON': workalendar.america.canada.Ontario, 'CA-QC': workalendar.america.canada.Quebec, 'CA-BC': workalendar.america.canada.BritishColumbia, 'CA-AB': workalendar.america.canada.Alberta, 'CA-SK': workalendar.america.canada.Saskatchewan, 'CA-MB': workalendar.america.canada.Manitoba, 'CA-NB': workalendar.america.canada.NewBrunswick, 'CA-NS': workalendar.america.canada.NovaScotia, 'CA-PE': workalendar.america.canada.PrinceEdwardIsland, 'CA-NL': workalendar.america.canada.Newfoundland, 'CA-YT': workalendar.america.canada.Yukon, 'CA-NT': workalendar.america.canada.NorthwestTerritories, 'CA-NU': workalendar.america.canada.Nunavut} ``` #### Get all calendars with subregions ```python >>> registry.get_calendars(include_subregions=True) ``` ### Notes - If any of the codes is unknown, this function won’t raise an error. ``` -------------------------------- ### Compute the nth working day after a given date Source: https://workalendar.github.io/workalendar/basic.html Use add_working_days() to add a number of working days to a date. The example adds 5 working days to December 23, 2012, resulting in December 31, 2012, skipping weekends and Christmas. ```python >>> from datetime import date >>> from workalendar.europe import France >>> cal = France() >>> cal.add_working_days(date(2012, 12, 23), 5) datetime.date(2012, 12, 31) ``` -------------------------------- ### Find the nth weekday in a month with Calendar.get_nth_weekday_in_month Source: https://workalendar.github.io/workalendar/advanced.html Use Calendar.get_nth_weekday_in_month() to find the nth occurrence of a weekday in a given month. By default it finds the first occurrence. The example shows finding the 4th Thursday (Thanksgiving) in November 2018. ```python >>> from workalendar.core import Calendar, THU >>> Calendar.get_nth_weekday_in_month(2018, 11, THU) # by default, find the first datetime.date(2018, 11, 2) >>> Calendar.get_nth_weekday_in_month(2018, 11, THU, 4) # Thanksgiving datetime.date(2018, 11, 23) ``` -------------------------------- ### Get sub-regions for Australia using registry.get_subregions('AU') Source: https://workalendar.github.io/workalendar/iso-registry.html Shows how to retrieve sub-regions (states/territories) for a country code using registry.get_subregions('AU'). Returns a dict mapping ISO codes to calendar classes. Note: returns an empty dict if the code is unknown. ```python >>> registry.get_subregions('AU') {'AU-ACT': , 'AU-NSW': , 'AU-NT': , 'AU-QLD': , 'AU-SA': , 'AU-TAS': , 'AU-VIC': , 'AU-WA': } ``` -------------------------------- ### Find the last weekday in a month with Calendar.get_last_weekday_in_month Source: https://workalendar.github.io/workalendar/advanced.html Use Calendar.get_last_weekday_in_month() to find the last occurrence of a weekday in a given month. The example shows finding the last Monday and last Friday in July 2018. ```python >>> from workalendar.core import Calendar, MON, FRI >>> Calendar.get_last_weekday_in_month(2018, 7, MON) datetime.date(2018, 7, 30) >>> Calendar.get_last_weekday_in_month(2018, 7, FRI) datetime.date(2018, 7, 27) ``` -------------------------------- ### Calculate the number of working days between two given days Source: https://workalendar.github.io/workalendar/basic.html Use get_working_days_delta() to count working days between two dates. The example returns 50 for April 2 to June 17, 2018 in France. ```python >>> from datetime import date >>> from workalendar.europe import France >>> cal = France() >>> cal.get_working_days_delta(date(2018, 4, 2), date(2018, 6, 17)) 50 ``` -------------------------------- ### Instantiate Zhraa with include_january_2nd option Source: https://workalendar.github.io/workalendar/class-options.html Shows how to use the optional argument in business logic, conditionally setting include_january_2nd based on year and employee context, then creating a Zhraa calendar instance. ```python include_january_2nd = year == 2019 \ and (employee_name == "Bob" or employee_location == "North") calendar = Zhraa(include_january_2nd=include_january_2nd) ``` -------------------------------- ### Define a calendar class with optional argument (Zhraa with include_january_2nd) Source: https://workalendar.github.io/workalendar/class-options.html Shows a modified Zhraa class that accepts an optional include_january_2nd argument in __init__, and conditionally adds January 2nd as a holiday in get_variable_days. ```python @iso_register('ZK') class Zhraa(WesternCalendar): include_easter_monday = True include_labour_day = True FIXED_HOLIDAYS = WesternCalendar.FIXED_HOLIDAYS + ( (8, 2, "King Birthday"), ) def __init__(self, include_january_2nd=False, **kwargs): super().__init__(**kwargs) self.include_january_2nd = include_january_2nd def get_variable_days(self, year): # usual variable days days = super().get_variable_days(year) days.append( (Zhraa.get_nth_weekday_in_month(year, 6, MON), 'Day of the Founder'), ) if self.include_january_2nd: days.append( (date(year, 1, 2), "January 2nd") ) return days ``` -------------------------------- ### Register Zhraa with ISO code Source: https://workalendar.github.io/workalendar/contributing.html Decorates the class with @iso_register('ZK') to add it to the global registry, enabling lookup by ISO code. ```python from ..registry_tools import iso_register @iso_register('ZK') class Zhraa(WesternCalendar): # The rest of your code... ``` -------------------------------- ### Register Zhraa in europe package exports Source: https://workalendar.github.io/workalendar/contributing.html Adds the new calendar to workalendar/europe/__init__.py so it is exported from the package. ```python from .zhraa import Zhraa # ... __all__ = ( 'Belgium', 'CzechRepublic', # ... 'Zhraa', ) ``` -------------------------------- ### IsoRegistry.get() Source: https://workalendar.github.io/workalendar/iso-registry.html Retrieves a single calendar class from the registry using its ISO code. Returns None if the code is unknown. ```APIDOC ## IsoRegistry.get() ### Description Retrieves a single calendar class from the registry using its ISO code. Returns None if the code is unknown. ### Method `get` ### Parameters - **iso_code** (string) - Required - The ISO code of the country or region (e.g., 'CH' for Switzerland). ### Returns - **CalendarClass** (class) - The calendar class corresponding to the ISO code, or `None` if not found. ### Example ```python >>> CalendarClass = registry.get('CH') >>> calendar = CalendarClass() >>> calendar.holidays(2018) [(datetime.date(2018, 1, 1), 'New year'), (datetime.date(2018, 3, 30), 'Good Friday'), (datetime.date(2018, 4, 1), 'Easter Sunday'), (datetime.date(2018, 4, 2), 'Easter Monday'), (datetime.date(2018, 5, 10), 'Ascension Thursday'), (datetime.date(2018, 5, 20), 'Whit Sunday'), (datetime.date(2018, 5, 21), 'Whit Monday'), (datetime.date(2018, 8, 1), 'National Holiday'), (datetime.date(2018, 12, 25), 'Christmas Day'), (datetime.date(2018, 12, 26), 'Boxing Day')] ``` ### Notes - As of version 10.0.0, `IsoRegistry.get_calendar_class()` has been renamed to `IsoRegistry.get()`. ``` -------------------------------- ### Create Zhraa calendar class Source: https://workalendar.github.io/workalendar/contributing.html Initial skeleton for a new calendar class in workalendar/europe/zhraa.py. The docstring becomes the human-readable name; without it, the class name is used. ```python from ..core import WesternCalendar # NOTE: You may use absolute imports if your code lives outside of our codebase. class Zhraa(WesternCalendar): "Kingdom of Zhraa" ``` -------------------------------- ### Include subregions with registry.get_calendars(['FR', 'CH', 'CA'], include_subregions=True) Source: https://workalendar.github.io/workalendar/iso-registry.html Returns a dictionary with the specified countries and their subregions. The output shows all Swiss cantons and Canadian provinces/territories. Unknown codes do not raise an error. ```python >>> registry.get_calendars(['FR', 'CH', 'CA'], include_subregions=True) {'FR': workalendar.europe.france.France, 'CH': workalendar.europe.switzerland.Switzerland, 'CH-AG': workalendar.europe.switzerland.Aargau, 'CH-AI': workalendar.europe.switzerland.AppenzellInnerrhoden, 'CH-AR': workalendar.europe.switzerland.AppenzellAusserrhoden, 'CH-BE': workalendar.europe.switzerland.Bern, 'CH-BL': workalendar.europe.switzerland.BaselLandschaft, 'CH-BS': workalendar.europe.switzerland.BaselStadt, 'CH-FR': workalendar.europe.switzerland.Fribourg, 'CH-GE': workalendar.europe.switzerland.Geneva, 'CH-GL': workalendar.europe.switzerland.Glarus, 'CH-GR': workalendar.europe.switzerland.Graubunden, 'CH-JU': workalendar.europe.switzerland.Jura, 'CH-LU': workalendar.europe.switzerland.Luzern, 'CH-NE': workalendar.europe.switzerland.Neuchatel, 'CH-NW': workalendar.europe.switzerland.Nidwalden, 'CH-OW': workalendar.europe.switzerland.Obwalden, 'CH-SG': workalendar.europe.switzerland.StGallen, 'CH-SH': workalendar.europe.switzerland.Schaffhausen, 'CH-SO': workalendar.europe.switzerland.Solothurn, 'CH-SZ': workalendar.europe.switzerland.Schwyz, 'CH-TG': workalendar.europe.switzerland.Thurgau, 'CH-TI': workalendar.europe.switzerland.Ticino, 'CH-UR': workalendar.europe.switzerland.Uri, 'CH-VD': workalendar.europe.switzerland.Vaud, 'CH-VS': workalendar.europe.switzerland.Valais, 'CH-ZG': workalendar.europe.switzerland.Zug, 'CH-ZH': workalendar.europe.switzerland.Zurich, 'CA': workalendar.america.canada.Canada, 'CA-ON': workalendar.america.canada.Ontario, 'CA-QC': workalendar.america.canada.Quebec, 'CA-BC': workalendar.america.canada.BritishColumbia, 'CA-AB': workalendar.america.canada.Alberta, 'CA-SK': workalendar.america.canada.Saskatchewan, 'CA-MB': workalendar.america.canada.Manitoba, 'CA-NB': workalendar.america.canada.NewBrunswick, 'CA-NS': workalendar.america.canada.NovaScotia, 'CA-PE': workalendar.america.canada.PrinceEdwardIsland, 'CA-NL': workalendar.america.canada.Newfoundland, 'CA-YT': workalendar.america.canada.Yukon, 'CA-NT': workalendar.america.canada.NorthwestTerritories, 'CA-NU': workalendar.america.canada.Nunavut} ``` -------------------------------- ### Write Zhraa test class Source: https://workalendar.github.io/workalendar/contributing.html Test class for the new calendar, checking fixed and variable holidays for 2014. Running it with tox or py.test will fail until the calendar is implemented. ```python from ..europe import Zhraa # snip... class ZhraaTest(GenericCalendarTest): cal_class = Zhraa def test_year_2014(self): holidays = self.cal.holidays_set(2014) self.assertIn(date(2014, 1, 1), holidays) # new year self.assertIn(date(2014, 5, 1), holidays) # labour day self.assertIn(date(2014, 8, 2), holidays) # king birthday self.assertIn(date(2014, 12, 25), holidays) # Xmas # variable days self.assertIn(date(2014, 4, 21), holidays) # easter monday self.assertIn(date(2014, 6, 2), holidays) # First MON in June ``` -------------------------------- ### IsoRegistry.get_subregions() Source: https://workalendar.github.io/workalendar/iso-registry.html Returns a dictionary of sub-region calendar classes for a given country ISO code. Returns an empty dictionary if the code is unknown. ```APIDOC ## IsoRegistry.get_subregions() ### Description Returns a dictionary of sub-region calendar classes for a given country ISO code. Returns an empty dictionary if the code is unknown. ### Method `get_subregions` ### Parameters - **iso_code** (string) - Required - The ISO code of the country (e.g., 'AU' for Australia). ### Returns - **dict** - A dictionary mapping sub-region ISO codes (e.g., 'AU-ACT') to calendar classes. ### Example ```python >>> registry.get_subregions('AU') {'AU-ACT': , 'AU-NSW': , 'AU-NT': , 'AU-QLD': , 'AU-SA': , 'AU-TAS': , 'AU-VIC': , 'AU-WA': } ``` ### Notes - Returns an empty `dict` if the code is unknown. ``` -------------------------------- ### Export holidays to iCal and save to file Source: https://workalendar.github.io/workalendar/ical.html Directly saves the iCal export to a file named 'france.ics' with holidays between 2019 and 2022. The export function will not work if the path is unwriteable or points to an existing directory. ```python >>> from workalendar.europe import France >>> cal = France() >>> cal.export_to_ical(period=[2019, 2022], target_path="france.ics") ``` -------------------------------- ### Use keep_datetime option to preserve input type Source: https://workalendar.github.io/workalendar/basic.html By default, add_working_days returns a datetime.date. Setting keep_datetime=True returns a datetime.datetime with the same time as the input. ```python >>> from datetime import date, datetime >>> from workalendar.europe import France >>> cal = France() >>> cal.add_working_days(datetime(2012, 12, 23, 14, 0, 39), 5, keep_datetime=True) datetime.datetime(2012, 12, 31, 14, 0, 39) ``` -------------------------------- ### Export holidays to iCal and print content Source: https://workalendar.github.io/workalendar/ical.html Exports all public holidays for France from 2019 to 2022 using the export_to_ical method. The resulting iCal content is printed, showing the BEGIN:VCALENDAR structure with VEVENT entries. If no period is provided, it defaults to [2000, 2030]. ```python >>> from workalendar.europe import France >>> cal = France() >>> ical_content = cal.export_to_ical(period=[2019, 2022]) >>> print(ical_content) BEGIN:VCALENDAR VERSION:2.0 PRODID:-//workalendar//ical 9.0.0//EN BEGIN:VEVENT SUMMARY:New year DTSTART;VALUE=DATE:20190101 DTSTAMP;VALUE=DATE-TIME:20200828T152009Z UID:2019-01-01New year@peopledoc.github.io/workalendar END:VEVENT BEGIN:VEVENT SUMMARY:Easter Monday DTSTART;VALUE=DATE:20190422 DTSTAMP;VALUE=DATE-TIME:20200828T152009Z UID:2019-04-22Easter Monday@peopledoc.github.io/workalendar END:VEVENT BEGIN:VEVENT SUMMARY:Labour Day DTSTART;VALUE=DATE:20190501 DTSTAMP;VALUE=DATE-TIME:20200828T152009Z UID:2019-05-01Labour Day@peopledoc.github.io/workalendar END:VEVENT # ... ``` -------------------------------- ### Add Easter Monday to Zhraa Source: https://workalendar.github.io/workalendar/contributing.html Adds Easter Monday by setting include_easter_monday, since WesternCalendar inherits from ChristianMixin. ```python from ..core import WesternCalendar class Zhraa(WesternCalendar): include_easter_monday = True include_labour_day = True FIXED_HOLIDAYS = WesternCalendar.FIXED_HOLIDAYS + ( (8, 2, "King Birthday"), ) ``` -------------------------------- ### Add variable day to Zhraa Source: https://workalendar.github.io/workalendar/contributing.html Overrides get_variable_days to add a variable holiday (Day of the Founder) using get_nth_weekday_in_month. The returned days list contains tuples of date and label. ```python class Zhraa(WesternCalendar): include_easter_monday = True include_labour_day = True FIXED_HOLIDAYS = WesternCalendar.FIXED_HOLIDAYS + ( (8, 2, "King Birthday"), ) def get_variable_days(self, year): # usual variable days days = super().get_variable_days(year) days.append( (Zhraa.get_nth_weekday_in_month(year, 6, MON), 'Day of the Founder'), ) return days ``` -------------------------------- ### Add fixed holidays to Zhraa Source: https://workalendar.github.io/workalendar/contributing.html Adds Labour Day and King Birthday as fixed holidays. include_labour_day is a common flag; labour_day_label can override its label. ```python class Zhraa(WesternCalendar): include_labour_day = True FIXED_HOLIDAYS = WesternCalendar.FIXED_HOLIDAYS + ( (8, 2, "King Birthday"), ) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.