Robot Framework
robot.utils.robottime Namespace Reference

Classes

class  _SecsToTimestrHelper
 
class  TimestampCache
 

Functions

def _elapsed_time_to_string (elapsed)
 
def _elapsed_time_to_string_without_millis (elapsed)
 
def _float_secs_to_secs_and_millis (secs)
 
def _get_dst_difference (time1, time2)
 
def _get_timetuple (epoch_secs=None)
 
def _normalize_timestamp (ts, seps)
 
def _normalize_timestr (timestr)
 
def _number_to_secs (number)
 
def _parse_time_epoch (timestr)
 
def _parse_time_now_and_utc (timestr)
 
def _parse_time_now_and_utc_base (base)
 
def _parse_time_now_and_utc_extra (extra)
 
def _parse_time_timestamp (timestr)
 
def _split_timestamp (timestamp)
 
def _time_string_to_secs (timestr)
 
def _timer_to_secs (number)
 
def _timestamp_to_millis (timestamp, seps=None)
 
def elapsed_time_to_string (elapsed, include_millis=True)
 Converts elapsed time in milliseconds to format 'hh:mm:ss.mil'. More...
 
def format_time (timetuple_or_epochsecs, daysep='', daytimesep=' ', timesep=':', millissep=None)
 Returns a timestamp formatted from given time using separators. More...
 
def get_elapsed_time (start_time, end_time)
 Returns the time between given timestamps in milliseconds. More...
 
def get_time (format='timestamp', time_=None)
 Return the given or current time in requested format. More...
 
def get_timestamp (daysep='', daytimesep=' ', timesep=':', millissep='.')
 
def parse_time (timestr)
 Parses the time string and returns its value as seconds since epoch. More...
 
def secs_to_timestamp (secs, seps=None, millis=False)
 
def secs_to_timestr (secs, compact=False)
 Converts time in seconds to a string representation. More...
 
def timestamp_to_secs (timestamp, seps=None)
 
def timestr_to_secs (timestr, round_to=3, accept_plain_values=True)
 Parses time strings like '1h 10s', '01:00:10' and '42' and returns seconds. More...
 

Variables

 _timer_re
 
 TIMESTAMP_CACHE = TimestampCache()
 

Function Documentation

◆ _elapsed_time_to_string()

def robot.utils.robottime._elapsed_time_to_string (   elapsed)
private

Definition at line 384 of file robottime.py.

◆ _elapsed_time_to_string_without_millis()

def robot.utils.robottime._elapsed_time_to_string_without_millis (   elapsed)
private

Definition at line 391 of file robottime.py.

◆ _float_secs_to_secs_and_millis()

def robot.utils.robottime._float_secs_to_secs_and_millis (   secs)
private

Definition at line 39 of file robottime.py.

◆ _get_dst_difference()

def robot.utils.robottime._get_dst_difference (   time1,
  time2 
)
private

Definition at line 326 of file robottime.py.

◆ _get_timetuple()

def robot.utils.robottime._get_timetuple (   epoch_secs = None)
private

Definition at line 31 of file robottime.py.

◆ _normalize_timestamp()

def robot.utils.robottime._normalize_timestamp (   ts,
  seps 
)
private

Definition at line 406 of file robottime.py.

◆ _normalize_timestr()

def robot.utils.robottime._normalize_timestr (   timestr)
private

Definition at line 121 of file robottime.py.

◆ _number_to_secs()

def robot.utils.robottime._number_to_secs (   number)
private

Definition at line 70 of file robottime.py.

◆ _parse_time_epoch()

def robot.utils.robottime._parse_time_epoch (   timestr)
private

Definition at line 281 of file robottime.py.

◆ _parse_time_now_and_utc()

def robot.utils.robottime._parse_time_now_and_utc (   timestr)
private

Definition at line 298 of file robottime.py.

◆ _parse_time_now_and_utc_base()

def robot.utils.robottime._parse_time_now_and_utc_base (   base)
private

Definition at line 308 of file robottime.py.

◆ _parse_time_now_and_utc_extra()

def robot.utils.robottime._parse_time_now_and_utc_extra (   extra)
private

Definition at line 318 of file robottime.py.

◆ _parse_time_timestamp()

def robot.utils.robottime._parse_time_timestamp (   timestr)
private

Definition at line 291 of file robottime.py.

◆ _split_timestamp()

def robot.utils.robottime._split_timestamp (   timestamp)
private

Definition at line 414 of file robottime.py.

◆ _time_string_to_secs()

def robot.utils.robottime._time_string_to_secs (   timestr)
private

Definition at line 92 of file robottime.py.

◆ _timer_to_secs()

def robot.utils.robottime._timer_to_secs (   number)
private

Definition at line 77 of file robottime.py.

◆ _timestamp_to_millis()

def robot.utils.robottime._timestamp_to_millis (   timestamp,
  seps = None 
)
private

Definition at line 398 of file robottime.py.

◆ elapsed_time_to_string()

def robot.utils.robottime.elapsed_time_to_string (   elapsed,
  include_millis = True 
)

Converts elapsed time in milliseconds to format 'hh:mm:ss.mil'.

If `include_millis` is True, '.mil' part is omitted.

Definition at line 374 of file robottime.py.

◆ format_time()

def robot.utils.robottime.format_time (   timetuple_or_epochsecs,
  daysep = '',
  daytimesep = ' ',
  timesep = ':',
  millissep = None 
)

Returns a timestamp formatted from given time using separators.

Time can be given either as a timetuple or seconds after epoch.

Timetuple is (year, month, day, hour, min, sec[, millis]), where parts must
be integers and millis is required only when millissep is not None.
Notice that this is not 100% compatible with standard Python timetuples
which do not have millis.

Seconds after epoch can be either an integer or a float.

Definition at line 207 of file robottime.py.

◆ get_elapsed_time()

def robot.utils.robottime.get_elapsed_time (   start_time,
  end_time 
)

Returns the time between given timestamps in milliseconds.

Definition at line 359 of file robottime.py.

◆ get_time()

def robot.utils.robottime.get_time (   format = 'timestamp',
  time_ = None 
)

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'

Definition at line 236 of file robottime.py.

◆ get_timestamp()

def robot.utils.robottime.get_timestamp (   daysep = '',
  daytimesep = ' ',
  timesep = ':',
  millissep = '.' 
)

Definition at line 335 of file robottime.py.

◆ parse_time()

def robot.utils.robottime.parse_time (   timestr)

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 hh:mm:ss' 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.

Definition at line 271 of file robottime.py.

◆ secs_to_timestamp()

def robot.utils.robottime.secs_to_timestamp (   secs,
  seps = None,
  millis = False 
)

Definition at line 348 of file robottime.py.

◆ secs_to_timestr()

def robot.utils.robottime.secs_to_timestr (   secs,
  compact = False 
)

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 maximun 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)

Definition at line 151 of file robottime.py.

◆ timestamp_to_secs()

def robot.utils.robottime.timestamp_to_secs (   timestamp,
  seps = None 
)

Definition at line 339 of file robottime.py.

◆ timestr_to_secs()

def robot.utils.robottime.timestr_to_secs (   timestr,
  round_to = 3,
  accept_plain_values = True 
)

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.

`accept_plain_values` is considered deprecated and should not be used.

Definition at line 55 of file robottime.py.

Variable Documentation

◆ _timer_re

robot.utils.robottime._timer_re
private

Definition at line 28 of file robottime.py.

◆ TIMESTAMP_CACHE

robot.utils.robottime.TIMESTAMP_CACHE = TimestampCache()

Definition at line 461 of file robottime.py.