robot.utils.robottime
¶
timestr_to_secs
¶
Parses time strings like '1h 10s', '01:00:10' and '42' and returns seconds.
Time can also be given as an integer or float or, starting from RF 6.0.1,
as a timedelta
instance.
The result is rounded according to the round_to
argument.
Use round_to=None
to disable rounding altogether.
Source code in src/robot/utils/robottime.py
secs_to_timestr
¶
Converts time in seconds to a string representation.
Returned string is in format like '1 day 2 hours 3 minutes 4 seconds 5 milliseconds' with following rules:
- Time parts having zero value are not included (e.g. '3 minutes 4 seconds' instead of '0 days 0 hours 3 minutes 4 seconds')
- Hour part has a maximum of 23 and minutes and seconds both have 59 (e.g. '1 minute 40 seconds' instead of '100 seconds')
If compact has value 'True', short suffixes are used. (e.g. 1d 2h 3min 4s 5ms)
Source code in src/robot/utils/robottime.py
format_time
¶
Deprecated in Robot Framework 7.0. Will be removed in Robot Framework 8.0.
Source code in src/robot/utils/robottime.py
get_time
¶
Return the given or current time in requested format.
If time is not given, current time is used. How time is returned is determined based on the given 'format' string as follows. Note that all checks are case-insensitive.
- If 'format' contains word 'epoch' the time is returned in seconds after the unix epoch.
- If 'format' contains any of the words 'year', 'month', 'day', 'hour', 'min' or 'sec' only selected parts are returned. The order of the returned parts is always the one in previous sentence and order of words in 'format' is not significant. Parts are returned as zero padded strings (e.g. May -> '05').
- Otherwise (and by default) the time is returned as a timestamp string in format '2006-02-24 15:08:31'
Source code in src/robot/utils/robottime.py
parse_timestamp
¶
Parse timestamp in ISO 8601-like formats into a datetime
.
Months, days, hours, minutes and seconds must use two digits and year must use four. Microseconds can use up to six digits. All time parts can be omitted.
Separators '-', '_', ' ', 'T', ':' and '.' between date and time components. Separators can also be omitted altogether.
Examples::
1 2 3 4 |
|
This is similar to datetime.fromisoformat
, but a little less strict.
The standard function is recommended if the input format is known to be
accepted.
If the input is a datetime
, it is returned as-is.
New in Robot Framework 7.0.
Source code in src/robot/utils/robottime.py
parse_time
¶
Parses the time string and returns its value as seconds since epoch.
Time can be given in five different formats:
1) Numbers are interpreted as time since epoch directly. It is possible to
use also ints and floats, not only strings containing numbers.
2) Valid timestamp ('YYYY-MM-DD hhss' and 'YYYYMMDD hhmmss').
3) 'NOW' (case-insensitive) is the current local time.
4) 'UTC' (case-insensitive) is the current time in UTC.
5) Format 'NOW - 1 day' or 'UTC + 1 hour 30 min' is the current local/UTC
time plus/minus the time specified with the time string.
Seconds are rounded down to avoid getting times in the future.
Source code in src/robot/utils/robottime.py
get_timestamp
¶
Deprecated in Robot Framework 7.0. Will be removed in Robot Framework 8.0.
Source code in src/robot/utils/robottime.py
timestamp_to_secs
¶
Deprecated in Robot Framework 7.0. Will be removed in Robot Framework 8.0.
Source code in src/robot/utils/robottime.py
secs_to_timestamp
¶
Deprecated in Robot Framework 7.0. Will be removed in Robot Framework 8.0.
Source code in src/robot/utils/robottime.py
get_elapsed_time
¶
Deprecated in Robot Framework 7.0. Will be removed in Robot Framework 8.0.
Source code in src/robot/utils/robottime.py
elapsed_time_to_string
¶
Converts elapsed time to format 'hhss.mil'.
Elapsed time as an integer or as a float is currently considered to be
milliseconds, but that will be changed to seconds in Robot Framework 8.0.
Use seconds=True
to change the behavior already now and to avoid the
deprecation warning. An alternative is giving the elapsed time as
a timedelta
.
If include_millis
is True, '.mil' part is omitted.
Support for giving the elapsed time as a timedelta
and the seconds
argument are new in Robot Framework 7.0.