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.
Get datetime object from epoch
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
myDate (str or datetime.datetime) – the date string to be converted
Decorator to measure the function call time
- class DIRAC.Core.Utilities.TimeUtilities.timeInterval(initialDateTime, intervalTimeDelta)
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
Function to be used as a decorator for timing other functions/methods
Get seconds since epoch. Accepts datetime or date objects
Get milliseconds since epoch
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.