Skip to content

Commit

Permalink
test: trying integration error
Browse files Browse the repository at this point in the history
  • Loading branch information
rupozzi committed Jun 1, 2022
1 parent e64910a commit 8214a66
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
14 changes: 6 additions & 8 deletions src/DIRAC/Core/Utilities/TimeUtilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand All @@ -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
Expand Down Expand Up @@ -85,15 +83,15 @@ def toEpoch(dateTimeObject=None):
Get seconds since epoch
"""
if not dateTimeObject:
dateTimeObject = _dateTimeObject
dateTimeObject = datetime.datetime.utcnow()
return nativetime.mktime(dateTimeObject.timetuple())


def fromEpoch(epoch):
"""
Get datetime object from epoch
"""
return _dateTimeObject.fromtimestamp(epoch)
return datetime.datetime.utcnow().fromtimestamp(epoch)


def toString(myDate=None):
Expand Down Expand Up @@ -124,7 +122,7 @@ def toString(myDate=None):
myDate.microseconds,
)
else:
return toString(_dateTimeObject)
return toString(datetime.datetime.utcnow())


def fromString(myDate=None):
Expand All @@ -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:
Expand All @@ -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(":")
Expand Down
4 changes: 2 additions & 2 deletions tests/Integration/Core/Test_MySQLDB.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 8214a66

Please sign in to comment.