/** * Converts the value of this instance to its equivalent ISO8601 string representation, with fractional seconds represented to the specified number of digits. * @param format The type of ISO8601 string to create. * @param digitsOfFractionalSeconds The number of digits after the decimal point in the 'seconds' portion of the time. * @return A string representing this date and time in ISO8601 format. */ @CS2JWarning("Unhandled attribute removed: Pure") @Nonnull public final String toIso8601String(@Nonnull Iso8601Format format, int digitsOfFractionalSeconds) { return toIso8601String(format, digitsOfFractionalSeconds, true); }
/** * Converts the value of this instance to its equivalent ISO8601 extended string representation, with fractional seconds represented to 15 digits. * @return A string representing this date and time in extended ISO8601 format. */ @CS2JWarning("Unhandled attribute removed: Pure") @Nonnull public final String toIso8601String() { return toIso8601String(Iso8601Format.EXTENDED); }
/** * Converts the value of this instance to its equivalent ISO8601 string representation, with fractional seconds represented to 15 digits. * @param format The type of ISO8601 string to create. * @return A string representing this date and time in ISO8601 format. */ @CS2JWarning("Unhandled attribute removed: Pure") @Nonnull public final String toIso8601String(@Nonnull Iso8601Format format) { return toIso8601String(format, 15, false); }
/** * Converts a {@link JulianDate} to an ISO8601 date string. * @param date The date to convert. * @param format The format to use. * @return The date represented as an ISO8601 date string. */ @Nonnull public static String toIso8601(@Nonnull JulianDate date, @Nonnull Iso8601Format format) { //If the JulianDate is outside the range of supported CZML values, //clamp it to the minimum/maximum CZML ISO8601 value. if (JulianDate.lessThanOrEqual(date, s_minimumDate)) { return GregorianDate.MinValue.toIso8601String(format); } if (JulianDate.greaterThanOrEqual(date, s_maximumDate)) { return GregorianDate.MaxValue.toIso8601String(format); } return date.toGregorianDate().toIso8601String(format); }
public final void toIso8601StringWithFractionalSeconds(int year, int month, int day, int hour, int minute, double second, String expectedIsoString) { cesiumlanguagewriter.GregorianDate gregorianDate = new GregorianDate(year, month, day, hour, minute, second); String isoString = gregorianDate.toIso8601String(Iso8601Format.EXTENDED, 6); Assert.assertEquals(expectedIsoString, isoString); }
public final void toIso8601CompactStringProducesCorrectStrings(int year, int month, int day, int hour, int minute, double second, String expectedIsoString) { cesiumlanguagewriter.GregorianDate gregorianDate = new GregorianDate(year, month, day, hour, minute, second); String isoString = gregorianDate.toIso8601String(Iso8601Format.COMPACT); Assert.assertEquals(expectedIsoString, isoString); }
@Test public final void maxValueRoundTripsThroughJulianDate() { JulianDate max = GregorianDate.MaxValue.toJulianDate(); GregorianDate date = max.toGregorianDate(); String iso = date.toIso8601String(Iso8601Format.EXTENDED, 6); String expected = GregorianDate.MaxValue.toIso8601String(Iso8601Format.EXTENDED, 6); Assert.assertEquals(expected, iso); }
public final void toIso8601Validation(@Nonnull GregorianDate date) { // found this regex online Pattern regex = RegexHelper .create("^([\\+-]?\\d{4}(?!\\d{2}\\b))((-?)((0[1-9]|1[0-2])(\\3([12]\\d|0[1-9]|3[01]))?|W([0-4]\\d|5[0-2])(-?[1-7])?|(00[1-9]|0[1-9]\\d|[12]\\d{2}|3([0-5]\\d|6[1-6])))([T\\s]((([01]\\d|2[0-3])((:?)[0-5]\\d)?|24\\:?00)([\\.,]\\d+(?!:))?)?(\\17[0-5]\\d([\\.,]\\d+)?)?([zZ]|([\\+-])([01]\\d|2[0-3]):?([0-5]\\d)?)?)?)?$"); String s = date.toIso8601String(); Assert.assertTrue(RegexHelper.isMatch(regex, s)); s = date.toIso8601String(Iso8601Format.BASIC); Assert.assertTrue(RegexHelper.isMatch(regex, s)); s = date.toIso8601String(Iso8601Format.COMPACT); Assert.assertTrue(RegexHelper.isMatch(regex, s)); s = date.toIso8601String(Iso8601Format.EXTENDED); Assert.assertTrue(RegexHelper.isMatch(regex, s)); for (int numDigits = 0; numDigits <= 15; ++numDigits) { s = date.toIso8601String(Iso8601Format.BASIC, numDigits); Assert.assertTrue(RegexHelper.isMatch(regex, s)); s = date.toIso8601String(Iso8601Format.COMPACT, numDigits); Assert.assertTrue(RegexHelper.isMatch(regex, s)); s = date.toIso8601String(Iso8601Format.EXTENDED, numDigits); Assert.assertTrue(RegexHelper.isMatch(regex, s)); } }
@Test public final void testToISO8601String() { // Full format String isoString = "1985-04-12T10:15:30Z"; GregorianDate iso = new GregorianDate(1985, 4, 12, 10, 15, 30D); GregorianDate result = GregorianDate.parse(isoString); AssertHelper.assertEquals(iso, result); String resultString = result.toIso8601String(); Assert.assertEquals(isoString, resultString); Assert.assertEquals(isoString, iso.toIso8601String()); }
public final void toIso8601ExtendedStringProducesCorrectStrings(int year, int month, int day, int hour, int minute, double second, String expectedIsoString) { cesiumlanguagewriter.GregorianDate gregorianDate = new GregorianDate(year, month, day, hour, minute, second); String isoString = gregorianDate.toIso8601String(Iso8601Format.EXTENDED); Assert.assertEquals(expectedIsoString, isoString); AssertHelper.assertEquals(gregorianDate, GregorianDate.parse(isoString)); }
@Test public final void testParseIso8601FormatBasic() { GregorianDate g1 = new GregorianDate(1985, 4, 12, 10, 15, 30D); String s1 = g1.toIso8601String(Iso8601Format.BASIC); GregorianDate gp1 = GregorianDate.parse(s1); AssertHelper.assertEquals(g1, gp1); }
public final void toIso8601BasicStringProducesCorrectStrings(int year, int month, int day, int hour, int minute, double second, String expectedIsoString) { cesiumlanguagewriter.GregorianDate gregorianDate = new GregorianDate(year, month, day, hour, minute, second); String isoString = gregorianDate.toIso8601String(Iso8601Format.BASIC); Assert.assertEquals(expectedIsoString, isoString); AssertHelper.assertEquals(gregorianDate, GregorianDate.parse(isoString)); }
@Test public final void passClampToIso8601() { String expected = GregorianDate.MinValue.toIso8601String(Iso8601Format.BASIC); String actual = CesiumFormattingHelper.toIso8601(JulianDate.getMinValue(), Iso8601Format.BASIC); Assert.assertEquals(expected, actual); actual = CesiumFormattingHelper.toIso8601(GregorianDate.MinValue.toJulianDate(), Iso8601Format.BASIC); Assert.assertEquals(expected, actual); expected = GregorianDate.MaxValue.toIso8601String(Iso8601Format.BASIC); actual = CesiumFormattingHelper.toIso8601(JulianDate.getMaxValue(), Iso8601Format.BASIC); Assert.assertEquals(expected, actual); actual = CesiumFormattingHelper.toIso8601(GregorianDate.MaxValue.toJulianDate(), Iso8601Format.BASIC); Assert.assertEquals(expected, actual); expected = GregorianDate.MinValue.toIso8601String(Iso8601Format.EXTENDED); actual = CesiumFormattingHelper.toIso8601(JulianDate.getMinValue(), Iso8601Format.EXTENDED); Assert.assertEquals(expected, actual); expected = GregorianDate.MaxValue.toIso8601String(Iso8601Format.EXTENDED); actual = CesiumFormattingHelper.toIso8601(JulianDate.getMaxValue(), Iso8601Format.EXTENDED); Assert.assertEquals(expected, actual); expected = GregorianDate.MinValue.toIso8601String(Iso8601Format.COMPACT); actual = CesiumFormattingHelper.toIso8601(JulianDate.getMinValue(), Iso8601Format.COMPACT); Assert.assertEquals(expected, actual); expected = GregorianDate.MaxValue.toIso8601String(Iso8601Format.COMPACT); actual = CesiumFormattingHelper.toIso8601(JulianDate.getMaxValue(), Iso8601Format.COMPACT); Assert.assertEquals(expected, actual); }