/** * 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); }
result[0] = new GregorianDate(yr4, doy, result[0].getHour(), result[0].getMinute(), result[0].getSecond()); return true;
zeroPad(result, dt.getMinute(), tokLen == 1 ? 1 : 2); break;
@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 testYearDayConstructor() { ZonedDateTime aTime = DateTimeHelper.create(2000, 2, 28, 1, 3, 4); Assert.assertEquals((int) 31 + 28, (int) aTime.getDayOfYear()); //* January has 31 days, so add 28 to that... GregorianDate sameDate = new GregorianDate(aTime.getYear(), aTime.getDayOfYear()); Assert.assertEquals((int) 2000, (int) sameDate.getYear()); Assert.assertEquals((int) 59, (int) sameDate.getDayOfYear()); Assert.assertEquals((int) 2, (int) sameDate.getMonth()); Assert.assertEquals((int) 0, (int) sameDate.getHour()); Assert.assertEquals((int) 0, (int) sameDate.getMinute()); Assert.assertEquals(0, sameDate.getSecond(), 0d); sameDate = new GregorianDate(2000, 60.6); //* 60 days and 14.4 hours, or 14 hours and 24 minutes (1/10 of a day is 2.4 hours, times that by 6) Assert.assertEquals((int) 2000, (int) sameDate.getYear()); Assert.assertEquals((int) 60, (int) sameDate.getDayOfYear()); Assert.assertEquals((int) 2, (int) sameDate.getMonth()); //* leap year Assert.assertEquals((int) 14, (int) sameDate.getHour()); Assert.assertEquals((int) 24, (int) sameDate.getMinute()); Assert.assertEquals(0D, sameDate.getSecond(), Constants.Epsilon9); //* Richard and Michael both said this is ok }
@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) 23, (int) gd.getDay()); Assert.assertEquals((int) 12, (int) gd.getHour()); Assert.assertEquals((int) 5, (int) gd.getMinute()); Assert.assertEquals(30.300, gd.getSecond(), Constants.Epsilon11); Assert.assertEquals((int) 23, (int) gd.getDay()); Assert.assertEquals((int) 0, (int) gd.getHour()); Assert.assertEquals((int) 0, (int) gd.getMinute()); Assert.assertEquals(0.0, gd.getSecond(), Constants.Epsilon11); Assert.assertEquals((int) 23, (int) gd.getDay()); Assert.assertEquals((int) 23, (int) gd.getHour()); Assert.assertEquals((int) 59, (int) gd.getMinute()); Assert.assertEquals(59.999, gd.getSecond(), Constants.Epsilon11);