Merge "Issue #1636 Changes to TimeTools to allow file timestamp pattern to allow option hour; and WarningDecoder.py now uses TimeTools." into development
Former-commit-id:a9f4bfb079
[formerlyd0ab7330fc
[formerly 57e32f0c573791f07e5f801411fb6292fc74d87f]] Former-commit-id:d0ab7330fc
Former-commit-id:2d3dc0aa3f
This commit is contained in:
commit
eeeb47fa52
5 changed files with 516 additions and 196 deletions
|
@ -21,11 +21,28 @@
|
||||||
# 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.
|
||||||
##
|
##
|
||||||
|
##
|
||||||
|
# This program decodes a product's UGC and VTEC strings
|
||||||
|
#
|
||||||
|
# <pre>
|
||||||
|
#
|
||||||
|
# SOFTWARE HISTORY
|
||||||
|
#
|
||||||
|
# Date Ticket# Engineer Description
|
||||||
|
# ------------ ---------- ----------- --------------------------
|
||||||
|
# Initial creation
|
||||||
|
# Feb 19, 2013 1636 rferrel Use TimeTools to get file timestamp.
|
||||||
|
# </pre>
|
||||||
|
#
|
||||||
|
# @author rferrel
|
||||||
|
# @version 1.0
|
||||||
|
##
|
||||||
|
|
||||||
import sys, os, time, re, string, getopt
|
import sys, os, time, re, string, getopt
|
||||||
import copy
|
import copy
|
||||||
import LogStream
|
import LogStream
|
||||||
from ufpy import TimeUtil
|
from ufpy import TimeUtil
|
||||||
|
from com.raytheon.uf.edex.decodertools.time import TimeTools
|
||||||
|
|
||||||
ACCURATE_CITIES_PILS = ['CFW', 'FFA', 'NPW', 'RFW', 'WSW']
|
ACCURATE_CITIES_PILS = ['CFW', 'FFA', 'NPW', 'RFW', 'WSW']
|
||||||
|
|
||||||
|
@ -83,12 +100,17 @@ class StdWarningDecoder():
|
||||||
|
|
||||||
#base time for decoder
|
#base time for decoder
|
||||||
self._time = time.time() + self._timeOffset #present time
|
self._time = time.time() + self._timeOffset #present time
|
||||||
allowArchive = os.getenv("ALLOW_ARCHIVE_DATA")
|
|
||||||
if allowArchive.lower() == "true" and re.match(".*\\.\\d{8}$", self._incomingFilename):
|
if TimeTools.allowArchive() :
|
||||||
m = re.search('(.*\\.)(\\d{8}$)', self._incomingFilename)
|
try:
|
||||||
yyyymmdd = m.group(2)
|
yyyymmddhh = TimeTools.getTimestamp(self._incomingFilename)
|
||||||
timeTuple = time.strptime(yyyymmdd, "%Y%m%d")
|
if len(yyyymmddhh) < 10:
|
||||||
|
timeTuple = time.strptime(yyyymmddhh, "%Y%m%d")
|
||||||
|
else :
|
||||||
|
timeTuple = time.strptime(yyyymmddhh, "%Y%m%d%H")
|
||||||
self._time = time.mktime(timeTuple)
|
self._time = time.mktime(timeTuple)
|
||||||
|
except :
|
||||||
|
LogStream.logProblem('Unable to get timestamp from filename: "%s"' % (self._incomingFilename))
|
||||||
|
|
||||||
os.umask(0) #ensure proper permissions
|
os.umask(0) #ensure proper permissions
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,6 @@
|
||||||
package com.raytheon.uf.edex.decodertools.time;
|
package com.raytheon.uf.edex.decodertools.time;
|
||||||
|
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
|
@ -49,6 +48,7 @@ import com.raytheon.uf.edex.decodertools.core.DecoderTools;
|
||||||
* 20070903 379 jkorman Added newCalendar from milliseconds.
|
* 20070903 379 jkorman Added newCalendar from milliseconds.
|
||||||
* 20070925 391 jkorman Added copyToNearestHour method.
|
* 20070925 391 jkorman Added copyToNearestHour method.
|
||||||
* 20071019 391 jkorman Added getSystemCalendar and TimeService.
|
* 20071019 391 jkorman Added getSystemCalendar and TimeService.
|
||||||
|
* 20130219 1636 rferrel File timestamp can now be YYMMDD or YYMMDDHH.
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
* @author jkorman
|
* @author jkorman
|
||||||
|
@ -56,13 +56,18 @@ import com.raytheon.uf.edex.decodertools.core.DecoderTools;
|
||||||
*/
|
*/
|
||||||
public class TimeTools {
|
public class TimeTools {
|
||||||
|
|
||||||
/**
|
/** Environment variable to indicate archived files. */
|
||||||
* Time stamp that includes the receipt time
|
private static final String ALLOW_ARCHIVE_ENV = "ALLOW_ARCHIVE_DATA";
|
||||||
* format : YYYYMMDD
|
|
||||||
*/
|
|
||||||
public static final Pattern FILE_TIMESTAMP = Pattern.compile("(.*\\.)(\\d{8}$)");
|
|
||||||
|
|
||||||
public static final Pattern WMO_TIMESTAMP = Pattern.compile("([0-3][0-9])(\\d{2})(\\d{2})[Zz]?");
|
/**
|
||||||
|
* Time stamp that includes the receipt time format at the end of the file
|
||||||
|
* name: .YYYYMMDD or .YYYYMMDDHH
|
||||||
|
*/
|
||||||
|
private static final Pattern FILE_TIMESTAMP = Pattern
|
||||||
|
.compile("(.*\\.)(\\d{8}|\\d{10}$)");
|
||||||
|
|
||||||
|
public static final Pattern WMO_TIMESTAMP = Pattern
|
||||||
|
.compile("([0-3][0-9])(\\d{2})(\\d{2})[Zz]?");
|
||||||
|
|
||||||
public static final int HOURS_DAY = 24;
|
public static final int HOURS_DAY = 24;
|
||||||
|
|
||||||
|
@ -82,12 +87,35 @@ public class TimeTools {
|
||||||
|
|
||||||
private static final Log logger = LogFactory.getLog(TimeTools.class);
|
private static final Log logger = LogFactory.getLog(TimeTools.class);
|
||||||
|
|
||||||
|
static interface ICheckAllowArchive {
|
||||||
|
boolean allowArchive();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Default class for checking for allowing archive.
|
||||||
|
*/
|
||||||
|
private static class CheckOSEnv implements ICheckAllowArchive {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean allowArchive() {
|
||||||
|
// This doesn't pick up the environment variable.
|
||||||
|
// return Boolean.getBoolean(ALLOW_ARCHIVE_ENV);
|
||||||
|
return "true".equalsIgnoreCase(System.getenv().get(
|
||||||
|
ALLOW_ARCHIVE_ENV));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Allows the check on archive to be overriden for testing. */
|
||||||
|
static ICheckAllowArchive checkAllowArchive = new CheckOSEnv();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check to see if archive files are allowed.
|
||||||
*
|
*
|
||||||
* @return
|
* @return true when archive files are allowed
|
||||||
*/
|
*/
|
||||||
public static boolean allowArchive() {
|
public static boolean allowArchive() {
|
||||||
return ("true".equalsIgnoreCase(System.getenv().get("ALLOW_ARCHIVE_DATA")));
|
return checkAllowArchive.allowArchive();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -127,9 +155,11 @@ public class TimeTools {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a calendar that expresses the current system time based from specified
|
* Get a calendar that expresses the current system time based on specified
|
||||||
* date information if the
|
* date information or the current service time if not allowing archive.
|
||||||
* @param year Year to set.
|
*
|
||||||
|
* @param year
|
||||||
|
* Year to set.
|
||||||
* @param month
|
* @param month
|
||||||
* @param day
|
* @param day
|
||||||
* @param hour
|
* @param hour
|
||||||
|
@ -158,14 +188,18 @@ public class TimeTools {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Get Calendar with the time based on the timestamp at the end of the
|
||||||
|
* fileName.
|
||||||
*
|
*
|
||||||
* @param fileName
|
* @param fileName
|
||||||
* @return
|
* @return calendar
|
||||||
*/
|
*/
|
||||||
public static final Calendar getSystemCalendar(String fileName) {
|
public static final Calendar getSystemCalendar(String fileName) {
|
||||||
int year = -1;
|
int year = -1;
|
||||||
int month = -1;
|
int month = -1;
|
||||||
int day = -1;
|
int day = -1;
|
||||||
|
int hour = -1;
|
||||||
|
|
||||||
if (fileName != null) {
|
if (fileName != null) {
|
||||||
Matcher matcher = FILE_TIMESTAMP.matcher(fileName);
|
Matcher matcher = FILE_TIMESTAMP.matcher(fileName);
|
||||||
if (matcher.find()) {
|
if (matcher.find()) {
|
||||||
|
@ -174,6 +208,11 @@ public class TimeTools {
|
||||||
year = Integer.parseInt(yyyymmdd.substring(0, 4));
|
year = Integer.parseInt(yyyymmdd.substring(0, 4));
|
||||||
month = Integer.parseInt(yyyymmdd.substring(4, 6));
|
month = Integer.parseInt(yyyymmdd.substring(4, 6));
|
||||||
day = Integer.parseInt(yyyymmdd.substring(6, 8));
|
day = Integer.parseInt(yyyymmdd.substring(6, 8));
|
||||||
|
if (yyyymmdd.length() < 10) {
|
||||||
|
hour = 0;
|
||||||
|
} else {
|
||||||
|
hour = Integer.parseInt(yyyymmdd.substring(8, 10));
|
||||||
|
}
|
||||||
} catch (NumberFormatException nfe) {
|
} catch (NumberFormatException nfe) {
|
||||||
year = -1;
|
year = -1;
|
||||||
month = -1;
|
month = -1;
|
||||||
|
@ -181,7 +220,22 @@ public class TimeTools {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return getSystemCalendar(year, month, day, 0, 0);
|
return getSystemCalendar(year, month, day, hour, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the timestamp in the file name.
|
||||||
|
*
|
||||||
|
* @param fileName
|
||||||
|
* @return timestamp if it matches FILE_TIMESTAMP otherwise null
|
||||||
|
*/
|
||||||
|
public static final String getTimestamp(String fileName) {
|
||||||
|
String timestamp = null;
|
||||||
|
Matcher matcher = FILE_TIMESTAMP.matcher(fileName);
|
||||||
|
if (matcher.find()) {
|
||||||
|
timestamp = matcher.group(2);
|
||||||
|
}
|
||||||
|
return timestamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -197,8 +251,8 @@ public class TimeTools {
|
||||||
* @throws DataFormatException
|
* @throws DataFormatException
|
||||||
* if an error occurs
|
* if an error occurs
|
||||||
*/
|
*/
|
||||||
public static final Calendar findCurrentTime(String wmoDateStamp, String fileName)
|
public static final Calendar findCurrentTime(String wmoDateStamp,
|
||||||
throws DataFormatException {
|
String fileName) throws DataFormatException {
|
||||||
Calendar refCal = getSystemCalendar(fileName);
|
Calendar refCal = getSystemCalendar(fileName);
|
||||||
try {
|
try {
|
||||||
Matcher matcher = WMO_TIMESTAMP.matcher(wmoDateStamp);
|
Matcher matcher = WMO_TIMESTAMP.matcher(wmoDateStamp);
|
||||||
|
@ -209,7 +263,8 @@ public class TimeTools {
|
||||||
|
|
||||||
refCal = adjustDayHourMinute(refCal, iDay, iHour, iMinute);
|
refCal = adjustDayHourMinute(refCal, iDay, iHour, iMinute);
|
||||||
} else {
|
} else {
|
||||||
throw new ParseException("Invalid format - time does not match "
|
throw new ParseException(
|
||||||
|
"Invalid format - time does not match "
|
||||||
+ WMO_TIMESTAMP.pattern(), 0);
|
+ WMO_TIMESTAMP.pattern(), 0);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -302,8 +357,8 @@ public class TimeTools {
|
||||||
if (wmoDay <= maxDayThisMonth) {
|
if (wmoDay <= maxDayThisMonth) {
|
||||||
// First allow up to 3 hours into the next day
|
// First allow up to 3 hours into the next day
|
||||||
if ((cDay + 1) == wmoDay) {
|
if ((cDay + 1) == wmoDay) {
|
||||||
// This is potentially next month's data received early
|
// This is potentially next month's data received
|
||||||
// Allow three hours into the next day
|
// early. Allow three hours into the next day
|
||||||
if (wmoHour > 2) {
|
if (wmoHour > 2) {
|
||||||
// Back up a month
|
// Back up a month
|
||||||
cal.add(Calendar.MONTH, -1);
|
cal.add(Calendar.MONTH, -1);
|
||||||
|
@ -311,7 +366,8 @@ public class TimeTools {
|
||||||
} else {
|
} else {
|
||||||
// Back up a month
|
// Back up a month
|
||||||
cal.add(Calendar.MONTH, -1);
|
cal.add(Calendar.MONTH, -1);
|
||||||
int mDay = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
|
int mDay = cal
|
||||||
|
.getActualMaximum(Calendar.DAY_OF_MONTH);
|
||||||
if (mDay < wmoDay) {
|
if (mDay < wmoDay) {
|
||||||
cal.add(Calendar.MONTH, -1);
|
cal.add(Calendar.MONTH, -1);
|
||||||
}
|
}
|
||||||
|
@ -488,9 +544,10 @@ public class TimeTools {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Is the year valid. This method supposes any positive year
|
* Is the year valid. This method supposes any positive year value as valid.
|
||||||
* value as valid.
|
*
|
||||||
* @param year The year to check.
|
* @param year
|
||||||
|
* The year to check.
|
||||||
* @return Is the year valid?
|
* @return Is the year valid?
|
||||||
*/
|
*/
|
||||||
public static final boolean isValidYear(int year) {
|
public static final boolean isValidYear(int year) {
|
||||||
|
@ -499,7 +556,9 @@ public class TimeTools {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The the specified month of the year valid.
|
* The the specified month of the year valid.
|
||||||
* @param month Numeric value of the month.
|
*
|
||||||
|
* @param month
|
||||||
|
* Numeric value of the month.
|
||||||
* @return Is the month valid?
|
* @return Is the month valid?
|
||||||
*/
|
*/
|
||||||
public static final boolean isValidMonth(int month) {
|
public static final boolean isValidMonth(int month) {
|
||||||
|
@ -508,7 +567,9 @@ public class TimeTools {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Is the specified hour of the day valid? Range 0..23 inclusive.
|
* Is the specified hour of the day valid? Range 0..23 inclusive.
|
||||||
* @param hour The hour to check.
|
*
|
||||||
|
* @param hour
|
||||||
|
* The hour to check.
|
||||||
* @return Is the hour valid?
|
* @return Is the hour valid?
|
||||||
*/
|
*/
|
||||||
public static final boolean isValidHour(int hour) {
|
public static final boolean isValidHour(int hour) {
|
||||||
|
@ -517,20 +578,25 @@ public class TimeTools {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Is the specified minute/second valid? Range 0..59 inclusive.
|
* Is the specified minute/second valid? Range 0..59 inclusive.
|
||||||
* @param hour The minute/second to check.
|
*
|
||||||
|
* @param hour
|
||||||
|
* The minute/second to check.
|
||||||
* @return Is the minute/second valid?
|
* @return Is the minute/second valid?
|
||||||
*/
|
*/
|
||||||
public static final boolean isValidMinSec(int value) {
|
public static final boolean isValidMinSec(int value) {
|
||||||
return ((value > -1) && (value < MINUTES_HOUR));
|
return ((value > -1) && (value < MINUTES_HOUR));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Is a specified date valid? This method checks an entire
|
* Is a specified date valid? This method checks an entire year, month, day
|
||||||
* year, month, day timestamp.
|
* timestamp.
|
||||||
* @param year The year to check.
|
*
|
||||||
* @param month Numeric value of the month.
|
* @param year
|
||||||
* @param day Is the month valid?
|
* The year to check.
|
||||||
|
* @param month
|
||||||
|
* Numeric value of the month.
|
||||||
|
* @param day
|
||||||
|
* Is the month valid?
|
||||||
* @return Is year, month, day timestamp valid.
|
* @return Is year, month, day timestamp valid.
|
||||||
*/
|
*/
|
||||||
public static final boolean isValidDate(int year, int month, int day) {
|
public static final boolean isValidDate(int year, int month, int day) {
|
||||||
|
@ -549,135 +615,8 @@ public class TimeTools {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* End of month, end of year
|
* Disable constructor.
|
||||||
*
|
|
||||||
* @return test passed status
|
|
||||||
*/
|
*/
|
||||||
private static boolean test(String [] data) {
|
private TimeTools() {
|
||||||
String expected = data[3];
|
|
||||||
System.out.print(String.format("Test Step %12s ", data[0]));
|
|
||||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
||||||
Headers header = new Headers();
|
|
||||||
header.put(DecoderTools.INGEST_FILE_NAME, data[1]);
|
|
||||||
|
|
||||||
Calendar c = findDataTime(data[2],header);
|
|
||||||
sdf.setTimeZone(c.getTimeZone());
|
|
||||||
|
|
||||||
String cs = sdf.format(c.getTime());
|
|
||||||
System.out.print(String.format("%20s expected %20s ",cs, expected));
|
|
||||||
return expected.equals(cs);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final void main(String [] args) {
|
|
||||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
||||||
sdf.setTimeZone(TimeZone.getTimeZone(ZULU_TIMEZONE));
|
|
||||||
|
|
||||||
ITimeService service = new ITimeService() {
|
|
||||||
@Override
|
|
||||||
public Calendar getCalendar() {
|
|
||||||
final Calendar c = Calendar.getInstance();
|
|
||||||
c.setTimeZone(TimeZone.getTimeZone(ZULU_TIMEZONE));
|
|
||||||
c.set(Calendar.YEAR, 2011);
|
|
||||||
c.set(Calendar.MONTH, Calendar.JULY);
|
|
||||||
c.set(Calendar.DAY_OF_MONTH,15);
|
|
||||||
c.set(Calendar.HOUR_OF_DAY, 14);
|
|
||||||
c.set(Calendar.MINUTE, 15);
|
|
||||||
c.set(Calendar.SECOND, 32);
|
|
||||||
c.set(Calendar.MILLISECOND, 268);
|
|
||||||
|
|
||||||
return c;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
TimeTools.setTimeService(service);
|
|
||||||
|
|
||||||
if(allowArchive()) {
|
|
||||||
String [] [] archiveData = {
|
|
||||||
{ "test001","UANT01_CWAO_171653_225472224.20110717", "171653","2011-07-17 16:53:00", },
|
|
||||||
{ "test002","UANT01_CWAO_312315_225472224.20110731", "312315","2011-07-31 23:15:00", },
|
|
||||||
{ "test003","UANT01_CWAO_312315_225472224.20110801", "312315","2011-07-31 23:15:00", },
|
|
||||||
{ "test004","UANT01_CWAO_170000_225472224.20110716", "170000","2011-07-17 00:00:00", },
|
|
||||||
{ "test005","UANT01_CWAO_170000_225472224.20110717", "170000","2011-07-17 00:00:00", },
|
|
||||||
{ "test006","UANT01_CWAO_100000_225472224.20111109", "100000","2011-11-10 00:00:00", },
|
|
||||||
{ "test007","UANT01_CWAO_010000_225472224.20111231", "010000","2012-01-01 00:00:00", },
|
|
||||||
{ "test008","UANT01_CWAO_312350_225472224.20120101", "312350","2011-12-31 23:50:00", },
|
|
||||||
{ "test009","UANT01_CWAO_010259_225472224.20111231", "010259","2012-01-01 02:59:00", },
|
|
||||||
{ "test010","UANT01_CWAO_010300_225472224.20111231", "010300","2011-12-01 03:00:00", },
|
|
||||||
{ "test011","UANT01_CWAO_290050_225472224.20120228", "290050","2012-02-29 00:50:00", },
|
|
||||||
{ "test012","UANT01_CWAO_010100_225472224.20120229", "010100","2012-03-01 01:00:00", },
|
|
||||||
};
|
|
||||||
System.out.println("Performing archive mode data tests");
|
|
||||||
for(String [] d : archiveData) {
|
|
||||||
System.out.println(" status = " + (test(d) ? "passed" : "failed"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(!allowArchive()) {
|
|
||||||
System.out.println("Performing non-archive mode data tests");
|
|
||||||
|
|
||||||
System.out.println(String.format("Base time = %s", sdf.format(getSystemCalendar().getTime())));
|
|
||||||
// 2011-07-15 14:15:32.268
|
|
||||||
String[][] data = {
|
|
||||||
{ "test001", "UANT01_CWAO_171653_225472224.20110717", "171653",
|
|
||||||
"2011-06-17 16:53:00", },
|
|
||||||
{ "test002", "UANT01_CWAO_312315_225472224.20110731", "312315",
|
|
||||||
"2011-05-31 23:15:00", },
|
|
||||||
};
|
|
||||||
for (String[] d : data) {
|
|
||||||
System.out.println(" status = " + (test(d) ? "passed" : "failed"));
|
|
||||||
}
|
|
||||||
//**********************************************************************
|
|
||||||
service = new ITimeService() {
|
|
||||||
@Override
|
|
||||||
public Calendar getCalendar() {
|
|
||||||
final Calendar c = Calendar.getInstance();
|
|
||||||
c.setTimeZone(TimeZone.getTimeZone(ZULU_TIMEZONE));
|
|
||||||
c.set(Calendar.YEAR, 2011);
|
|
||||||
c.set(Calendar.MONTH, Calendar.AUGUST);
|
|
||||||
c.set(Calendar.DAY_OF_MONTH,1);
|
|
||||||
c.set(Calendar.HOUR_OF_DAY, 14);
|
|
||||||
c.set(Calendar.MINUTE, 15);
|
|
||||||
c.set(Calendar.SECOND, 32);
|
|
||||||
c.set(Calendar.MILLISECOND, 268);
|
|
||||||
|
|
||||||
return c;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
TimeTools.setTimeService(service);
|
|
||||||
System.out.println(String.format("Base time = %s", sdf.format(getSystemCalendar().getTime())));
|
|
||||||
|
|
||||||
data = new String [][] {
|
|
||||||
{ "test011", "UANT01_CWAO_312353_225472224.20110717", "312353",
|
|
||||||
"2011-07-31 23:53:00", },
|
|
||||||
};
|
|
||||||
for (String[] d : data) {
|
|
||||||
System.out.println(" status = " + (test(d) ? "passed" : "failed"));
|
|
||||||
}
|
|
||||||
//**********************************************************************
|
|
||||||
service = new ITimeService() {
|
|
||||||
@Override
|
|
||||||
public Calendar getCalendar() {
|
|
||||||
final Calendar c = Calendar.getInstance();
|
|
||||||
c.setTimeZone(TimeZone.getTimeZone(ZULU_TIMEZONE));
|
|
||||||
c.set(Calendar.YEAR, 2011);
|
|
||||||
c.set(Calendar.MONTH, Calendar.JULY);
|
|
||||||
c.set(Calendar.DAY_OF_MONTH,31);
|
|
||||||
c.set(Calendar.HOUR_OF_DAY, 22);
|
|
||||||
c.set(Calendar.MINUTE, 45);
|
|
||||||
c.set(Calendar.SECOND, 32);
|
|
||||||
c.set(Calendar.MILLISECOND, 268);
|
|
||||||
|
|
||||||
return c;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
TimeTools.setTimeService(service);
|
|
||||||
System.out.println(String.format("Base time = %s", sdf.format(getSystemCalendar().getTime())));
|
|
||||||
|
|
||||||
data = new String [][] {
|
|
||||||
{ "test011", "UANT01_CWAO_010053_225472224.20110717", "010053",
|
|
||||||
"2011-08-01 00:53:00", },
|
|
||||||
};
|
|
||||||
for (String[] d : data) {
|
|
||||||
System.out.println(" status = " + (test(d) ? "passed" : "failed"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,5 +76,6 @@
|
||||||
<classpathentry combineaccessrules="false" exported="true" kind="src" path="/com.raytheon.uf.common.dataplugin.level"/>
|
<classpathentry combineaccessrules="false" exported="true" kind="src" path="/com.raytheon.uf.common.dataplugin.level"/>
|
||||||
<classpathentry combineaccessrules="false" exported="true" kind="src" path="/com.raytheon.uf.common.dataplugin.grid"/>
|
<classpathentry combineaccessrules="false" exported="true" kind="src" path="/com.raytheon.uf.common.dataplugin.grid"/>
|
||||||
<classpathentry combineaccessrules="false" exported="true" kind="src" path="/com.raytheon.uf.edex.log"/>
|
<classpathentry combineaccessrules="false" exported="true" kind="src" path="/com.raytheon.uf.edex.log"/>
|
||||||
|
<classpathentry combineaccessrules="false" kind="src" path="/com.raytheon.uf.edex.decodertools"/>
|
||||||
<classpathentry kind="output" path="bin"/>
|
<classpathentry kind="output" path="bin"/>
|
||||||
</classpath>
|
</classpath>
|
||||||
|
|
|
@ -0,0 +1,234 @@
|
||||||
|
/**
|
||||||
|
* This software was developed and / or modified by Raytheon Company,
|
||||||
|
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
|
||||||
|
*
|
||||||
|
* U.S. EXPORT CONTROLLED TECHNICAL DATA
|
||||||
|
* This software product contains export-restricted data whose
|
||||||
|
* export/transfer/disclosure is restricted by U.S. law. Dissemination
|
||||||
|
* to non-U.S. persons whether in the United States or abroad requires
|
||||||
|
* an export license or other authorization.
|
||||||
|
*
|
||||||
|
* Contractor Name: Raytheon Company
|
||||||
|
* Contractor Address: 6825 Pine Street, Suite 340
|
||||||
|
* Mail Stop B8
|
||||||
|
* Omaha, NE 68106
|
||||||
|
* 402.291.0100
|
||||||
|
*
|
||||||
|
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
|
||||||
|
* further licensing information.
|
||||||
|
**/
|
||||||
|
package com.raytheon.uf.edex.decodertools.time;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.TimeZone;
|
||||||
|
|
||||||
|
import org.junit.BeforeClass;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import com.raytheon.edex.esb.Headers;
|
||||||
|
import com.raytheon.uf.edex.decodertools.core.DecoderTools;
|
||||||
|
import com.raytheon.uf.edex.decodertools.time.TimeTools.ICheckAllowArchive;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test {@link TimeTools}.
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
*
|
||||||
|
* SOFTWARE HISTORY
|
||||||
|
*
|
||||||
|
* Date Ticket# Engineer Description
|
||||||
|
* ------------ ---------- ----------- --------------------------
|
||||||
|
* Feb 19, 2013 1636 rferrel Initial creation
|
||||||
|
*
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* @author rferrel
|
||||||
|
* @version 1.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class TimeToolsAllowArchiveTest {
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public static void classSetup() {
|
||||||
|
TimeTools.checkAllowArchive = new ICheckAllowArchive() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean allowArchive() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
ITimeService service = new ITimeService() {
|
||||||
|
@Override
|
||||||
|
public Calendar getCalendar() {
|
||||||
|
final Calendar c = Calendar.getInstance();
|
||||||
|
c.setTimeZone(TimeZone.getTimeZone(TimeTools.ZULU_TIMEZONE));
|
||||||
|
c.set(Calendar.YEAR, 2011);
|
||||||
|
c.set(Calendar.MONTH, Calendar.JULY);
|
||||||
|
c.set(Calendar.DAY_OF_MONTH, 15);
|
||||||
|
c.set(Calendar.HOUR_OF_DAY, 14);
|
||||||
|
c.set(Calendar.MINUTE, 15);
|
||||||
|
c.set(Calendar.SECOND, 32);
|
||||||
|
c.set(Calendar.MILLISECOND, 268);
|
||||||
|
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
TimeTools.setTimeService(service);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* End of month, end of year
|
||||||
|
*
|
||||||
|
* @return test passed status
|
||||||
|
*/
|
||||||
|
static boolean test(String[] data) {
|
||||||
|
String expected = data[3];
|
||||||
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||||
|
Headers header = new Headers();
|
||||||
|
header.put(DecoderTools.INGEST_FILE_NAME, data[1]);
|
||||||
|
|
||||||
|
Calendar c = TimeTools.findDataTime(data[2], header);
|
||||||
|
sdf.setTimeZone(c.getTimeZone());
|
||||||
|
|
||||||
|
String cs = sdf.format(c.getTime());
|
||||||
|
return expected.equals(cs);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test() {
|
||||||
|
assertTrue(TimeTools.allowArchive());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test001() {
|
||||||
|
String[] data = new String[] { "test001",
|
||||||
|
"UANT01_CWAO_171653_225472224.20110717", "171653",
|
||||||
|
"2011-07-17 16:53:00" };
|
||||||
|
assertTrue(TimeToolsAllowArchiveTest.test(data));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test001H() {
|
||||||
|
String[] data = new String[] { "test001H",
|
||||||
|
"UANT01_CWAO_171653_225472224.2012091722", "171653",
|
||||||
|
"2012-09-17 16:53:00" };
|
||||||
|
assertTrue(TimeToolsAllowArchiveTest.test(data));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testShortTimestamp() {
|
||||||
|
String[] data = new String[] { "testShortTimestamp",
|
||||||
|
"UANT01_CWAO_171653_225472224.2011071", "171653",
|
||||||
|
"2011-07-17 16:53:00" };
|
||||||
|
assertFalse(TimeToolsAllowArchiveTest.test(data));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testLongTimestamp() {
|
||||||
|
String[] data = new String[] { "testLongTimestamp",
|
||||||
|
"UANT01_CWAO_171653_225472224.20110711235", "171653",
|
||||||
|
"2011-07-17 16:53:00" };
|
||||||
|
assertFalse(TimeToolsAllowArchiveTest.test(data));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testLongBadTimestamp() {
|
||||||
|
String[] data = new String[] { "testBadTimestamp",
|
||||||
|
"UANT01_CWAO_171653_225472224.201107114", "171653",
|
||||||
|
"2011-07-17 16:53:00" };
|
||||||
|
assertFalse(TimeToolsAllowArchiveTest.test(data));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test002() {
|
||||||
|
String[] data = new String[] { "test002",
|
||||||
|
"UANT01_CWAO_312315_225472224.20110731", "312315",
|
||||||
|
"2011-07-31 23:15:00", };
|
||||||
|
assertTrue(TimeToolsAllowArchiveTest.test(data));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test003() {
|
||||||
|
String[] data = new String[] { "test003",
|
||||||
|
"UANT01_CWAO_312315_225472224.20110801", "312315",
|
||||||
|
"2011-07-31 23:15:00", };
|
||||||
|
assertTrue(TimeToolsAllowArchiveTest.test(data));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test004() {
|
||||||
|
String[] data = new String[] { "test004",
|
||||||
|
"UANT01_CWAO_170000_225472224.20110716", "170000",
|
||||||
|
"2011-07-17 00:00:00", };
|
||||||
|
assertTrue(TimeToolsAllowArchiveTest.test(data));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test005() {
|
||||||
|
String[] data = new String[] { "test005",
|
||||||
|
"UANT01_CWAO_170000_225472224.20110717", "170000",
|
||||||
|
"2011-07-17 00:00:00", };
|
||||||
|
assertTrue(TimeToolsAllowArchiveTest.test(data));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test006() {
|
||||||
|
String[] data = new String[] { "test006",
|
||||||
|
"UANT01_CWAO_100000_225472224.20111109", "100000",
|
||||||
|
"2011-11-10 00:00:00", };
|
||||||
|
assertTrue(TimeToolsAllowArchiveTest.test(data));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test007() {
|
||||||
|
String[] data = new String[] { "test007",
|
||||||
|
"UANT01_CWAO_010000_225472224.20111231", "010000",
|
||||||
|
"2012-01-01 00:00:00", };
|
||||||
|
assertTrue(TimeToolsAllowArchiveTest.test(data));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test008() {
|
||||||
|
String[] data = new String[] { "test008",
|
||||||
|
"UANT01_CWAO_312350_225472224.20120101", "312350",
|
||||||
|
"2011-12-31 23:50:00", };
|
||||||
|
assertTrue(TimeToolsAllowArchiveTest.test(data));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test009() {
|
||||||
|
String[] data = new String[] { "test009",
|
||||||
|
"UANT01_CWAO_010259_225472224.20111231", "010259",
|
||||||
|
"2012-01-01 02:59:00", };
|
||||||
|
assertTrue(TimeToolsAllowArchiveTest.test(data));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test010() {
|
||||||
|
String[] data = new String[] { "test010",
|
||||||
|
"UANT01_CWAO_010300_225472224.20111231", "010300",
|
||||||
|
"2011-12-01 03:00:00", };
|
||||||
|
assertTrue(TimeToolsAllowArchiveTest.test(data));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test011() {
|
||||||
|
String[] data = new String[] { "test011",
|
||||||
|
"UANT01_CWAO_290050_225472224.20120228", "290050",
|
||||||
|
"2012-02-29 00:50:00", };
|
||||||
|
assertTrue(TimeToolsAllowArchiveTest.test(data));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test012() {
|
||||||
|
String[] data = new String[] { "test012",
|
||||||
|
"UANT01_CWAO_010100_225472224.20120229", "010100",
|
||||||
|
"2012-03-01 01:00:00", };
|
||||||
|
assertTrue(TimeToolsAllowArchiveTest.test(data));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,124 @@
|
||||||
|
/**
|
||||||
|
* This software was developed and / or modified by Raytheon Company,
|
||||||
|
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
|
||||||
|
*
|
||||||
|
* U.S. EXPORT CONTROLLED TECHNICAL DATA
|
||||||
|
* This software product contains export-restricted data whose
|
||||||
|
* export/transfer/disclosure is restricted by U.S. law. Dissemination
|
||||||
|
* to non-U.S. persons whether in the United States or abroad requires
|
||||||
|
* an export license or other authorization.
|
||||||
|
*
|
||||||
|
* Contractor Name: Raytheon Company
|
||||||
|
* Contractor Address: 6825 Pine Street, Suite 340
|
||||||
|
* Mail Stop B8
|
||||||
|
* Omaha, NE 68106
|
||||||
|
* 402.291.0100
|
||||||
|
*
|
||||||
|
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
|
||||||
|
* further licensing information.
|
||||||
|
**/
|
||||||
|
package com.raytheon.uf.edex.decodertools.time;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.TimeZone;
|
||||||
|
|
||||||
|
import org.junit.BeforeClass;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import com.raytheon.uf.edex.decodertools.time.TimeTools.ICheckAllowArchive;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test {@link TimeTools}.
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
*
|
||||||
|
* SOFTWARE HISTORY
|
||||||
|
*
|
||||||
|
* Date Ticket# Engineer Description
|
||||||
|
* ------------ ---------- ----------- --------------------------
|
||||||
|
* Feb 19, 2013 1636 rferrel Initial creation
|
||||||
|
*
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* @author rferrel
|
||||||
|
* @version 1.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class TimeToolsNoArchiveTest {
|
||||||
|
@BeforeClass
|
||||||
|
public static void classSetup() {
|
||||||
|
TimeTools.checkAllowArchive = new ICheckAllowArchive() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean allowArchive() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
ITimeService service = new ITimeService() {
|
||||||
|
@Override
|
||||||
|
public Calendar getCalendar() {
|
||||||
|
final Calendar c = Calendar.getInstance();
|
||||||
|
c.setTimeZone(TimeZone.getTimeZone(TimeTools.ZULU_TIMEZONE));
|
||||||
|
c.set(Calendar.YEAR, 2011);
|
||||||
|
c.set(Calendar.MONTH, Calendar.JULY);
|
||||||
|
c.set(Calendar.DAY_OF_MONTH, 15);
|
||||||
|
c.set(Calendar.HOUR_OF_DAY, 14);
|
||||||
|
c.set(Calendar.MINUTE, 15);
|
||||||
|
c.set(Calendar.SECOND, 32);
|
||||||
|
c.set(Calendar.MILLISECOND, 268);
|
||||||
|
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
TimeTools.setTimeService(service);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test() {
|
||||||
|
assertFalse(TimeTools.allowArchive());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test001() {
|
||||||
|
String[] data = new String[] { "test001",
|
||||||
|
"UANT01_CWAO_171653_225472224.20110717", "171653",
|
||||||
|
"2011-06-17 16:53:00", };
|
||||||
|
assertTrue(TimeToolsAllowArchiveTest.test(data));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test002() {
|
||||||
|
String[] data = new String[] { "test002",
|
||||||
|
"UANT01_CWAO_312315_225472224.20110731", "312315",
|
||||||
|
"2011-05-31 23:15:00", };
|
||||||
|
assertTrue(TimeToolsAllowArchiveTest.test(data));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test011() {
|
||||||
|
ITimeService service = new ITimeService() {
|
||||||
|
@Override
|
||||||
|
public Calendar getCalendar() {
|
||||||
|
final Calendar c = Calendar.getInstance();
|
||||||
|
c.setTimeZone(TimeZone.getTimeZone(TimeTools.ZULU_TIMEZONE));
|
||||||
|
c.set(Calendar.YEAR, 2011);
|
||||||
|
c.set(Calendar.MONTH, Calendar.JULY);
|
||||||
|
c.set(Calendar.DAY_OF_MONTH, 31);
|
||||||
|
c.set(Calendar.HOUR_OF_DAY, 22);
|
||||||
|
c.set(Calendar.MINUTE, 45);
|
||||||
|
c.set(Calendar.SECOND, 32);
|
||||||
|
c.set(Calendar.MILLISECOND, 268);
|
||||||
|
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
TimeTools.setTimeService(service);
|
||||||
|
String[] data = new String[] { "test011",
|
||||||
|
"UANT01_CWAO_312353_225472224.20110717", "312353",
|
||||||
|
"2011-07-31 23:53:00", };
|
||||||
|
assertTrue(TimeToolsAllowArchiveTest.test(data));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue