Merge "Issue #2667 fixed milliseconds on time range in python" into development
Former-commit-id:2c1c4dd658
[formerly beaf4668ed9bfa150446980a4042b2a6c90b4b8f] Former-commit-id:bcf2cada6c
This commit is contained in:
commit
8c06e69d31
3 changed files with 32 additions and 16 deletions
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Reference in a new issue