Time

DIRAC Times 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.

The following datetime classes are used in the returned objects:

  • dateTime = datetime.datetime

  • date = datetime.date

  • time = datetime.timedelta

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.Times.second * 1.5 is not allowed

  • DIRAC.Times.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.Time.date(myDateTime=None)

Return current UTC date, as datetime.date object if a _dateTimeType is pass as argument its associated date is returned

DIRAC.Core.Utilities.Time.dateTime()

Return current UTC datetime, as datetime.datetime object

DIRAC.Core.Utilities.Time.from2K(seconds2K=None)

Get date from seconds since 2K

DIRAC.Core.Utilities.Time.fromEpoch(epoch)

Get datetime object from epoch

DIRAC.Core.Utilities.Time.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

DIRAC.Core.Utilities.Time.queryTime(f)

Decorator to measure the function call time

DIRAC.Core.Utilities.Time.time(myDateTime=None)

Return current UTC time, as datetime.time object if a _dateTimeType is pass as argument its associated time is returned

class DIRAC.Core.Utilities.Time.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.Time.timeThis(method)

Function to be used as a decorator for timing other functions/methods

DIRAC.Core.Utilities.Time.to2K(dateTimeObject=None)

Get seconds, with microsecond precission, since 2K

DIRAC.Core.Utilities.Time.toEpoch(dateTimeObject=None)

Get seconds since epoch

DIRAC.Core.Utilities.Time.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 alwys positive intergers and hour carries the sign.