/** Parse a String into an Iso8601 Date */ public Iso8601Date parseIso8601Date(String value) { return new Iso8601Date(value); }
/** Parse a String into an Iso8601 Date */ public Iso8601Date parseIso8601Date(String value) { return new Iso8601Date(value); }
/** Parse a String into an Iso8601 Date */ public Iso8601Date parseIso8601Date(String value) { return new Iso8601Date(value); }
Iso8601Date decodeDate(final String dateStr) { try { return new Iso8601Date(dateStr); } catch (DateParser.InvalidDateException ex) { try { return new Iso8601Date(DateFormat.getDateTimeInstance().parse(dateStr)); } catch (ParseException e) { try { return new Iso8601Date(new Date(dateStr)); } catch (Exception e1) { throw new DateParser.InvalidDateException("Could not parse as date: " + dateStr, e); } } } } }
Iso8601Date decodeDate(final String dateStr) { try { return new Iso8601Date(dateStr); } catch (DateParser.InvalidDateException ex) { try { return new Iso8601Date(DateFormat.getDateTimeInstance().parse(dateStr)); } catch (ParseException e) { try { return new Iso8601Date(new Date(dateStr)); } catch (Exception e1) { throw new DateParser.InvalidDateException("Could not parse as date: " + dateStr, e); } } } } }
public Date getRunDate() { final String dt = getAttribute(DATE_RUN_PRODUCED_TAG); if (dt == null) return null; else return new Iso8601Date(dt); }
/** * Converts to Iso8601Date if not already in that form. */ public void setRunDate(Date runDate) { if (runDate != null && !(runDate instanceof Iso8601Date)) { runDate = new Iso8601Date(runDate); } setAttribute(DATE_RUN_PRODUCED_TAG, runDate != null ? runDate.toString() : null); }
/** * Converts to Iso8601Date if not already in that form. */ public void setRunDate(Date runDate) { if (runDate != null && !(runDate instanceof Iso8601Date)) { runDate = new Iso8601Date(runDate); } setAttribute(DATE_RUN_PRODUCED_TAG, runDate != null ? runDate.toString() : null); }
public Date getRunDate() { final String dt = getAttribute(DATE_RUN_PRODUCED_TAG); if (dt == null) return null; else return new Iso8601Date(dt); }
/** * Converts to Iso8601Date if not already in that form. */ public void setRunDate(Date runDate) { if (runDate != null && !(runDate instanceof Iso8601Date)) { runDate = new Iso8601Date(runDate); } setAttribute(DATE_RUN_PRODUCED_TAG, runDate != null ? runDate.toString() : null); }
public RelativeIso8601Date(final String dateStr) { /** * We must pass a date parsable {@link Iso8601Date#Iso8601Date(String)}; we will never actually read the passed value, so it doesn't * matter what it is. */ super(LAZY_NOW_LABEL.equals(dateStr) ? new Iso8601Date(new Date()).toString() : dateStr); doSetTimeNextQuery = LAZY_NOW_LABEL.equals(dateStr); }
public Date getRunDate() { final String dt = getAttribute(DATE_RUN_PRODUCED_TAG); if (dt == null) return null; else return new Iso8601Date(dt); }
public RelativeIso8601Date(final String dateStr) { /** * We must pass a date parsable {@link Iso8601Date#Iso8601Date(String)}; we will never actually read the passed value, so it doesn't * matter what it is. */ super(LAZY_NOW_LABEL.equals(dateStr) ? new Iso8601Date(new Date()).toString() : dateStr); doSetTimeNextQuery = LAZY_NOW_LABEL.equals(dateStr); }
public RelativeIso8601Date(final String dateStr) { /** * We must pass a date parsable {@link Iso8601Date#Iso8601Date(String)}; we will never actually read the passed value, so it doesn't * matter what it is. */ super(LAZY_NOW_LABEL.equals(dateStr) ? new Iso8601Date(new Date()).toString() : dateStr); doSetTimeNextQuery = LAZY_NOW_LABEL.equals(dateStr); }
@Test public void testBasic() { final String dateStr = "2008-12-15"; Iso8601Date first = new Iso8601Date(dateStr); String firstFormatted = first.toString(); Iso8601Date second = new Iso8601Date(firstFormatted); Assert.assertEquals(first, second); String secondFormatted = second.toString(); Assert.assertEquals(firstFormatted, secondFormatted); }
@Test public void testMillisecondTruncation() { // Create a Date with milliseconds final Date now = new Date(); if (now.getTime() % 1000 == 0) { now.setTime(now.getTime() + 3); } Iso8601Date isoDate = new Iso8601Date(now); Assert.assertEquals(isoDate.getTime() % 1000, 0); Assert.assertEquals(isoDate.getTime() / 1000, now.getTime() / 1000); } }
@Test public void equalityTest() { final String s = new Iso8601Date(new Date(12345)).toString(); final Iso8601Date iso8601Date = new Iso8601Date(s); final RelativeIso8601Date relativeIso8601Date = new RelativeIso8601Date(s); Assert.assertEquals(relativeIso8601Date.getTime(), iso8601Date.getTime(), DELTA_FOR_TIME); } }
@Test public void testLazyInstance() { final RelativeIso8601Date lazy = RelativeIso8601Date.generateLazyNowInstance(); Assert.assertEquals(lazy.toString(), RelativeIso8601Date.LAZY_NOW_LABEL); Assert.assertEquals(lazy.toString(), RelativeIso8601Date.LAZY_NOW_LABEL); Assert.assertEquals(lazy.toString(), RelativeIso8601Date.LAZY_NOW_LABEL); Assert.assertEquals(lazy.getTime(), new Iso8601Date(new Date(System.currentTimeMillis())).getTime(), DELTA_FOR_TIME); // Assert no exception thrown; this should be valid, because toString should now return an iso-looking date. new Iso8601Date(lazy.toString()); }
@Test public void testNonLazyInstance() { final long time = new Iso8601Date(new Date(System.currentTimeMillis())).getTime(); // ISO strips off milliseconds // Test both constructor methods final List<RelativeIso8601Date> testDates = Arrays.<RelativeIso8601Date>asList( new RelativeIso8601Date(new Date(time)), new RelativeIso8601Date(new Iso8601Date(new Date(time)).toString()) ); for (final RelativeIso8601Date nonLazy : testDates) { Assert.assertFalse(nonLazy.toString().equals(RelativeIso8601Date.LAZY_NOW_LABEL)); Assert.assertEquals((double) nonLazy.getTime(), (double) time, DELTA_FOR_TIME); // Assert no exception thrown; this should be valid, because toString return an iso-looking date. new RelativeIso8601Date(nonLazy.toString()); } }
@Test public void testSetNonIso8601Date() throws Exception { final SAMReadGroupRecord rg = new SAMReadGroupRecord("rg1"); // set not ISO 8601 date final Date date = new Date(); rg.setRunDate(date); // and assert that it is correctly wrapped Assert.assertEquals(rg.getRunDate(), new Iso8601Date(date)); }