Add Custom Holidays
Add a day or list of days which are considered as holidays in addition to country specific holidays when calculating
Arguments
Argument | Type | Default value | Description |
---|---|---|---|
days | str, date, DateTime, List[str | date | DateTime] | null | string or list of dates to consider as holidays |
param days: | string or list of dates to consider as holidays |
---|---|
return: | list of current custom holidays |
Python example.
library = Calendar()
custom_holidays = library.add_custom_holidays("2023-03-08")
# custom_holidays == ["2023-03-08"]
custom_holidays = library.add_custom_holidays([
"2023-03-09", "2023-03-10"
])
# custom_holidays == ["2023-03-08", "2023-03-09", "2023-03-10"]
Robot Framework example.
@{custom_holidays}= Add Custom Holidays 2023-03-08
# ${custom_holidays} == ["2023-03-08"]
@{more_holidays}= Create List 2023-03-09 2023-03-10
@{custom_holidays}= Add Custom Holidays ${more_holidays}
# ${custom_holidays} == ["2023-03-08", "2023-03-09", "2023-03-10"]
Compare Times
Compares given times and returns True if time2 is more recent than time1.
Arguments
Argument | Type | Default value | Description |
---|---|---|---|
time1 | str, date, DateTime | null | first time for comparison |
time2 | str, date, DateTime | null | second time for comparison |
param time1: | first time for comparison |
---|---|
param time2: | second time for comparison |
return: | True if time2 is more recent than time1 |
Python example.
recent = Calendar().compare_times("2023-03-09 13:02", "2023-03-09 13:47")
if recent:
print("2023-03-09 13:47 is more recent")
Robot Framework example.
${recent}= Compare Times 2023-03-09 13:02 2023-03-09 13:47
IF ${recent}
Log 2023-03-09 13:47 is more recent
END
Compare Times ${time1} < ${time2}
Compares given times and returns True if time2 is more recent than time1.
param time1: | first time for comparison |
---|---|
param time2: | second time for comparison |
return: | True if time2 is more recent than time1 |
Robot Framework example.
${recent}= Compare Times 2023-03-09 15:50 < 2023-03-09 15:59
IF ${recent}
Log 2023-03-09 15:59 is more recent
END
Compare Times ${time1} > ${time2}
Compares given times and returns True if time1 is more recent than time2.
param time1: | first time for comparison |
---|---|
param time2: | second time for comparison |
return: | True if time1 is more recent than time2 |
Robot Framework example.
${recent}= Compare Times 2023-03-09 15:59 > 2023-03-09 15:58
IF ${recent}
Log 2023-03-09 15:59 is more recent
END
Create Time
This keyword tries to construct valid calendar instance from given date string and its expected date format.
Arguments
Argument | Type | Default value | Description |
---|---|---|---|
date_string | str | null | for example. "22 May 19" |
date_format_in | str, None | None | for example. "DD MMM YY" |
timezone | str, None | None | default timezone is "UTC" |
date_format_out | str, None | None | for example. "DD-MM-YY" |
See https://pendulum.eustace.io/docs/#tokens for valid tokens for the date format. Tokens are used to form correct date and time format.
param date_string: | |
---|---|
for example. "22 May 19" | |
param date_format_in: | |
for example. "DD MMM YY" | |
param timezone: | default timezone is "UTC" |
param date_format_out: | |
for example. "DD-MM-YY" | |
return: | set datetime as an object or string if date_format_out has been set |
Python example.
date = Calendar().create_time(
"22 May 19",
"DD MMM YY"
)
Robot Framework example.
${date}= Create Time
... 22 May 19
... DD MMM YY
First Business Day Of The Month
Return first business day of the month.
Arguments
Argument | Type | Default value | Description |
---|---|---|---|
date | str, date, DateTime | null | date describing the month |
country | str, None | None | country code, default None |
If country is not given then holidays are not considered.
param date: | date describing the month |
---|---|
param country: | country code, default None |
return: | first business of the month |
Python example.
first_day = Calendar().first_business_day_of_the_month("2024-06-01")
# first_day == "2024-06-03"
Robot Framework example.
${first_day}= First Business Day of the Month 2024-06-01
# ${first_day} == "2024-06-03"
Get Iso Calendar
Get ISO calendar information for the given date.
Arguments
Argument | Type | Default value | Description |
---|---|---|---|
date | str, date, DateTime | null |
parameter date: | input date |
---|---|
return: | ISO calendar object containing year, week number and weekday. |
Python example.
iso_cal = Calendar().get_iso_calendar("2023-03-09")
print(iso_cal.year)
print(iso_cal.week)
print(iso_cal.weekday)
Robot Framework example.
${iso_cal}= Get ISO Calendar 2023-03-09
${iso_year}= Set Variable ${iso_cal.year}
${iso_week}= Set Variable ${iso_cal.week}
${iso_weekday}= Set Variable ${iso_cal.weekday}
Is the ${date} Business Day in ${country}
Is the date a business day in a country.
param date_in: | input date |
---|---|
param country: | country code |
return: | True if the day is a business day, False if not |
Robot Framework example.
${is_business_day}= Is the 2023-01-02 business day in FI
IF ${is_business_day}
Log To Console It is time for the work
ELSE
Log To Console It is time to relax
END
Is the ${date} Holiday in ${country}
Is the date a holiday in a country.
param date_in: | input date |
---|---|
param country: | country code |
return: | True if the day is a holiday, False if not |
Robot Framework example.
${is_it}= Is the 2022-12-26 holiday in FI
IF ${is_holiday}
Log Time to relax
ELSE
Log Time for the work
END
Is The Date Business Day
Is the date a business day in a country.
Arguments
Argument | Type | Default value | Description |
---|---|---|---|
date | str, date, DateTime | null | input date |
country | str, None | None | country code, default None |
If country is not given then holidays are not considered.
param date: | input date |
---|---|
param country: | country code, default None |
return: | True if the day is a business day, False if not |
Python example.
for day in range(1,32):
date = f"2023-1-{day}"
is_business_day = Calendar().is_the_date_business_day(date, "FI")
if is_business_day:
print(f'It is time for the work on {date}')
else:
print(f'It is time to relax on {date}')
Robot Framework example.
FOR ${day} IN RANGE 1 32
${date}= Set Variable 2023-1-${day}
${is_business_day}= Is the date business day ${date} FI
IF ${is_business_day}
Log To Console It is time for the work on ${date}
ELSE
Log To Console It is time to relax on ${date}
END
END
Is The Date Holiday
Is the date a holiday in a country. If country is not given then checks only if date is in custom holiday list.
Arguments
Argument | Type | Default value | Description |
---|---|---|---|
date | str, date, DateTime | null | |
country | str, None | None | country code, default None |
param date_in: | input date |
---|---|
param country: | country code, default None |
return: | True if the day is a holiday, False if not |
Python example.
is_holiday = Calendar().is_the_date_holiday("2022-12-26", "FI")
if is_holiday:
print('Time to relax')
else:
print('Time for the work')
Robot Framework example.
${is_holiday}= Is the date holiday 2022-12-26 FI
IF ${is_holiday}
Log Time to relax
ELSE
Log Time for the work
END
Last Business Day Of The Month
Return last business day of the month.
Arguments
Argument | Type | Default value | Description |
---|---|---|---|
date | str, date, DateTime | null | date describing the month |
country | str, None | None | country code, default None |
If country is not given then holidays are not considered.
param date: | date describing the month |
---|---|
param country: | country code, default None |
return: | last business day of the month |
Python example.
last_day = Calendar().last_business_day_of_the_month("2023-12-01")
# last_day == "2023-12-29"
Robot Framework example.
${last_day}= Last Business Day of the Month 2023-12-01
# ${last_day} == "2023-12-29"
Reset Custom Holidays
Reset custom holiday list into empty list.
Return Holidays
Return holidays for a country. If country is not given then only custom holidays are returned.
Arguments
Argument | Type | Default value | Description |
---|---|---|---|
years | int, List[int] | null | single year or list of years to list holidays for |
country | str, None | None | country code, default None |
param years: | single year or list of years to list holidays for |
---|---|
param country: | country code, default None |
return: | holidays in a dictionary, the key is the date and the value is name of the holiday |
Python example.
holidays = Calendar().return_holidays(2023, "FI")
for date, holiday_name in holidays.items():
print(f"{date} is {holiday_name}")
Robot Framework example.
&{holidays}= Return Holidays 2023 FI
FOR ${date} IN @{holidays.keys()}
Log To Console ${date} is ${holidays}[${date}]
END
Return Next Business Day
Return the next business day.
Arguments
Argument | Type | Default value | Description |
---|---|---|---|
date | str, date, DateTime | null | day of origin |
country | str, None | None | country code, default None |
return_format | str | YYYY-MM-DD | dates can be formatted for the resulting list, defaults to "YYYY-MM-DD" |
locale | str, None | None | name of the locale |
param date: | day of origin |
---|---|
param country: | country code, default None |
param return_format: | |
dates can be formatted for the resulting list, defaults to "YYYY-MM-DD" | |
param locale: | name of the locale |
return: | the next business day from day of origin |
Python example.
next_business = Calendar().return_next_business_day("2023-01-05", "FI")
# next_business == "2023-01-09"
Robot Framework example.
${next_business}= Return Next Business Day 2023-01-05 FI
# ${next_business} == "2023-01-09"
Return Previous Business Day
Return the previous business day.
Arguments
Argument | Type | Default value | Description |
---|---|---|---|
date | str, date, DateTime | null | day of origin |
country | str, None | None | country code, default None |
return_format | str | YYYY-MM-DD | dates can be formatted for the resulting list, defaults to "YYYY-MM-DD" |
locale | str, None | None | name of the locale |
param date: | day of origin |
---|---|
param country: | country code, default None |
param return_format: | |
dates can be formatted for the resulting list, defaults to "YYYY-MM-DD" | |
param locale: | name of the locale |
return: | the previous business day from day of origin |
Python example.
prev_business = Calendar().return_previous_business_day("2023-01-09", "FI")
# prev == "2023-01-05"
Robot Framework example.
${previous_business}= Return Previous Business Day 2023-01-09 FI
# ${previous_business} == "2023-01-05"
Set Business Days
Set weekdays which are considered as business days for calculating previous and next business day.
Arguments
Argument | Type | Default value | Description |
---|---|---|---|
days | List[int] | null | list of integers denoting weekdays |
param days: | list of integers denoting weekdays |
---|---|
return: | previous list of weekdays |
Python example.
# set 4 day work week
previous = Calendar().set_business_days([1,2,3,4])
# previous == [1,2,3,4,5]
Robot Framework example.
@{4days}= Create List 1 2 3 4
@{previous}= Set Business Days ${days}
# ${previous} == [1,2,3,4,5]
Set Locale
Set locale globally for the library
Arguments
Argument | Type | Default value | Description |
---|---|---|---|
locale_name | str | null | name of the locale |
param locale_name: | |
---|---|
name of the locale | |
return: | name of the previous locale |
Python example.
library = Calendar()
library.set_locale("es")
now = library.time_now(return_format="dddd DD MMMM YYYY")
# now == "jueves 09 marzo 2023"
library.set_locale("en")
now = library.time_now(return_format="dddd DD MMMM YYYY")
# now == "Thursday 09 March 2023"
Robot Framework example.
Set Locale es
${now}= Time Now return_format=dddd DD MMMM YYYY
# ${now} == "jueves 09 marzo 2023"
Set Locale en
${now}= Time Now return_format=dddd DD MMMM YYYY
# ${now} == "Thursday 09 March 2023"
Sort List Of Dates
Sort list of dates.
Arguments
Argument | Type | Default value | Description |
---|---|---|---|
dates | List[str | date | DateTime] | null | list of dates to sort |
return_format | str, None | None | dates can be formatted for the resulting list |
reverse | bool | False | True return latest to oldest, defaults to False, which means order from oldest to latest |
param dates: | list of dates to sort |
---|---|
param return_format: | |
dates can be formatted for the resulting list | |
param reverse: | True return latest to oldest, defaults to False, which means order from oldest to latest |
return: | list of sorted dates |
Python example.
datelist = [
"2023-07-02 12:02:31",
"2023-07-03 12:02:35",
"2023-07-03 12:02:31"
]
sorted = Calendar().sort_list_of_dates(datelist)
# sorted[0] == "2023-07-03 12:02:35"
# sorted[-1] == "2023-07-02 12:02:31"
sorted = Calendar().sort_list_of_dates(datelist, reverse=True)
# sorted[0] == "2023-07-02 12:02:31"
# sorted[-1] == "2023-07-03 12:02:35"
Robot Framework example.
@{datelist}= Create List
... 2023-07-02 12:02:31
... 2023-07-03 12:02:35
... 2023-07-03 12:02:31
${sorted}= Sort List Of Dates ${datelist}
# ${sorted}[0] == "2023-07-03 12:02:35"
${sorted}= Sort List Of Dates ${datelist} reverse=True
# ${sorted}[0] == "2023-07-02 12:02:31"
Time Difference
Compare 2 dates and get the time difference.
Arguments
Argument | Type | Default value | Description |
---|---|---|---|
start_date | str, date, DateTime | null | starting date for the comparison |
end_date | str, date, DateTime | null | ending date for the comparison |
start_timezone | str, None | None | timezone for the starting date, defaults to None |
end_timezone | str, None | None | timezone for the ending date, defaults to None |
Returned dictionary contains following properties:
- end_date_is_later, True if end_date is more recent than start_date, otherwise False
- years, time difference in years
- months, time difference in months
- days, time difference in days
- hours, time difference in hours (in addition to the days)
- minutes, time difference in minutes (in addition to the hours)
- seconds, time difference in seconds (in addition to the minutes)
param start_date: | |
---|---|
starting date for the comparison | |
param end_date: | ending date for the comparison |
param start_timezone: | |
timezone for the starting date, defaults to None | |
param end_timezone: | |
timezone for the ending date, defaults to None | |
return: | dictionary containing comparison result |
Python example.
diff = Calendar().time_difference(
"1975-05-22T18:00:00",
"1975-05-22T22:45:30"
)
# diff['end_date_is_later'] == True
# diff['days'] == 0
# diff['hours'] == 4
# diff['minutes'] == 45
# diff['seconds'] == 30
Robot Framework example.
&{diff}= Time Difference 1975-05-22T18:00:00 1975-05-22T22:45:30
# ${diff}[end_date_is_later] == True
Time Difference Between Timezones
Return the hour difference between timezones.
Arguments
Argument | Type | Default value | Description |
---|---|---|---|
start_timezone | str | null | first timezone |
end_timezone | str | null | second timezone |
param start_timezone: | |
---|---|
first timezone | |
param end_timezone: | |
second timezone | |
return: | hour difference between the timezones |
Python example.
diff = Calendar().time_difference_between_timezones(
"America/New_York",
"Europe/Helsinki"
)
# diff == 7
Robot Framework example.
${diff}= Time Difference Between Timezones
... America/New_York
... Europe/Helsinki
# ${diff} == 7
Time Difference In Days
Return the time difference of dates in days.
Arguments
Argument | Type | Default value | Description |
---|---|---|---|
start_date | str, date, DateTime | null | the start date |
end_date | str, date, DateTime | null | the end date |
start_timezone | str, None | None | timezone for the start date, defaults to None |
end_timezone | str, None | None | timezone for the end date, defaults to None |
param start_date: | |
---|---|
the start date | |
param end_date: | the end date |
param start_timezone: | |
timezone for the start date, defaults to None | |
param end_timezone: | |
timezone for the end date, defaults to None | |
return: | difference in days |
Python example.
diff = Calendar().time_difference_in_days(
"2023-05-21",
"2023-05-29"
)
# diff == 8
Robot Framework example.
${diff}= Time Difference In Days
... 2023-05-21
... 2023-05-29
# ${diff} == 8
Time Difference In Hours
Return the time difference of dates in hours.
Arguments
Argument | Type | Default value | Description |
---|---|---|---|
start_date | str, date, DateTime | null | the start date |
end_date | str, date, DateTime | null | the end date |
start_timezone | str, None | None | timezone for the start date, defaults to None |
end_timezone | str, None | None | timezone for the end date, defaults to None |
param start_date: | |
---|---|
the start date | |
param end_date: | the end date |
param start_timezone: | |
timezone for the start date, defaults to None | |
param end_timezone: | |
timezone for the end date, defaults to None | |
return: | difference in hours |
Python example.
diff = Calendar().time_difference_in_hours(
"2023-08-21T22:00:00",
"2023-08-22T04:00:00"
)
# diff == 6
Robot Framework example.
${diff}= Time Difference In Hours
... 2023-08-21T22:00:00
... 2023-08-22T04:00:00
# ${diff} == 6
Time Difference In Minutes
Return the time difference of dates in minutes.
Arguments
Argument | Type | Default value | Description |
---|---|---|---|
start_date | str, date, DateTime | null | the start date |
end_date | str, date, DateTime | null | the end date |
start_timezone | str, None | None | timezone for the start date, defaults to None |
end_timezone | str, None | None | timezone for the end date, defaults to None |
param start_date: | |
---|---|
the start date | |
param end_date: | the end date |
param start_timezone: | |
timezone for the start date, defaults to None | |
param end_timezone: | |
timezone for the end date, defaults to None | |
return: | difference in minutes |
Python example.
diff = Calendar().time_difference_in_minutes(
"12:30",
"16:35"
)
# diff == 245
Robot Framework example.
${diff}= Time Difference In Minutes
... 12:30
... 16:35
# ${diff} == 245
Time Difference In Months
Return time difference of dates in months.
Arguments
Argument | Type | Default value | Description |
---|---|---|---|
start_date | str, date, DateTime | null | the start date |
end_date | str, date, DateTime | null | the end date |
start_timezone | str, None | None | timezone for the start date, defaults to None |
end_timezone | str, None | None | timezone for the end date, defaults to None |
param start_date: | |
---|---|
the start date | |
param end_date: | the end date |
param start_timezone: | |
timezone for the start date, defaults to None | |
param end_timezone: | |
timezone for the end date, defaults to None | |
return: | difference in months |
Python example.
diff = Calendar().time_difference_in_months(
"2022-05-21T22:00:00",
"2023-08-21T22:00:00"
)
# diff == 15
Robot Framework example.
${diff}= Time Difference In Months
... 2022-05-21T22:00:00
... 2023-08-21T22:00:00
# ${diff} == 15
Time Now
Return current date and time
Arguments
Argument | Type | Default value | Description |
---|---|---|---|
timezone | str, None | None | optional, for example. "America/Boston" |
return_format | str | YYYY-MM-DD | dates can be formatted for the resulting list, defaults to "YYYY-MM-DD" |
param timezone: | optional, for example. "America/Boston" |
---|---|
param return_format: | |
dates can be formatted for the resulting list, defaults to "YYYY-MM-DD" | |
return: | current datetime as an object |
Python example.
now = Calendar().time_now("Europe/Helsinki")
Robot Framework example.
${now}= Time Now Europe/Helsinki