diff --git a/src/DIRAC/Core/Utilities/TimeUtilities.py b/src/DIRAC/Core/Utilities/TimeUtilities.py index e4a3130662a..0a2a8799813 100755 --- a/src/DIRAC/Core/Utilities/TimeUtilities.py +++ b/src/DIRAC/Core/Utilities/TimeUtilities.py @@ -32,8 +32,6 @@ day = datetime.timedelta(days=1) week = datetime.timedelta(days=7) -_dateTimeObject = datetime.datetime.utcnow() - def timeThis(method): """Function to be used as a decorator for timing other functions/methods""" @@ -46,7 +44,7 @@ def timed(*args, **kw): return result te = nativetime.time() - pre = _dateTimeObject.strftime("%Y-%m-%d %H:%M:%S UTC ") + pre = datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S UTC ") try: pre += args[0].log.getName() + "/" + args[0].log.getSubName() + " TIME: " + args[0].transString @@ -85,7 +83,7 @@ def toEpoch(dateTimeObject=None): Get seconds since epoch """ if not dateTimeObject: - dateTimeObject = _dateTimeObject + dateTimeObject = datetime.datetime.utcnow() return nativetime.mktime(dateTimeObject.timetuple()) @@ -93,7 +91,7 @@ def fromEpoch(epoch): """ Get datetime object from epoch """ - return _dateTimeObject.fromtimestamp(epoch) + return datetime.datetime.utcnow().fromtimestamp(epoch) def toString(myDate=None): @@ -124,7 +122,7 @@ def toString(myDate=None): myDate.microseconds, ) else: - return toString(_dateTimeObject) + return toString(datetime.datetime.utcnow()) def fromString(myDate=None): @@ -143,7 +141,7 @@ def fromString(myDate=None): return datetime.datetime(year=dateTuple[0], month=dateTuple[1], day=dateTuple[2]) + fromString( dateTimeTuple[1] ) - # return _dateTimeObject.combine( fromString( dateTimeTuple[0] ), + # return datetime.datetime.utcnow().combine( fromString( dateTimeTuple[0] ), # fromString( dateTimeTuple[1] ) ) except Exception: try: @@ -152,7 +150,7 @@ def fromString(myDate=None): ) + fromString(dateTimeTuple[1]) except ValueError: return None - # return _dateTimeObject.combine( fromString( dateTimeTuple[0] ), + # return datetime.datetime.utcnow().combine( fromString( dateTimeTuple[0] ), # fromString( dateTimeTuple[1] ) ) elif myDate.find(":") > 0: timeTuple = myDate.replace(".", ":").split(":") diff --git a/tests/Integration/Core/Test_MySQLDB.py b/tests/Integration/Core/Test_MySQLDB.py index 564288b1785..4b334356f44 100644 --- a/tests/Integration/Core/Test_MySQLDB.py +++ b/tests/Integration/Core/Test_MySQLDB.py @@ -230,8 +230,8 @@ def test_getDistinctAttributeValues(name, fields, requiredFields, values, table, ), (table, allFields, genVal2(), name, {"older": "UTC_TIMESTAMP()", "timeStamp": "Time"}, 2, True), (table, allFields, genVal2(), name, {"newer": "UTC_TIMESTAMP()", "timeStamp": "Time"}, 0, True), - (table, allFields, genVal2(), name, {"older": TimeUtilities.toString, "timeStamp": "Time"}, 0, True), - (table, allFields, genVal2(), name, {"newer": TimeUtilities.toString, "timeStamp": "Time"}, 2, True), + (table, allFields, genVal2(), name, {"older": TimeUtilities.toString, "timeStamp": "Time"}, 2, True), + (table, allFields, genVal2(), name, {"newer": TimeUtilities.toString, "timeStamp": "Time"}, 0, True), ], ) def test_getFields(table, reqFields, values, name, args, expected, isExpectedCount):