/** * Rounds this instance to the specified number of decimal digits in the seconds, rolling over to minutes, hours, days, etc. as necessary. If the specified {@code timeStandard} is {@link TimeStandard#COORDINATED_UNIVERSAL_TIME}, (UTC), the seconds will be allowed to go above 60 during a leap second. For any other time standard, the {@code Second} ({@link #getSecond get}) will be below 60. * @param digits The number of digits after the decimal point to include in the seconds. * @param timeStandard The time standard in which this {@link GregorianDate} is expressed. * @return The rounded date. */ @CS2JWarning("Unhandled attribute removed: Pure") @Nonnull public final GregorianDate roundSeconds(int digits, @Nonnull TimeStandard timeStandard) { double roundedSeconds = MathHelper.round(m_second, digits); double secondsDifference = roundedSeconds - m_second; // no need to rollover if rounding down or within same minute if (roundedSeconds < 60.0 || secondsDifference <= 0) { return new GregorianDate(getYear(), getMonth(), getDay(), getHour(), getMinute(), roundedSeconds); } return rolloverTime(0D, 0D, 0D, secondsDifference, timeStandard); }
tokLen = countRepeat(format, i, ch); if (tokLen <= 2) { zeroPad(result, dt.getDay(), tokLen == 1 ? 1 : 2); } else if (tokLen == 3) { result.append(dfi.getAbbreviatedDayName(dt.getDayOfWeek()));
@Test public final void julianDateGregorianDateRoundTrip() { GregorianDate gregorianDate = new GregorianDate(2008, 1, 1, 1, 1, 1.00000000008); JulianDate julianDate = new JulianDate(gregorianDate); GregorianDate roundTrip = julianDate.toGregorianDate(); Assert.assertEquals((int) gregorianDate.getYear(), (int) roundTrip.getYear()); Assert.assertEquals((int) gregorianDate.getMonth(), (int) roundTrip.getMonth()); Assert.assertEquals((int) gregorianDate.getDay(), (int) roundTrip.getDay()); Assert.assertEquals((int) gregorianDate.getHour(), (int) roundTrip.getHour()); Assert.assertEquals((int) gregorianDate.getMinute(), (int) roundTrip.getMinute()); Assert.assertEquals(gregorianDate.getSecond(), roundTrip.getSecond(), Constants.Epsilon13); }
@Test public final void canConvertToJulianDate() { { GregorianDate gregorianDate = new GregorianDate(2008, 10, 23, 23, 59, 59.999); JulianDate julianDate = gregorianDate.toJulianDate(); GregorianDate newGregorianDate = new GregorianDate(julianDate); Assert.assertEquals((int) gregorianDate.getYear(), (int) newGregorianDate.getYear()); Assert.assertEquals((int) gregorianDate.getMonth(), (int) newGregorianDate.getMonth()); Assert.assertEquals((int) gregorianDate.getDay(), (int) newGregorianDate.getDay()); Assert.assertEquals((int) gregorianDate.getHour(), (int) newGregorianDate.getHour()); Assert.assertEquals((int) gregorianDate.getMinute(), (int) newGregorianDate.getMinute()); Assert.assertEquals(gregorianDate.getSecond(), newGregorianDate.getSecond(), Constants.Epsilon11); } { GregorianDate gregorianDate = new GregorianDate(2008, 10, 23, 1, 1, 1D); JulianDate julianDate = gregorianDate.toJulianDate(); GregorianDate newGregorianDate = new GregorianDate(julianDate); Assert.assertEquals((int) gregorianDate.getYear(), (int) newGregorianDate.getYear()); Assert.assertEquals((int) gregorianDate.getMonth(), (int) newGregorianDate.getMonth()); Assert.assertEquals((int) gregorianDate.getDay(), (int) newGregorianDate.getDay()); Assert.assertEquals((int) gregorianDate.getHour(), (int) newGregorianDate.getHour()); Assert.assertEquals((int) gregorianDate.getMinute(), (int) newGregorianDate.getMinute()); Assert.assertEquals(gregorianDate.getSecond(), newGregorianDate.getSecond(), Constants.Epsilon11); } }
@Test public final void canConstructGregorianDate() { GregorianDate gd = new GregorianDate(2000, 1, 2, 6, 30, 15D); Assert.assertEquals((int) 2000, (int) gd.getYear()); Assert.assertEquals((int) 1, (int) gd.getMonth()); Assert.assertEquals((int) 2, (int) gd.getDay()); Assert.assertEquals((int) 6, (int) gd.getHour()); Assert.assertEquals((int) 30, (int) gd.getMinute()); Assert.assertEquals(15, gd.getSecond(), 0d); gd = new GregorianDate(2000, 1, 2); Assert.assertEquals((int) 2000, (int) gd.getYear()); Assert.assertEquals((int) 1, (int) gd.getMonth()); Assert.assertEquals((int) 2, (int) gd.getDay()); Assert.assertEquals((int) 0, (int) gd.getHour()); Assert.assertEquals((int) 0, (int) gd.getMinute()); Assert.assertEquals(0, gd.getSecond(), 0d); }
@Test public final void julianToGregorianDate() { JulianDate julianDate = new JulianDate(2451545.0, TimeStandard.COORDINATED_UNIVERSAL_TIME); GregorianDate gregorianDate = julianDate.toGregorianDate(); Assert.assertEquals((int) 2000, (int) gregorianDate.getYear()); Assert.assertEquals((int) 1, (int) gregorianDate.getMonth()); Assert.assertEquals((int) 1, (int) gregorianDate.getDay()); Assert.assertEquals((int) 12, (int) gregorianDate.getHour()); Assert.assertEquals((int) 0, (int) gregorianDate.getMinute()); Assert.assertEquals(0, gregorianDate.getSecond(), 0d); julianDate = new JulianDate(2453736.5, TimeStandard.COORDINATED_UNIVERSAL_TIME); gregorianDate = julianDate.toGregorianDate(); Assert.assertEquals((int) 2006, (int) gregorianDate.getYear()); Assert.assertEquals((int) 1, (int) gregorianDate.getMonth()); Assert.assertEquals((int) 1, (int) gregorianDate.getDay()); Assert.assertEquals((int) 0, (int) gregorianDate.getHour()); Assert.assertEquals((int) 0, (int) gregorianDate.getMinute()); Assert.assertEquals(0, gregorianDate.getSecond(), 0d); julianDate = new JulianDate(2441683.5, TimeStandard.COORDINATED_UNIVERSAL_TIME); gregorianDate = julianDate.toGregorianDate(); Assert.assertEquals((int) 1973, (int) gregorianDate.getYear()); Assert.assertEquals((int) 1, (int) gregorianDate.getMonth()); Assert.assertEquals((int) 1, (int) gregorianDate.getDay()); Assert.assertEquals((int) 0, (int) gregorianDate.getHour()); Assert.assertEquals((int) 0, (int) gregorianDate.getMinute()); Assert.assertEquals(0, gregorianDate.getSecond(), 0d); julianDate = new JulianDate(2441683.5, TimeStandard.COORDINATED_UNIVERSAL_TIME); GregorianDate internationalTimeGregorianDate = julianDate.toGregorianDate(TimeStandard.INTERNATIONAL_ATOMIC_TIME); AssertHelper.assertNotEqual(gregorianDate, internationalTimeGregorianDate); }
Assert.assertEquals((int) 2008, (int) gd.getYear()); Assert.assertEquals((int) 10, (int) gd.getMonth()); Assert.assertEquals((int) 23, (int) gd.getDay()); Assert.assertEquals((int) 12, (int) gd.getHour()); Assert.assertEquals((int) 5, (int) gd.getMinute()); Assert.assertEquals((int) 2008, (int) gd.getYear()); Assert.assertEquals((int) 10, (int) gd.getMonth()); Assert.assertEquals((int) 23, (int) gd.getDay()); Assert.assertEquals((int) 0, (int) gd.getHour()); Assert.assertEquals((int) 0, (int) gd.getMinute()); Assert.assertEquals((int) 2008, (int) gd.getYear()); Assert.assertEquals((int) 10, (int) gd.getMonth()); Assert.assertEquals((int) 23, (int) gd.getDay()); Assert.assertEquals((int) 23, (int) gd.getHour()); Assert.assertEquals((int) 59, (int) gd.getMinute());