RPA.Calendar
module RPA.Calendar
class RPA.Calendar.Calendar
Library for handling different operations for date and time handling especially in business days and holiday contexts.
Utilizing pendulum and holidays packages.
Library is by default using days from Monday to Friday as business
days, but that can be changed by giving list of weekdays to
Set Business Days
keyword. A weekday is given as a integer, the
0 for Sunday and 6 for Saturday.
Common country holidays are respected when getting next and previous
business days, but custom holidays can be added into consideration
using keyword Add Custom Holidays
keyword.
Some dates containing for example month names are in English (en), but
the locale of the library can be changed with keyword Set Locale
or
for specific keyword if that has a locale
parameter.
variable ROBOT_AUTO_KEYWORDS
variable ROBOT_LIBRARY_DOC_FORMAT
variable ROBOT_LIBRARY_SCOPE
method add_custom_holidays
Add a day or list of days which are considered as holidays in addition to country specific holidays when calculating
- Parameters: days β string or list of dates to consider as holidays
- Returns: list of current custom holidays
Python example.
Robot Framework example.
method compare_times
Compares given times and returns True if time2 is more recent than time1.
Parameters
- time1 β first time for comparison
- time2 β second time for comparison
- Returns: True if time2 is more recent than time1
Python example.
Robot Framework example.
method create_time
This keyword tries to construct valid calendar instance from given date string and its expected date format.
See https://pendulum.eustace.io/docs/#tokens for valid tokens for the date format. Tokens are used to form correct date and time format.
Parameters
- date_string β for example. β22 May 19β
- date_format_in β for example. βDD MMM YYβ
- timezone β default timezone is βUTCβ
- date_format_out β for example. βDD-MM-YYβ
- Returns: set datetime as an object or string if date_format_out has been set
Python example.
Robot Framework example.
method first_business_day_of_the_month
Return first business day of the month.
If country is not given then holidays are not considered.
Parameters
- date β date describing the month
- country β country code, default None
- Returns: first business of the month
Python example.
Robot Framework example.
method get_iso_calendar
Get ISO calendar information for the given date.
- Parameters: date β input date
- Returns: ISO calendar object containing year, week number and weekday.
Python example.
Robot Framework example.
method is_the_date_business_day
Is the date a business day in a country.
If country is not given then holidays are not considered.
Parameters
- date β input date
- country β country code, default None
- Returns: True if the day is a business day, False if not
Python example.
Robot Framework example.
method 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.
Parameters
- date_in β input date
- country β country code, default None
- Returns: True if the day is a holiday, False if not
Python example.
Robot Framework example.
method last_business_day_of_the_month
Return last business day of the month.
If country is not given then holidays are not considered.
Parameters
- date β date describing the month
- country β country code, default None
- Returns: last business day of the month
Python example.
Robot Framework example.
method reset_custom_holidays
Reset custom holiday list into empty list.
method return_holidays
Return holidays for a country. If country is not given then only custom holidays are returned.
Parameters
- years β single year or list of years to list holidays for
- country β country code, default None
- Returns: holidays in a dictionary, the key is the date and the value is name of the holiday
Python example.
Robot Framework example.
method return_next_business_day
Return the next business day.
Parameters
- date β day of origin
- country β country code, default None
- return_format β dates can be formatted for the resulting list, defaults to βYYYY-MM-DDβ
- locale β name of the locale
- Returns: the next business day from day of origin
Python example.
Robot Framework example.
method return_previous_business_day
Return the previous business day.
Parameters
- date β day of origin
- country β country code, default None
- return_format β dates can be formatted for the resulting list, defaults to βYYYY-MM-DDβ
- locale β name of the locale
- Returns: the previous business day from day of origin
Python example.
Robot Framework example.
method set_business_days
Set weekdays which are considered as business days for calculating previous and next business day.
- Parameters: days β list of integers denoting weekdays
- Returns: previous list of weekdays
Python example.
Robot Framework example.
method set_locale
Set locale globally for the library
- Parameters: locale_name β name of the locale
- Returns: name of the previous locale
Python example.
Robot Framework example.
method sort_list_of_dates
Sort list of dates.
Parameters
- dates β list of dates to sort
- return_format β dates can be formatted for the resulting list
- reverse β True return latest to oldest, defaults to False, which means order from oldest to latest
- Returns: list of sorted dates
Python example.
Robot Framework example.
method time_difference
Compare 2 dates and get the time difference.
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)
Parameters
- start_date β starting date for the comparison
- end_date β ending date for the comparison
- start_timezone β timezone for the starting date, defaults to None
- end_timezone β timezone for the ending date, defaults to None
- Returns: dictionary containing comparison result
Python example.
Robot Framework example.
method time_difference_between_timezones
Return the hour difference between timezones.
Parameters
- start_timezone β first timezone
- end_timezone β second timezone
- Returns: hour difference between the timezones
Python example.
Robot Framework example.
method time_difference_in_days
Return the time difference of dates in days.
Parameters
- start_date β the start date
- end_date β the end date
- start_timezone β timezone for the start date, defaults to None
- end_timezone β timezone for the end date, defaults to None
- Returns: difference in days
Python example.
Robot Framework example.
method time_difference_in_hours
Return the time difference of dates in hours.
Parameters
- start_date β the start date
- end_date β the end date
- start_timezone β timezone for the start date, defaults to None
- end_timezone β timezone for the end date, defaults to None
- Returns: difference in hours
Python example.
Robot Framework example.
method time_difference_in_minutes
Return the time difference of dates in minutes.
Parameters
- start_date β the start date
- end_date β the end date
- start_timezone β timezone for the start date, defaults to None
- end_timezone β timezone for the end date, defaults to None
- Returns: difference in minutes
Python example.
Robot Framework example.
method time_difference_in_months
Return time difference of dates in months.
Parameters
- start_date β the start date
- end_date β the end date
- start_timezone β timezone for the start date, defaults to None
- end_timezone β timezone for the end date, defaults to None
- Returns: difference in months
Python example.
Robot Framework example.
method time_now
Return current date and time
Parameters
- timezone β optional, for example. βAmerica/Bostonβ
- return_format β dates can be formatted for the resulting list, defaults to βYYYY-MM-DDβ
- Returns: current datetime as an object
Python example.
Robot Framework example.