Omaha #4139 Fix handling of pre-epoch dates in ISC

Change-Id: I116f35c34544319bf9875aaeea82d24751b2cca2

Former-commit-id: 2718eab540d66cac4ac88f01b840bdf23bc0562b
This commit is contained in:
Ron Anderson 2015-02-18 11:28:34 -06:00
parent 61039e84a9
commit 3d100c7bd6
4 changed files with 28 additions and 97 deletions

View file

@ -16,10 +16,19 @@
#
# See the AWIPS II Master Rights File ("Master Rights File.pdf") for
# further licensing information.
# ----------------------------------------------------------------------------
# SOFTWARE HISTORY
#
# Date Ticket# Engineer Description
# ------------ ---------- ----------- --------------------------
# 02/17/2015 4139 randerso Removed timeFromComponents and dependent
# functions in favor of calendar.timegm
#
##
import string, getopt, sys, time, gzip, os, LogStream, stat, traceback
import calendar
from collections import OrderedDict
import numpy
#import pupynere as NetCDF
@ -214,51 +223,6 @@ def processParmList(argDict, db):
final.append(p)
return final
###-------------------------------------------------------------------------###
# leap year routine
def leapYear(year):
return (year % 4 == 0 and (year + 100) % 400 != 0)
###-------------------------------------------------------------------------###
# days in month routine
def daysInMonth(month, year):
days = [ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ]
if month != 2:
return days[month - 1]
# special February handling for leap years
if leapYear(year):
return days[1] + 1
else:
return days[1]
###-------------------------------------------------------------------------###
# convert to time from components
# 0-year,1-month,2-day,3-hour,4-min,5-sec
def timeFromComponents(timeTuple):
epochDays = 0
pyear = 1970
pmonth = 1 # startTime
while pyear != timeTuple[0]:
epochDays = epochDays + 365 # days in year
if leapYear(pyear):
epochDays = epochDays + 1 # account for leap year
pyear = pyear + 1
while pmonth != timeTuple[1]:
epochDays = epochDays + daysInMonth(pmonth, timeTuple[0])
pmonth = pmonth + 1
epochDays = epochDays + timeTuple[2] - 1 # but not this day
epochTime = epochDays * 86400 + \
timeTuple[3] * 3600 + timeTuple[4] * 60 + timeTuple[5]
return int(epochTime)
###-------------------------------------------------------------------------###
### Returns true if the specified time is contained within the timeRange
def contains(timerange, time):
@ -296,14 +260,14 @@ def getIntTime(timeStr):
"Create an Integer time from a string: YYYYMMDD_HHMM"
try:
intTime = time.strptime(timeStr, "%Y%m%d_%H%M")
timeTuple = time.strptime(timeStr, "%Y%m%d_%H%M")
except:
logProblem(timeStr, \
"is not a valid time string. Use YYYYMMDD_HHMM",traceback.format_exc())
s = timeStr + " is not a valid time string. Use YYYYMMDD_HHMM"
raise SyntaxError, s
return
return timeFromComponents(intTime)
return calendar.timegm(timeTuple)
###-------------------------------------------------------------------------###
### Makes a TimeRange from the input string of the form YYYYMMDD_HHMM.

View file

@ -16,10 +16,17 @@
#
# See the AWIPS II Master Rights File ("Master Rights File.pdf") for
# further licensing information.
# ----------------------------------------------------------------------------
# SOFTWARE HISTORY
#
# Date Ticket# Engineer Description
# ------------ ---------- ----------- --------------------------
# 02/17/2015 4139 randerso Replaced call to iscTime.timeFromComponents
# with call to calendar.timegm
##
import os, stat, time, string, sys
import os, stat, time, string, sys, calendar
import iscTime, iscUtil, mergeGrid
try:
# dev environment
@ -973,7 +980,7 @@ class IscMosaic:
importError = True
while importError:
try:
intTime = time.strptime(timeStr, "%Y%m%d_%H%M")
timeTuple = time.strptime(timeStr, "%Y%m%d_%H%M")
importError = False
except ImportError:
importError = True
@ -981,7 +988,7 @@ class IscMosaic:
logger.exception("%s is not a valid time string. Use YYYYMMDD_HHMM", timeStr)
raise Exception, "Bad date format YYYYMMDD_HHMM"
return iscTime.timeFromComponents(intTime)
return calendar.timegm(timeTuple)
#---------------------------------------------------------------------
# get netcdf input variables

View file

@ -28,53 +28,10 @@
# Date Ticket# Engineer Description
# ------------ ---------- ----------- --------------------------
# 07/06/09 1995 bphillip Initial Creation.
#
#
# 02/17/2015 4139 randerso Removed timeFromComponents and dependent
# functions in favor of calendar.timegm
#
# leap year routine
def leapYear(year):
return (year % 4 == 0 and (year+100) % 400 != 0)
# days in month routine
def daysInMonth(month, year):
days = [ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ]
if month != 2:
return days[month-1]
# special February handling for leap years
if leapYear(year):
return days[1]+1
else:
return days[1]
# convert to time from components
# 0-year,1-month,2-day,3-hour,4-min,5-sec
def timeFromComponents(timeTuple):
epochDays = 0
pyear = 1970
pmonth = 1 # startTime
while pyear != timeTuple[0]:
epochDays = epochDays + 365 # days in year
if leapYear(pyear):
epochDays = epochDays + 1 # account for leap year
pyear = pyear + 1
while pmonth != timeTuple[1]:
epochDays = epochDays + daysInMonth(pmonth, timeTuple[0])
pmonth = pmonth + 1
epochDays = epochDays + timeTuple[2] - 1; # but not this day
epochTime = epochDays*86400 + \
timeTuple[3]*3600 + timeTuple[4]*60 + timeTuple[5]
return int(epochTime)
# time range routines
def containsT(tr, t):
return (t >= tr[0] and t < tr[1])

View file

@ -47,6 +47,7 @@ import com.raytheon.uf.common.time.util.TimeUtil;
* added serialization adapter, removed setters.
* 08/06/13 #1571 randerso Added hibernate annotations, javadoc cleanup
* 10/22/2013 #2361 njensen Remove ISerializableObject
* 02/17/2015 #4139 randerso Fix expandTRToQuantum to work with pre-epoch times.
*
* </pre>
*
@ -139,9 +140,11 @@ public class TimeConstraints {
}
long secSinceMidnight = absTime.getTime() % TimeUtil.MILLIS_PER_DAY;
if (secSinceMidnight < 0) {
secSinceMidnight += TimeUtil.MILLIS_PER_DAY;
}
long midnight = (absTime.getTime() / TimeUtil.MILLIS_PER_DAY)
* TimeUtil.MILLIS_PER_DAY;
long midnight = absTime.getTime() - secSinceMidnight;
int tStart = startTime - repeatInterval;