/** Returns a "lazy now" instance. */ public static RelativeIso8601Date generateLazyNowInstance() { return new RelativeIso8601Date(LAZY_NOW_LABEL); }
@Override public boolean before(final Date when) { conditionallyUpdateTime(); return super.before(when); }
@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 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()); }
@Override public int compareTo(final Date anotherDate) { conditionallyUpdateTime(); return super.compareTo(anotherDate); }
/** Returns a "lazy now" instance. */ public static RelativeIso8601Date generateLazyNowInstance() { return new RelativeIso8601Date(LAZY_NOW_LABEL); }
@Override @Deprecated public int getHours() { conditionallyUpdateTime(); return super.getHours(); }
/** Returns a "lazy now" instance. */ public static RelativeIso8601Date generateLazyNowInstance() { return new RelativeIso8601Date(LAZY_NOW_LABEL); }
@Override public long getTime() { conditionallyUpdateTime(); return super.getTime(); }
@Override @Deprecated public int getDate() { conditionallyUpdateTime(); return super.getDate(); }
@Override @Deprecated public int getMonth() { conditionallyUpdateTime(); return super.getMonth(); }
@Override public boolean equals(final Object obj) { conditionallyUpdateTime(); return super.equals(obj); }
@Override @Deprecated public int getDate() { conditionallyUpdateTime(); return super.getDate(); }
@Override @Deprecated public int getDay() { conditionallyUpdateTime(); return super.getDay(); }
@Override @Deprecated public int getMinutes() { conditionallyUpdateTime(); return super.getMinutes(); }
@Override @Deprecated public int getTimezoneOffset() { conditionallyUpdateTime(); return super.getTimezoneOffset(); }
@Override public Object clone() { conditionallyUpdateTime(); return super.clone(); }
@Override public int getDate() { conditionallyUpdateTime(); return super.getDate(); }
@Override @Deprecated public int getMonth() { conditionallyUpdateTime(); return super.getMonth(); }