/** * Converts a datetime string into and instance of java.util.Date using the * date format: yyyy-MM-ddTHH:mm:ss.SSSZ. * * @param dateTime * A datetime string * @return Corresponding instance of java.util.Date (returns null if * dateTime string argument is empty string or null) */ public static Date convertStringToDate(String dateTime) { return parseDateLoose(dateTime); }
/** * Converts a datetime string into and instance of java.util.Date using the * date format: yyyy-MM-ddTHH:mm:ss.SSSZ. * * @param dateTime * A datetime string * @return Corresponding instance of java.util.Date (returns null if * dateTime string argument is empty string or null) */ public static Date convertStringToDate(String dateTime) { return parseDateLoose(dateTime); }
public static boolean isStaleCache(Context context, Property[] headers) { String ifNoneMatch = context.getHeaderValue(INM_KEY); String ifModSince = context.getHeaderValue(IMS_KEY); if (ifModSince == null && ifNoneMatch == null) return true; // parse out the data for comparison Date imsDate = (ifModSince == null) ? null : DateUtility.parseDateLoose(ifModSince); long ims = (imsDate == null) ? Long.MIN_VALUE : imsDate.getTime(); // get the local comparison values String etag = null; long lastMod = Long.MAX_VALUE; for (Property header: headers) { if (HttpHeaders.ETAG.equalsIgnoreCase(header.name)) etag = header.value; if (HttpHeaders.LAST_MODIFIED.equalsIgnoreCase(header.name)) { Date d = DateUtility.parseDateLoose(header.value); if (d != null) lastMod = d.getTime(); } } if (ifNoneMatch != null && !ifNoneMatch.equals(etag)) return true; return (ifModSince != null && ims < lastMod); }
public static boolean isStaleCache(Context context, Property[] headers) { String ifNoneMatch = context.getHeaderValue(INM_KEY); String ifModSince = context.getHeaderValue(IMS_KEY); if (ifModSince == null && ifNoneMatch == null) return true; // parse out the data for comparison Date imsDate = (ifModSince == null) ? null : DateUtility.parseDateLoose(ifModSince); long ims = (imsDate == null) ? Long.MIN_VALUE : imsDate.getTime(); // get the local comparison values String etag = null; long lastMod = Long.MAX_VALUE; for (Property header: headers) { if (HttpHeaders.ETAG.equalsIgnoreCase(header.name)) etag = header.value; if (HttpHeaders.LAST_MODIFIED.equalsIgnoreCase(header.name)) { Date d = DateUtility.parseDateLoose(header.value); if (d != null) lastMod = d.getTime(); } } if (ifNoneMatch != null && !ifNoneMatch.equals(etag)) return true; return (ifModSince != null && ims < lastMod); }
throw new IOException("A row was returned, but it did not contain a 'date' binding"); return DateUtility.parseDateLoose(dateLiteral .getLexicalForm()); } else { if (header != null) { String lastModified = header.getValue(); return DateUtility.parseDateLoose(lastModified); } else {
@Test public void testParseDate() { String[] dates = { "1970-01-01T00:00:00.000Z", "1970-01-01T00:00:00.00Z", "1970-01-01T00:00:00.0Z", "1970-01-01T00:00:00Z", "1970-01-01Z", "1970-01-01T00:00:00.000", "1970-01-01T00:00:00.00", "1970-01-01T00:00:00.0", "1970-01-01T00:00:00", "1970-01-01", "Thu, 01 Jan 1970 00:00:00 GMT" }; for (String element : dates) { assertEquals(EPOCH, DateUtility.parseDateLoose(element)); } // why would "12345-01-01T00:00:00.000Z" be a bad date?? // i commented this out since it's quite reasonable. // but it would also be possible to check if the year has passed a // certain threshold and return null String[] badDates = { "", "ABCD-EF-GHTIJ:KL:MN.OPQZ", "1234", "1", "1970-01", "1970-1-1", /* "12345-01-01T00:00:00.000Z",*/ "12345-01-01T00:00:00." }; for (String element : badDates) { assertNull(element + " not null", DateUtility.parseDateLoose(element)); } // i think this was wrong since it used a different format for input // then all the other tests, so i switched the usage to the non XSD variables assertEquals(ONE_CE, DateUtility.parseDateLoose(ONE_CE_DT)); assertEquals(ONE_BCE, DateUtility.parseDateLoose(ONE_BCE_DT)); assertEquals(TWO_BCE, DateUtility.parseDateLoose(TWO_BCE_DT)); }
wellFormedDates = new ArrayList<Date>(); Date p = DateUtility.parseDateLoose(dc.dates().get(i).getValue()); if (p != null) { wellFormedDates.add(p);
wellFormedDates = new ArrayList<Date>(); Date p = DateUtility.parseDateLoose(dc.dates().get(i).getValue()); if (p != null) { wellFormedDates.add(p);