/** * Converts the value of this instance to its equivalent string representation. * @return A string representation of value of this instance. */ @Override public String toString() { return toString(null, null); }
/** * Converts the value of this instance to its equivalent short time string representation. * @return A string containing the name of the day of the week, the name of the month, the numeric day of the hours, minutes, and seconds equivalent to the time value of this instance. */ @CS2JWarning("Unhandled attribute removed: Pure") @Nonnull public final String toShortTimeString() { return toString("t"); }
/** * Converts the value of this instance to its equivalent long date string representation. * @return A string containing the name of the day of the week, the name of the month, the numeric day of the month, and the year equivalent to the date value of this instance. */ @CS2JWarning("Unhandled attribute removed: Pure") @Nonnull public final String toLongDateString() { return toString("D"); }
/** * Converts the value of this instance to its equivalent long time string representation. * @return A string containing the name of the day of the week, the name of the month, the numeric day of the hours, minutes, and seconds equivalent to the time value of this instance. */ @CS2JWarning("Unhandled attribute removed: Pure") @Nonnull public final String toLongTimeString() { return toString("T"); }
/** * Converts the value of this instance to its equivalent string representation using the specified culture-specific format information. * @param provider An {@link Locale} that supplies culture-specific formatting information. * @return A string representation of value of this instance as specified by {@code provider}. */ @CS2JWarning("Unhandled attribute removed: Pure") @Nonnull public final String toString(@Nullable Locale provider) { return toString(null, provider); }
/** * Converts the value of this instance to its equivalent short date string representation. * @return A string containing the numeric month, the numeric day of the month, and the year equivalent to the date value of this instance. */ @CS2JWarning("Unhandled attribute removed: Pure") @Nonnull public final String toShortDateString() { return toString("d"); }
/** * Converts the value of this instance to its equivalent string representation using the specified format. * @param format A format string. * @return A string representation of value of this instance as specified by {@code format}. * @exception NumberFormatException Thrown if the length of {@code format} is 1, and it is not one of the format specifier characters defined for {@link DateTimeFormatInfo}, or if {@code format} does not contain a valid custom format pattern. */ @CS2JWarning("Unhandled attribute removed: Pure") @Nonnull public final String toString(@Nullable String format) { return toString(format, null); }
@Test public final void secondsAreCorrectlyFormattedToDifferentNumbersOfDigits() { GregorianDate first = new GregorianDate(2009, 2, 7, 5, 41, 44.408); Assert.assertEquals("44.408", first.toString("ss.fff", m_cultureInfo)); Assert.assertEquals("44.4080", first.toString("ss.ffff", m_cultureInfo)); Assert.assertEquals("44.40800", first.toString("ss.fffff", m_cultureInfo)); }
@Test public final void wholeNumberSecondsIsFormattedCorrectly() { GregorianDate gd = new GregorianDate(2012, 8, 7, 13, 59, 55.0); Assert.assertEquals("2012-08-07 13:59:55.000000", gd.toString("yyyy-MM-dd HH:mm:ss.ffffff", m_cultureInfo)); gd = new GregorianDate(2012, 8, 7, 13, 59, 55.0); Assert.assertEquals("2012-08-07 13:59:55", gd.toString("yyyy-MM-dd HH:mm:ss", m_cultureInfo)); gd = new GregorianDate(2012, 8, 7, 13, 59, 55.0); Assert.assertEquals("2012-08-07 13:59:55", gd.toString("yyyy-MM-dd HH:mm:ss.FFFFFF", m_cultureInfo)); }
@Test public final void testFormattingLeapSecond() { GregorianDate date = new GregorianDate(2008, 12, 31, 23, 59, 60.444); Assert.assertEquals("31 Dec 2008 23:59:60.444", date.toString("d MMM yyyy H:mm:ss.fff", m_cultureInfo)); }
@Test public final void fractionalSecondsCloseToZeroAreFormattedCorrectly() { // Based on BUG71966: GregorianDate.ToString(format) produces incorrect value for fractional seconds cesiumlanguagewriter.GregorianDate date = new GregorianDate(2012, 2, 25, 0, 15, 0.000000000014551915228366852); Assert.assertEquals("001500.0000000", date.toString("HHmmss.fffffff", m_cultureInfo)); }
@Test public final void toStringTruncatesSeconds() { GregorianDate gd = new GregorianDate(2012, 8, 7, 13, 59, 59.9999999); Assert.assertEquals("2012-08-07 13:59:59.999999", gd.toString("yyyy-MM-dd HH:mm:ss.ffffff", m_cultureInfo)); }
@Test public final void testToString() { GregorianDate date = new GregorianDate(2002, 2, 25, 5, 25, 13D); Assert.assertEquals("2/25/2002", date.toString("d", m_cultureInfo)); Assert.assertEquals("Monday, February 25, 2002", date.toString("D", m_cultureInfo)); Assert.assertEquals("Monday, February 25, 2002 5:25 AM", date.toString("f", m_cultureInfo)); Assert.assertEquals("Monday, February 25, 2002 5:25:13 AM", date.toString("F", m_cultureInfo)); Assert.assertEquals("2/25/2002 5:25 AM", date.toString("g", m_cultureInfo)); Assert.assertEquals("2/25/2002 5:25:13 AM", date.toString("G", m_cultureInfo)); Assert.assertEquals("February 25", date.toString("m", m_cultureInfo)); Assert.assertEquals("February 25", date.toString("M", m_cultureInfo)); Assert.assertEquals("Mon, 25 Feb 2002 05:25:13 GMT", date.toString("r", m_cultureInfo)); Assert.assertEquals("Mon, 25 Feb 2002 05:25:13 GMT", date.toString("R", m_cultureInfo)); Assert.assertEquals("2002-02-25T05:25:13", date.toString("s", m_cultureInfo)); Assert.assertEquals("5:25 AM", date.toString("t", m_cultureInfo)); Assert.assertEquals("5:25:13 AM", date.toString("T", m_cultureInfo)); Assert.assertEquals("2002-02-25 05:25:13Z", date.toString("u", m_cultureInfo)); String smallY = date.toString("y", m_cultureInfo); Assert.assertTrue(ObjectHelper.equals(smallY, "February, 2002") || ObjectHelper.equals(smallY, "February 2002")); String bigY = date.toString("Y", m_cultureInfo); Assert.assertTrue(ObjectHelper.equals(bigY, "February, 2002") || ObjectHelper.equals(bigY, "February 2002")); Assert.assertEquals("2/25/2002 5:25:13 AM", date.toString("", m_cultureInfo)); Assert.assertEquals("25", date.toString("%d", m_cultureInfo)); Assert.assertEquals("25", date.toString("dd", m_cultureInfo)); Assert.assertEquals("Mon", date.toString("ddd", m_cultureInfo)); Assert.assertEquals("Monday", date.toString("dddd", m_cultureInfo)); Assert.assertEquals("2", date.toString("%M", m_cultureInfo)); Assert.assertEquals("02", date.toString("MM", m_cultureInfo)); Assert.assertEquals("Feb", date.toString("MMM", m_cultureInfo));
@Test public final void testToStringFormatProvider() { GregorianDate gd1 = new GregorianDate(2001, 1, 1, 6, 3, 14D); Assert.assertEquals("1/1/2001 6:03:14 AM", gd1.toString(CultureInfoHelper.create("en-US"))); gd1 = new GregorianDate(2003, 3, 4, 16, 43, 23.23452); Assert.assertEquals("3/4/2003 4:43:23 PM", gd1.toString(CultureInfoHelper.create("en-US"))); }
@Test public final void toStringThrowsOnInvalidFormatSpecifier() { ExpectedExceptionHelper.expectException(getRule$expectedException(), NumberFormatException.class); String unused = new GregorianDate(2009, 6, 10).toString("X"); }
@Test public final void cantFormatMoreThan15FractionalSeconds() { ExpectedExceptionHelper.expectException(getRule$expectedException(), NumberFormatException.class); String unused = new GregorianDate(2009, 6, 10).toString("ffffffffffffffff"); }
@Test public final void cantEndWithABackslash() { ExpectedExceptionHelper.expectException(getRule$expectedException(), NumberFormatException.class); String unused = new GregorianDate(2009, 6, 10).toString("f\\"); }
@Test public final void cantHaveADoublePercent() { ExpectedExceptionHelper.expectException(getRule$expectedException(), NumberFormatException.class); String unused = new GregorianDate(2009, 6, 10).toString("%%"); }
@Test public final void cantEndWithAPercent() { ExpectedExceptionHelper.expectException(getRule$expectedException(), NumberFormatException.class); String unused = new GregorianDate(2009, 6, 10).toString("f%"); }