Omaha #4139 Fix handling of pre-epoch dates in ISC
Change-Id: I116f35c34544319bf9875aaeea82d24751b2cca2 Former-commit-id: 2718eab540d66cac4ac88f01b840bdf23bc0562b
This commit is contained in:
parent
61039e84a9
commit
3d100c7bd6
4 changed files with 28 additions and 97 deletions
|
@ -16,10 +16,19 @@
|
||||||
#
|
#
|
||||||
# See the AWIPS II Master Rights File ("Master Rights File.pdf") for
|
# See the AWIPS II Master Rights File ("Master Rights File.pdf") for
|
||||||
# further licensing information.
|
# 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 string, getopt, sys, time, gzip, os, LogStream, stat, traceback
|
||||||
|
import calendar
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
import numpy
|
import numpy
|
||||||
#import pupynere as NetCDF
|
#import pupynere as NetCDF
|
||||||
|
@ -214,51 +223,6 @@ def processParmList(argDict, db):
|
||||||
final.append(p)
|
final.append(p)
|
||||||
return final
|
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
|
### Returns true if the specified time is contained within the timeRange
|
||||||
def contains(timerange, time):
|
def contains(timerange, time):
|
||||||
|
@ -296,14 +260,14 @@ def getIntTime(timeStr):
|
||||||
"Create an Integer time from a string: YYYYMMDD_HHMM"
|
"Create an Integer time from a string: YYYYMMDD_HHMM"
|
||||||
|
|
||||||
try:
|
try:
|
||||||
intTime = time.strptime(timeStr, "%Y%m%d_%H%M")
|
timeTuple = time.strptime(timeStr, "%Y%m%d_%H%M")
|
||||||
except:
|
except:
|
||||||
logProblem(timeStr, \
|
logProblem(timeStr, \
|
||||||
"is not a valid time string. Use YYYYMMDD_HHMM",traceback.format_exc())
|
"is not a valid time string. Use YYYYMMDD_HHMM",traceback.format_exc())
|
||||||
s = timeStr + " is not a valid time string. Use YYYYMMDD_HHMM"
|
s = timeStr + " is not a valid time string. Use YYYYMMDD_HHMM"
|
||||||
raise SyntaxError, s
|
raise SyntaxError, s
|
||||||
return
|
return
|
||||||
return timeFromComponents(intTime)
|
return calendar.timegm(timeTuple)
|
||||||
|
|
||||||
###-------------------------------------------------------------------------###
|
###-------------------------------------------------------------------------###
|
||||||
### Makes a TimeRange from the input string of the form YYYYMMDD_HHMM.
|
### Makes a TimeRange from the input string of the form YYYYMMDD_HHMM.
|
||||||
|
|
|
@ -16,10 +16,17 @@
|
||||||
#
|
#
|
||||||
# See the AWIPS II Master Rights File ("Master Rights File.pdf") for
|
# See the AWIPS II Master Rights File ("Master Rights File.pdf") for
|
||||||
# further licensing information.
|
# 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
|
import iscTime, iscUtil, mergeGrid
|
||||||
try:
|
try:
|
||||||
# dev environment
|
# dev environment
|
||||||
|
@ -973,7 +980,7 @@ class IscMosaic:
|
||||||
importError = True
|
importError = True
|
||||||
while importError:
|
while importError:
|
||||||
try:
|
try:
|
||||||
intTime = time.strptime(timeStr, "%Y%m%d_%H%M")
|
timeTuple = time.strptime(timeStr, "%Y%m%d_%H%M")
|
||||||
importError = False
|
importError = False
|
||||||
except ImportError:
|
except ImportError:
|
||||||
importError = True
|
importError = True
|
||||||
|
@ -981,7 +988,7 @@ class IscMosaic:
|
||||||
logger.exception("%s is not a valid time string. Use YYYYMMDD_HHMM", timeStr)
|
logger.exception("%s is not a valid time string. Use YYYYMMDD_HHMM", timeStr)
|
||||||
raise Exception, "Bad date format YYYYMMDD_HHMM"
|
raise Exception, "Bad date format YYYYMMDD_HHMM"
|
||||||
|
|
||||||
return iscTime.timeFromComponents(intTime)
|
return calendar.timegm(timeTuple)
|
||||||
|
|
||||||
#---------------------------------------------------------------------
|
#---------------------------------------------------------------------
|
||||||
# get netcdf input variables
|
# get netcdf input variables
|
||||||
|
|
|
@ -28,52 +28,9 @@
|
||||||
# Date Ticket# Engineer Description
|
# Date Ticket# Engineer Description
|
||||||
# ------------ ---------- ----------- --------------------------
|
# ------------ ---------- ----------- --------------------------
|
||||||
# 07/06/09 1995 bphillip Initial Creation.
|
# 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
|
# time range routines
|
||||||
def containsT(tr, t):
|
def containsT(tr, t):
|
||||||
|
|
|
@ -47,6 +47,7 @@ import com.raytheon.uf.common.time.util.TimeUtil;
|
||||||
* added serialization adapter, removed setters.
|
* added serialization adapter, removed setters.
|
||||||
* 08/06/13 #1571 randerso Added hibernate annotations, javadoc cleanup
|
* 08/06/13 #1571 randerso Added hibernate annotations, javadoc cleanup
|
||||||
* 10/22/2013 #2361 njensen Remove ISerializableObject
|
* 10/22/2013 #2361 njensen Remove ISerializableObject
|
||||||
|
* 02/17/2015 #4139 randerso Fix expandTRToQuantum to work with pre-epoch times.
|
||||||
*
|
*
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
|
@ -139,9 +140,11 @@ public class TimeConstraints {
|
||||||
}
|
}
|
||||||
|
|
||||||
long secSinceMidnight = absTime.getTime() % TimeUtil.MILLIS_PER_DAY;
|
long secSinceMidnight = absTime.getTime() % TimeUtil.MILLIS_PER_DAY;
|
||||||
|
if (secSinceMidnight < 0) {
|
||||||
|
secSinceMidnight += TimeUtil.MILLIS_PER_DAY;
|
||||||
|
}
|
||||||
|
|
||||||
long midnight = (absTime.getTime() / TimeUtil.MILLIS_PER_DAY)
|
long midnight = absTime.getTime() - secSinceMidnight;
|
||||||
* TimeUtil.MILLIS_PER_DAY;
|
|
||||||
|
|
||||||
int tStart = startTime - repeatInterval;
|
int tStart = startTime - repeatInterval;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue