TimeUtilities
DIRAC TimeUtilities module Support for basic Date and Time operations based on system datetime module.
It provides common interface to UTC timestamps, converter to string types and back.
Useful timedelta constant are also provided to define time intervals.
Notice: datetime.timedelta objects allow multiplication and division by interger but not by float. Thus:
DIRAC.TimeUtilities.second * 1.5 is not allowed
DIRAC.TimeUtilities.second * 3 / 2 is allowed
An timeInterval class provides a method to check if a give datetime is in the defined interval.
- DIRAC.Core.Utilities.TimeUtilities.fromEpoch(epoch)
Get datetime object from epoch
- DIRAC.Core.Utilities.TimeUtilities.fromString(myDate=None)
Convert date/time/datetime String back to appropriated objects
The format of the string it is assume to be that returned by toString method. See notice on toString method On Error, return None
- Parameters:
myDate (str or datetime.datetime) – the date string to be converted
- DIRAC.Core.Utilities.TimeUtilities.queryTime(f)
Decorator to measure the function call time
- class DIRAC.Core.Utilities.TimeUtilities.timeInterval(initialDateTime, intervalTimeDelta)
Bases:
object
Simple class to define a timeInterval object able to check if a given dateTime is inside
- __init__(initialDateTime, intervalTimeDelta)
Initialization method, it requires the initial dateTime and the timedelta that define the limits. The upper limit is not included thus it is [begin,end) If not properly initialized an error flag is set, and subsequent calls to any method will return None
- includes(myDateTime)
- DIRAC.Core.Utilities.TimeUtilities.timeThis(method)
Function to be used as a decorator for timing other functions/methods
- DIRAC.Core.Utilities.TimeUtilities.toEpoch(dateTimeObject=None)
Get seconds since epoch. Accepts datetime or date objects
- DIRAC.Core.Utilities.TimeUtilities.toEpochMilliSeconds(dateTimeObject=None)
Get milliseconds since epoch
- DIRAC.Core.Utilities.TimeUtilities.toString(myDate=None)
Convert to String if argument type is neither _dateTimeType, _dateType, nor _timeType the current dateTime converted to String is returned instead
- Notice: datetime.timedelta are converted to strings using the format:
[day] days [hour]:[min]:[sec]:[microsec] where hour, min, sec, microsec are always positive integers, and day carries the sign.
- To keep internal consistency we are using:
[hour]:[min]:[sec]:[microsec] where min, sec, microsec are always positive integers and hour carries the sign.