Issue #2667 fixed milliseconds on time range in python
ensured microseconds are set on time range datetime objects fixed time range get in milliseconds methods modified TimeRangeTypeAdapter to use get in milliseconds methods for serialization modified DataTime python to display decimal seconds when formatted to string Former-commit-id: 8c28a4f80c68f13934a4d518691ad393aba27ce2
This commit is contained in:
parent
e2f9e86659
commit
3844b0ac5e
3 changed files with 32 additions and 16 deletions
|
@ -28,22 +28,21 @@
|
||||||
# Date Ticket# Engineer Description
|
# Date Ticket# Engineer Description
|
||||||
# ------------ ---------- ----------- --------------------------
|
# ------------ ---------- ----------- --------------------------
|
||||||
# 09/16/10 dgilling Initial Creation.
|
# 09/16/10 dgilling Initial Creation.
|
||||||
|
# 01/22/14 2667 bclement use method to get millis from time range
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
|
||||||
|
|
||||||
import calendar
|
|
||||||
from dynamicserialize.dstypes.com.raytheon.uf.common.time import TimeRange
|
from dynamicserialize.dstypes.com.raytheon.uf.common.time import TimeRange
|
||||||
|
|
||||||
|
|
||||||
# class adapters are broken, let's use a Field adapter instead
|
|
||||||
ClassAdapter = 'com.raytheon.uf.common.time.TimeRange'
|
ClassAdapter = 'com.raytheon.uf.common.time.TimeRange'
|
||||||
|
|
||||||
|
|
||||||
def serialize(context, timeRange):
|
def serialize(context, timeRange):
|
||||||
context.writeI64(calendar.timegm(timeRange.getStart()) * 1000.0)
|
context.writeI64(timeRange.getStartInMillis())
|
||||||
context.writeI64(calendar.timegm(timeRange.getEnd()) * 1000.0)
|
context.writeI64(timeRange.getEndInMillis())
|
||||||
|
|
||||||
def deserialize(context):
|
def deserialize(context):
|
||||||
startTime = context.readI64()
|
startTime = context.readI64()
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
# ------------ ---------- ----------- --------------------------
|
# ------------ ---------- ----------- --------------------------
|
||||||
# ??/??/?? xxxxxxxx Initial Creation.
|
# ??/??/?? xxxxxxxx Initial Creation.
|
||||||
# 05/28/13 2023 dgilling Implement __str__().
|
# 05/28/13 2023 dgilling Implement __str__().
|
||||||
#
|
# 01/22/14 2667 bclement preserved milliseconds in string representation
|
||||||
#
|
#
|
||||||
|
|
||||||
import calendar
|
import calendar
|
||||||
|
@ -81,7 +81,9 @@ class DataTime(object):
|
||||||
|
|
||||||
if self.refTime is not None:
|
if self.refTime is not None:
|
||||||
refTimeInSecs = self.refTime.getTime() / 1000
|
refTimeInSecs = self.refTime.getTime() / 1000
|
||||||
|
micros = (self.refTime.getTime() % 1000) * 1000
|
||||||
dtObj = datetime.datetime.utcfromtimestamp(refTimeInSecs)
|
dtObj = datetime.datetime.utcfromtimestamp(refTimeInSecs)
|
||||||
|
dtObj = dtObj.replace(microsecond=micros)
|
||||||
buffer.write(dtObj.isoformat(' '))
|
buffer.write(dtObj.isoformat(' '))
|
||||||
|
|
||||||
if "FCST_USED" in self.utilityFlags:
|
if "FCST_USED" in self.utilityFlags:
|
||||||
|
@ -94,13 +96,9 @@ class DataTime(object):
|
||||||
|
|
||||||
if "PERIOD_USED" in self.utilityFlags:
|
if "PERIOD_USED" in self.utilityFlags:
|
||||||
buffer.write("[")
|
buffer.write("[")
|
||||||
startTimeInSecs = self.validPeriod.getStartInMillis() / 1000
|
buffer.write(self.validPeriod.start.isoformat(' '))
|
||||||
dtObj = datetime.datetime.utcfromtimestamp(startTimeInSecs)
|
|
||||||
buffer.write(dtObj.isoformat(' '))
|
|
||||||
buffer.write("--")
|
buffer.write("--")
|
||||||
endTimeInSecs = self.validPeriod.getEndInMillis() / 1000
|
buffer.write(self.validPeriod.end.isoformat(' '))
|
||||||
dtObj = datetime.datetime.utcfromtimestamp(endTimeInSecs)
|
|
||||||
buffer.write(dtObj.isoformat(' '))
|
|
||||||
buffer.write("]")
|
buffer.write("]")
|
||||||
|
|
||||||
strVal = buffer.getvalue()
|
strVal = buffer.getvalue()
|
||||||
|
|
|
@ -18,13 +18,25 @@
|
||||||
# further licensing information.
|
# further licensing information.
|
||||||
##
|
##
|
||||||
|
|
||||||
# File auto-generated against equivalent DynamicSerialize Java class
|
# File auto-generated against equivalent DynamicSerialize Java class. Then modified to add functionality
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# SOFTWARE HISTORY
|
||||||
|
#
|
||||||
|
# Date Ticket# Engineer Description
|
||||||
|
# ------------ ---------- ----------- --------------------------
|
||||||
|
# ??/??/?? xxxxxxxx Initial Creation.
|
||||||
|
# 01/22/14 2667 bclement fixed millisecond support
|
||||||
|
#
|
||||||
|
#
|
||||||
|
#
|
||||||
|
|
||||||
import calendar
|
import calendar
|
||||||
import datetime
|
import datetime
|
||||||
import time
|
import time
|
||||||
|
|
||||||
MAX_TIME = 2147483647
|
MAX_TIME = 2147483647
|
||||||
|
MICROS_IN_SECOND = 1000000
|
||||||
|
|
||||||
class TimeRange(object):
|
class TimeRange(object):
|
||||||
def __init__(self, start=None, end=None):
|
def __init__(self, start=None, end=None):
|
||||||
|
@ -52,17 +64,19 @@ class TimeRange(object):
|
||||||
return datetime.datetime(*timeArg[:6])
|
return datetime.datetime(*timeArg[:6])
|
||||||
else:
|
else:
|
||||||
totalSecs = long(timeArg)
|
totalSecs = long(timeArg)
|
||||||
|
micros = int((timeArg - totalSecs) * MICROS_IN_SECOND)
|
||||||
if totalSecs < MAX_TIME:
|
if totalSecs < MAX_TIME:
|
||||||
return datetime.datetime.utcfromtimestamp(totalSecs)
|
rval = datetime.datetime.utcfromtimestamp(totalSecs)
|
||||||
else:
|
else:
|
||||||
extraTime = datetime.timedelta(seconds=(totalSecs - MAX_TIME))
|
extraTime = datetime.timedelta(seconds=(totalSecs - MAX_TIME))
|
||||||
return datetime.datetime.utcfromtimestamp(MAX_TIME) + extraTime
|
rval = datetime.datetime.utcfromtimestamp(MAX_TIME) + extraTime
|
||||||
|
return rval.replace(microsecond=micros)
|
||||||
|
|
||||||
def getStart(self):
|
def getStart(self):
|
||||||
return self.start.utctimetuple()
|
return self.start.utctimetuple()
|
||||||
|
|
||||||
def getStartInMillis(self):
|
def getStartInMillis(self):
|
||||||
return long(calendar.timegm(self.getStart()) * 1000)
|
return self._getInMillis(self.start)
|
||||||
|
|
||||||
def setStart(self, start):
|
def setStart(self, start):
|
||||||
self.start = self.__convertToDateTime(start)
|
self.start = self.__convertToDateTime(start)
|
||||||
|
@ -71,7 +85,12 @@ class TimeRange(object):
|
||||||
return self.end.utctimetuple()
|
return self.end.utctimetuple()
|
||||||
|
|
||||||
def getEndInMillis(self):
|
def getEndInMillis(self):
|
||||||
return long(calendar.timegm(self.getEnd()) * 1000)
|
return self._getInMillis(self.end)
|
||||||
|
|
||||||
|
def _getInMillis(self, time):
|
||||||
|
rval = long(calendar.timegm(time.utctimetuple()) * 1000)
|
||||||
|
rval += time.microsecond // 1000
|
||||||
|
return rval
|
||||||
|
|
||||||
def setEnd(self, end):
|
def setEnd(self, end):
|
||||||
self.end = self.__convertToDateTime(end)
|
self.end = self.__convertToDateTime(end)
|
||||||
|
|
Loading…
Add table
Reference in a new issue