Skip to content

Commit

Permalink
fix: Removed unnecessary variables
Browse files Browse the repository at this point in the history
  • Loading branch information
rupozzi committed May 20, 2022
1 parent 54d8a74 commit 778eab7
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/DIRAC/Core/Utilities/TimeUtilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
day = datetime.timedelta(days=1)
week = datetime.timedelta(days=7)

dt = datetime.datetime(2000, 1, 1)
_dateTimeObject = datetime.datetime.utcnow()


def timeThis(method):
Expand All @@ -50,7 +50,7 @@ def timed(*args, **kw):
return result
te = nativetime.time()

pre = dt.utcnow().strftime("%Y-%m-%d %H:%M:%S UTC ")
pre = _dateTimeObject.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 @@ -89,15 +89,15 @@ def toEpoch(dateTimeObject=None):
Get seconds since epoch
"""
if not dateTimeObject:
dateTimeObject = datetime.datetime.utcnow()
dateTimeObject = _dateTimeObject
return nativetime.mktime(dateTimeObject.timetuple())


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


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


def fromString(myDate=None):
Expand All @@ -147,7 +147,7 @@ def fromString(myDate=None):
return datetime.datetime(year=dateTuple[0], month=dateTuple[1], day=dateTuple[2]) + fromString(
dateTimeTuple[1]
)
# return dt.combine( fromString( dateTimeTuple[0] ),
# return _dateTimeObject.combine( fromString( dateTimeTuple[0] ),
# fromString( dateTimeTuple[1] ) )
except Exception:
try:
Expand All @@ -156,7 +156,7 @@ def fromString(myDate=None):
) + fromString(dateTimeTuple[1])
except ValueError:
return None
# return dt.combine( fromString( dateTimeTuple[0] ),
# return _dateTimeObject.combine( fromString( dateTimeTuple[0] ),
# fromString( dateTimeTuple[1] ) )
elif myDate.find(":") > 0:
timeTuple = myDate.replace(".", ":").split(":")
Expand Down Expand Up @@ -206,9 +206,7 @@ def __init__(self, initialDateTime, intervalTimeDelta):
If not properly initialized an error flag is set, and subsequent calls
to any method will return None
"""
if not isinstance(initialDateTime, type(datetime.datetime.utcnow())) or not isinstance(
intervalTimeDelta, datetime.timedelta
):
if not isinstance(initialDateTime, datetime.datetime) or not isinstance(intervalTimeDelta, datetime.timedelta):
self.__error = True
return None
self.__error = False
Expand Down

0 comments on commit 778eab7

Please sign in to comment.