SimpleDate implements Parcelable { public Date getDate() { return mDate; } SimpleDate(final long time); private  SimpleDate(final Date date); @Override boolean equals(final Object o); Date getDate(); CharSequence getRelativeDateTimeText(final Context context); CharSequence getRelativeTimeText(final Context context); @Override int hashCode(); boolean isInTheFuture(); @Override String toString(); @Override int describeContents(); @Override void writeToParcel(final Parcel dest, final int flags); static final Creator<SimpleDate> CREATOR; static final Comparator<SimpleDate> CHRONOLOGICAL_ORDER; static final Comparator<SimpleDate> REVERSE_CHRONOLOGICAL_ORDER; static final JsonDeserializer<SimpleDate> JSON_DESERIALIZER; static final JsonSerializer<SimpleDate> JSON_SERIALIZER; }
@Test public void testAmPmDateConstruction() throws Exception { SimpleDate sd = mConstructor.newInstance(mAmPmFormat.parse(AM_PM_DATE_0)); assertNotNull(sd); final Calendar calendar = Calendar.getInstance(); calendar.setTime(sd.getDate()); assertEquals(calendar.get(Calendar.YEAR), 1998); assertEquals(calendar.get(Calendar.MONTH), Calendar.FEBRUARY); assertEquals(calendar.get(Calendar.DAY_OF_MONTH), 2); assertEquals(calendar.get(Calendar.HOUR), 4); assertEquals(calendar.get(Calendar.MINUTE), 34); assertEquals(calendar.get(Calendar.SECOND), 20); assertEquals(calendar.get(Calendar.AM_PM), Calendar.AM); sd = mConstructor.newInstance(mAmPmFormat.parse(AM_PM_DATE_1)); assertNotNull(sd); calendar.setTime(sd.getDate()); assertEquals(calendar.get(Calendar.YEAR), 2000); assertEquals(calendar.get(Calendar.MONTH), Calendar.JUNE); assertEquals(calendar.get(Calendar.DAY_OF_MONTH), 8); assertEquals(calendar.get(Calendar.HOUR), 8); assertEquals(calendar.get(Calendar.MINUTE), 10); assertEquals(calendar.get(Calendar.SECOND), 59); assertEquals(calendar.get(Calendar.AM_PM), Calendar.PM); sd = mConstructor.newInstance(mAmPmFormat.parse(AM_PM_DATE_2)); assertNotNull(sd); calendar.setTime(sd.getDate()); assertEquals(calendar.get(Calendar.YEAR), 2012); assertEquals(calendar.get(Calendar.MONTH), Calendar.DECEMBER); assertEquals(calendar.get(Calendar.DAY_OF_MONTH), 28); assertEquals(calendar.get(Calendar.HOUR), 0); assertEquals(calendar.get(Calendar.MINUTE), 0); assertEquals(calendar.get(Calendar.SECOND), 0); assertEquals(calendar.get(Calendar.AM_PM), Calendar.AM); }
@Test public void testArmyDateConstruction() throws Exception { SimpleDate sd = mConstructor.newInstance(mArmyFormat.parse(ARMY_DATE_0)); assertNotNull(sd); final Calendar calendar = Calendar.getInstance(); calendar.setTime(sd.getDate()); assertEquals(calendar.get(Calendar.YEAR), 2015); assertEquals(calendar.get(Calendar.MONTH), Calendar.SEPTEMBER); assertEquals(calendar.get(Calendar.DAY_OF_MONTH), 26); assertEquals(calendar.get(Calendar.HOUR_OF_DAY), 0); assertEquals(calendar.get(Calendar.MINUTE), 0); assertEquals(calendar.get(Calendar.SECOND), 0); sd = mConstructor.newInstance(mArmyFormat.parse(ARMY_DATE_1)); assertNotNull(sd); calendar.setTime(sd.getDate()); assertEquals(calendar.get(Calendar.YEAR), 1989); assertEquals(calendar.get(Calendar.MONTH), Calendar.NOVEMBER); assertEquals(calendar.get(Calendar.DAY_OF_MONTH), 28); assertEquals(calendar.get(Calendar.HOUR_OF_DAY), 13); assertEquals(calendar.get(Calendar.MINUTE), 41); assertEquals(calendar.get(Calendar.SECOND), 26); }
@Test public void testExtendedDateConstruction() throws Exception { String dateString = (String) mFixTimeZone.invoke(null, EXTENDED_DATE_0); SimpleDate sd = mConstructor.newInstance(mExtendedFormat.parse(dateString)); assertNotNull(sd); final Calendar calendar = Calendar.getInstance(); calendar.setTime(sd.getDate()); assertEquals(calendar.get(Calendar.YEAR), 2013); assertEquals(calendar.get(Calendar.MONTH), Calendar.FEBRUARY); assertEquals(calendar.get(Calendar.DAY_OF_MONTH), 20); dateString = (String) mFixTimeZone.invoke(null, EXTENDED_DATE_1); sd = mConstructor.newInstance(mExtendedFormat.parse(dateString)); assertNotNull(sd); calendar.setTime(sd.getDate()); assertEquals(calendar.get(Calendar.YEAR), 2015); assertEquals(calendar.get(Calendar.MONTH), Calendar.AUGUST); assertEquals(calendar.get(Calendar.DAY_OF_MONTH), 6); }
@Test public void testShortDateConstruction() throws Exception { SimpleDate sd = mConstructor.newInstance(mShortFormat.parse(SHORT_DATE_0)); assertNotNull(sd); final Calendar calendar = Calendar.getInstance(); calendar.setTime(sd.getDate()); assertEquals(calendar.get(Calendar.YEAR), 2013); assertEquals(calendar.get(Calendar.MONTH), Calendar.JULY); assertEquals(calendar.get(Calendar.DAY_OF_MONTH), 18); sd = mConstructor.newInstance(mShortFormat.parse(SHORT_DATE_1)); assertNotNull(sd); calendar.setTime(sd.getDate()); assertEquals(calendar.get(Calendar.YEAR), 2016); assertEquals(calendar.get(Calendar.MONTH), Calendar.MARCH); assertEquals(calendar.get(Calendar.DAY_OF_MONTH), 4); }