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: 9db7a7c6ec [formerly 3844b0ac5e] [formerly 9db7a7c6ec [formerly 3844b0ac5e] [formerly 2c8e41c0b8 [formerly 8c28a4f80c68f13934a4d518691ad393aba27ce2]]]
Former-commit-id: 2c8e41c0b8
Former-commit-id: 3b858335f3 [formerly 04c852b4cf]
Former-commit-id: 0592f98c95
This commit is contained in:
Brian Clements 2014-01-22 17:36:34 -06:00
parent 91396bb5a7
commit 0570c66413
3 changed files with 32 additions and 16 deletions

View file

@ -28,22 +28,21 @@
# Date Ticket# Engineer Description
# ------------ ---------- ----------- --------------------------
# 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
# class adapters are broken, let's use a Field adapter instead
ClassAdapter = 'com.raytheon.uf.common.time.TimeRange'
def serialize(context, timeRange):
context.writeI64(calendar.timegm(timeRange.getStart()) * 1000.0)
context.writeI64(calendar.timegm(timeRange.getEnd()) * 1000.0)
context.writeI64(timeRange.getStartInMillis())
context.writeI64(timeRange.getEndInMillis())
def deserialize(context):
startTime = context.readI64()

View file

@ -28,7 +28,7 @@
# ------------ ---------- ----------- --------------------------
# ??/??/?? xxxxxxxx Initial Creation.
# 05/28/13 2023 dgilling Implement __str__().
#
# 01/22/14 2667 bclement preserved milliseconds in string representation
#
import calendar
@ -81,7 +81,9 @@ class DataTime(object):
if self.refTime is not None:
refTimeInSecs = self.refTime.getTime() / 1000
micros = (self.refTime.getTime() % 1000) * 1000
dtObj = datetime.datetime.utcfromtimestamp(refTimeInSecs)
dtObj = dtObj.replace(microsecond=micros)
buffer.write(dtObj.isoformat(' '))
if "FCST_USED" in self.utilityFlags:
@ -94,13 +96,9 @@ class DataTime(object):
if "PERIOD_USED" in self.utilityFlags:
buffer.write("[")
startTimeInSecs = self.validPeriod.getStartInMillis() / 1000
dtObj = datetime.datetime.utcfromtimestamp(startTimeInSecs)
buffer.write(dtObj.isoformat(' '))
buffer.write(self.validPeriod.start.isoformat(' '))
buffer.write("--")
endTimeInSecs = self.validPeriod.getEndInMillis() / 1000
dtObj = datetime.datetime.utcfromtimestamp(endTimeInSecs)
buffer.write(dtObj.isoformat(' '))
buffer.write(self.validPeriod.end.isoformat(' '))
buffer.write("]")
strVal = buffer.getvalue()

View file

@ -18,13 +18,25 @@
# 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 datetime
import time
MAX_TIME = 2147483647
MICROS_IN_SECOND = 1000000
class TimeRange(object):
def __init__(self, start=None, end=None):
@ -52,17 +64,19 @@ class TimeRange(object):
return datetime.datetime(*timeArg[:6])
else:
totalSecs = long(timeArg)
micros = int((timeArg - totalSecs) * MICROS_IN_SECOND)
if totalSecs < MAX_TIME:
return datetime.datetime.utcfromtimestamp(totalSecs)
rval = datetime.datetime.utcfromtimestamp(totalSecs)
else:
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):
return self.start.utctimetuple()
def getStartInMillis(self):
return long(calendar.timegm(self.getStart()) * 1000)
return self._getInMillis(self.start)
def setStart(self, start):
self.start = self.__convertToDateTime(start)
@ -71,7 +85,12 @@ class TimeRange(object):
return self.end.utctimetuple()
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):
self.end = self.__convertToDateTime(end)