RPA.Calendar

Add a day or list of days which are considered as holidays in addition to country specific holidays when calculating

Arguments

ArgumentTypeDefault valueDescription
daysstr, date, DateTime, List[str | date | DateTime]nullstring 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"]

Compares given times and returns True if time2 is more recent than time1.

Arguments

ArgumentTypeDefault valueDescription
time1str, date, DateTimenullfirst time for comparison
time2str, date, DateTimenullsecond 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

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

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

This keyword tries to construct valid calendar instance from given date string and its expected date format.

Arguments

ArgumentTypeDefault valueDescription
date_stringstrnullfor example. "22 May 19"
date_format_instr, NoneNonefor example. "DD MMM YY"
timezonestr, NoneNonedefault timezone is "UTC"
date_format_outstr, NoneNonefor 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

Return first business day of the month.

Arguments

ArgumentTypeDefault valueDescription
datestr, date, DateTimenulldate describing the month
countrystr, NoneNonecountry 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 information for the given date.

Arguments

ArgumentTypeDefault valueDescription
datestr, date, DateTimenull
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 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 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 a business day in a country.

Arguments

ArgumentTypeDefault valueDescription
datestr, date, DateTimenullinput date
countrystr, NoneNonecountry 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 a holiday in a country. If country is not given then checks only if date is in custom holiday list.

Arguments

ArgumentTypeDefault valueDescription
datestr, date, DateTimenull
countrystr, NoneNonecountry 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

Return last business day of the month.

Arguments

ArgumentTypeDefault valueDescription
datestr, date, DateTimenulldate describing the month
countrystr, NoneNonecountry 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 holiday list into empty list.

Return holidays for a country. If country is not given then only custom holidays are returned.

Arguments

ArgumentTypeDefault valueDescription
yearsint, List[int]nullsingle year or list of years to list holidays for
countrystr, NoneNonecountry 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 the next business day.

Arguments

ArgumentTypeDefault valueDescription
datestr, date, DateTimenullday of origin
countrystr, NoneNonecountry code, default None
return_formatstrYYYY-MM-DDdates can be formatted for the resulting list, defaults to "YYYY-MM-DD"
localestr, NoneNonename 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 the previous business day.

Arguments

ArgumentTypeDefault valueDescription
datestr, date, DateTimenullday of origin
countrystr, NoneNonecountry code, default None
return_formatstrYYYY-MM-DDdates can be formatted for the resulting list, defaults to "YYYY-MM-DD"
localestr, NoneNonename 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 weekdays which are considered as business days for calculating previous and next business day.

Arguments

ArgumentTypeDefault valueDescription
daysList[int]nulllist 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 globally for the library

Arguments

ArgumentTypeDefault valueDescription
locale_namestrnullname 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.

Arguments

ArgumentTypeDefault valueDescription
datesList[str | date | DateTime]nulllist of dates to sort
return_formatstr, NoneNonedates can be formatted for the resulting list
reverseboolFalseTrue 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"

Compare 2 dates and get the time difference.

Arguments

ArgumentTypeDefault valueDescription
start_datestr, date, DateTimenullstarting date for the comparison
end_datestr, date, DateTimenullending date for the comparison
start_timezonestr, NoneNonetimezone for the starting date, defaults to None
end_timezonestr, NoneNonetimezone 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

Return the hour difference between timezones.

Arguments

ArgumentTypeDefault valueDescription
start_timezonestrnullfirst timezone
end_timezonestrnullsecond 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

Return the time difference of dates in days.

Arguments

ArgumentTypeDefault valueDescription
start_datestr, date, DateTimenullthe start date
end_datestr, date, DateTimenullthe end date
start_timezonestr, NoneNonetimezone for the start date, defaults to None
end_timezonestr, NoneNonetimezone 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

Return the time difference of dates in hours.

Arguments

ArgumentTypeDefault valueDescription
start_datestr, date, DateTimenullthe start date
end_datestr, date, DateTimenullthe end date
start_timezonestr, NoneNonetimezone for the start date, defaults to None
end_timezonestr, NoneNonetimezone 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

Return the time difference of dates in minutes.

Arguments

ArgumentTypeDefault valueDescription
start_datestr, date, DateTimenullthe start date
end_datestr, date, DateTimenullthe end date
start_timezonestr, NoneNonetimezone for the start date, defaults to None
end_timezonestr, NoneNonetimezone 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

Return time difference of dates in months.

Arguments

ArgumentTypeDefault valueDescription
start_datestr, date, DateTimenullthe start date
end_datestr, date, DateTimenullthe end date
start_timezonestr, NoneNonetimezone for the start date, defaults to None
end_timezonestr, NoneNonetimezone 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

Return current date and time

Arguments

ArgumentTypeDefault valueDescription
timezonestr, NoneNoneoptional, for example. "America/Boston"
return_formatstrYYYY-MM-DDdates 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