Пример #1
0
        /// <summary>
        /// Converts a <see cref="JulianDate"/> to an ISO8601 date string.
        /// </summary>
        /// <param name="date">The date to convert.</param>
        /// <param name="format">The format to use.</param>
        /// <returns>The date represented as an ISO8601 date string.</returns>
        public static string ToIso8601(JulianDate date, Iso8601Format format)
        {
            //If the JulianDate is outside the range of supported CZML values,
            //clamp it to the minimum/maximum CZML ISO8601 value.
            if (date <= s_minimumGregorianDate)
            {
                switch (format)
                {
                case Iso8601Format.Basic:
                    return("00000101T000000Z");

                case Iso8601Format.Compact:
                    return("00000101T00Z");

                case Iso8601Format.Extended:
                    return("0000-01-01T00:00:00Z");
                }
            }
            if (date >= s_maximumGregorianDate)
            {
                switch (format)
                {
                case Iso8601Format.Basic:
                    return("99991231T240000Z");

                case Iso8601Format.Compact:
                    return("99991231T24Z");

                case Iso8601Format.Extended:
                    return("9999-12-31T24:00:00Z");
                }
            }
            return(date.ToGregorianDate().ToIso8601String(format));
        }
Пример #2
0
        /// <summary>
        /// Converts a <see cref="JulianDate"/> to an ISO8601 date string.
        /// </summary>
        /// <param name="date">The date to convert.</param>
        /// <param name="format">The format to use.</param>
        /// <returns>The date represented as an ISO8601 date string.</returns>
        public static string ToIso8601(JulianDate date, Iso8601Format format)
        {
            //If the JulianDate is outside the range of supported CZML values,
            //clamp it to the minimum/maximum CZML ISO8601 value.
            if (date <= s_minimumGregorianDate)
            {
                switch (format)
                {
                    case Iso8601Format.Basic:
                        return "00000101T000000Z";

                    case Iso8601Format.Compact:
                        return "00000101T00Z";

                    case Iso8601Format.Extended:
                        return "0000-01-01T00:00:00Z";
                }
            }
            if (date >= s_maximumGregorianDate)
            {
                switch (format)
                {
                    case Iso8601Format.Basic:
                        return "99991231T240000Z";

                    case Iso8601Format.Compact:
                        return "99991231T24Z";

                    case Iso8601Format.Extended:
                        return "9999-12-31T24:00:00Z";
                }
            }
            return date.ToGregorianDate().ToIso8601String(format);
        }
Пример #3
0
        public static void CheckValid(int expectedLength, Iso8601Parts format)
        {
            Iso8601Format fmt = Iso8601Format.TryCreate(format).ValueOrException();

            Assert.Equal(expectedLength, fmt.Length);
            Assert.Equal(format, fmt.Format);
        }
Пример #4
0
        public void Iso8601WeekFormatting()
        {
            Iso8601Format fmt      = Iso8601Format.TryCreate(Iso8601Parts.YearWeekDay | Iso8601Parts.Separator_Date).ValueOrException();
            UtcDateTime   udt      = new(2019, 12, 30);
            Span <char>   expected = stackalloc char[10];

            expected[0] = '2';
            expected[1] = '0';
            expected[2] = '2';
            expected[3] = '0';
            expected[4] = '-';
            expected[5] = 'W';
            expected[8] = '-';
            Span <char> actual = stackalloc char[10];

            for (uint week = 1; week <= (uint)IsoYearWeek.WeeksInYear(2020); week++)
            {
                Formatting.Write2Digits(week, expected, 6);
                for (int day = 1; day < 8; day++)
                {
                    expected[9] = (char)('0' + day);

                    udt.Format(actual, TimeSpan.Zero, fmt);

                    Assert.Equal(new string(expected), new string(actual));

                    udt = udt.AddDays(1);
                }
            }
        }
Пример #5
0
        public static string ToIso8601Interval([NotNull] TimeInterval interval, Iso8601Format format)
        {
            if (interval == null)
            {
                throw new ArgumentNullException("interval");
            }

            return(ToIso8601Interval(interval.Start, interval.Stop, format));
        }
Пример #6
0
        public void TestParseIso8601Formats(Iso8601Format format)
        {
            GregorianDate expected = new GregorianDate(1985, 4, 12, 10, 15, 30);

            Assert.AreEqual(expected, GregorianDate.Parse(expected.ToIso8601String(format)));

            expected = new GregorianDate(1985, 4, 12, 10, 15, 0);
            Assert.AreEqual(expected, GregorianDate.Parse(expected.ToIso8601String(format)));

            expected = new GregorianDate(1985, 4, 12, 10, 0, 0);
            Assert.AreEqual(expected, GregorianDate.Parse(expected.ToIso8601String(format)));

            expected = new GregorianDate(1985, 4, 12, 0, 0, 0);
            Assert.AreEqual(expected, GregorianDate.Parse(expected.ToIso8601String(format)));
        }
Пример #7
0
        /// <summary>
        /// Converts a <see cref="JulianDate"/> to an ISO8601 date string.
        /// </summary>
        /// <param name="date">The date to convert.</param>
        /// <param name="format">The format to use.</param>
        /// <returns>The date represented as an ISO8601 date string.</returns>
        public static string ToIso8601(JulianDate date, Iso8601Format format)
        {
            //If the JulianDate is outside the range of supported CZML values,
            //clamp it to the minimum/maximum CZML ISO8601 value.
            if (date <= s_minimumDate)
            {
                return(GregorianDate.MinValue.ToIso8601String(format));
            }

            if (date >= s_maximumDate)
            {
                return(GregorianDate.MaxValue.ToIso8601String(format));
            }

            return(date.ToGregorianDate().ToIso8601String(format));
        }
Пример #8
0
 public static void AreCorrect()
 {
     Assert.Equal(24, Iso8601Format.TryCreate(Iso8601Parts.Format_ExtendedFormat_UtcTz).ValueOrException().Length);
     Assert.Equal(29, Iso8601Format.TryCreate(Iso8601Parts.Format_ExtendedFormat_FullTz).ValueOrException().Length);
     Assert.Equal(23, Iso8601Format.TryCreate(Iso8601Parts.Format_ExtendedFormat_LocalTz).ValueOrException().Length);
     Assert.Equal(20, Iso8601Format.TryCreate(Iso8601Parts.Format_ExtendedFormat_NoMillis_UtcTz).ValueOrException().Length);
     Assert.Equal(25, Iso8601Format.TryCreate(Iso8601Parts.Format_ExtendedFormat_NoMillis_FullTz).ValueOrException().Length);
     Assert.Equal(19, Iso8601Format.TryCreate(Iso8601Parts.Format_ExtendedFormat_NoMillis_LocalTz).ValueOrException().Length);
     Assert.Equal(20, Iso8601Format.TryCreate(Iso8601Parts.Format_BasicFormat_UtcTz).ValueOrException().Length);
     Assert.Equal(24, Iso8601Format.TryCreate(Iso8601Parts.Format_BasicFormat_FullTz).ValueOrException().Length);
     Assert.Equal(19, Iso8601Format.TryCreate(Iso8601Parts.Format_BasicFormat_LocalTz).ValueOrException().Length);
     Assert.Equal(16, Iso8601Format.TryCreate(Iso8601Parts.Format_BasicFormat_NoMillis_UtcTz).ValueOrException().Length);
     Assert.Equal(20, Iso8601Format.TryCreate(Iso8601Parts.Format_BasicFormat_NoMillis_FullTz).ValueOrException().Length);
     Assert.Equal(15, Iso8601Format.TryCreate(Iso8601Parts.Format_BasicFormat_NoMillis_LocalTz).ValueOrException().Length);
     Assert.Equal(10, Iso8601Format.TryCreate(Iso8601Parts.Format_DateOnly).ValueOrException().Length);
     Assert.Equal(8, Iso8601Format.TryCreate(Iso8601Parts.Format_DateOnlyWithoutSeparators).ValueOrException().Length);
     Assert.Equal(8, Iso8601Format.TryCreate(Iso8601Parts.Format_DateOrdinal).ValueOrException().Length);
 }
Пример #9
0
 /// <summary>
 /// Converts a <see cref="TimeInterval"/> as an ISO8601 interval string.
 /// </summary>
 /// <param name="interval">The interval to convert.</param>
 /// <param name="format">The format to use.</param>
 /// <returns>The interval represented as an ISO8601 interval string.</returns>
 public static string ToIso8601Interval(TimeInterval interval, Iso8601Format format)
 {
     return(ToIso8601Interval(interval.Start, interval.Stop, format));
 }
Пример #10
0
 /// <summary>
 /// Converts a <see cref="TimeInterval"/> as an ISO8601 interval string.
 /// </summary>
 /// <param name="start">The start of the interval.</param>
 /// <param name="stop">The end of the interval.</param>
 /// <param name="format">The format to use.</param>
 /// <returns>The interval represented as an ISO8601 interval string.</returns>
 public static string ToIso8601Interval(JulianDate start, JulianDate stop, Iso8601Format format)
 {
     return(ToIso8601(start, format) + "/" + ToIso8601(stop, format));
 }
Пример #11
0
 /// <summary>
 /// Converts a <see cref="TimeInterval"/> as an ISO8601 interval string.
 /// </summary>
 /// <param name="interval">The interval to convert.</param>
 /// <param name="format">The format to use.</param>
 /// <returns>The interval represented as an ISO8601 interval string.</returns>
 public static string ToIso8601Interval(TimeInterval interval, Iso8601Format format)
 {
     return ToIso8601Interval(interval.Start, interval.Stop, format);
 }
Пример #12
0
 /// <summary>
 /// Converts a <see cref="TimeInterval"/> as an ISO8601 interval string.
 /// </summary>
 /// <param name="start">The start of the interval.</param>
 /// <param name="stop">The end of the interval.</param>
 /// <param name="format">The format to use.</param>
 /// <returns>The interval represented as an ISO8601 interval string.</returns>
 public static string ToIso8601Interval(JulianDate start, JulianDate stop, Iso8601Format format)
 {
     return ToIso8601(start, format) + "/" + ToIso8601(stop, format);
 }
        /// <summary>
        /// Converts a <see cref="JulianDate"/> to an ISO8601 date string.
        /// </summary>
        /// <param name="date">The date to convert.</param>
        /// <param name="format">The format to use.</param>
        /// <returns>The date represented as an ISO8601 date string.</returns>
        public static string ToIso8601(JulianDate date, Iso8601Format format)
        {
            //If the JulianDate is outside the range of supported CZML values,
            //clamp it to the minimum/maximum CZML ISO8601 value.
            if (date <= s_minimumDate)
            {
                return GregorianDate.MinValue.ToIso8601String(format);
            }

            if (date >= s_maximumDate)
            {
                return GregorianDate.MaxValue.ToIso8601String(format);
            }

            return date.ToGregorianDate().ToIso8601String(format);
        }
Пример #14
0
        public void UtcDateTimeToString()
        {
            Iso8601Format weekFmt = Iso8601Format.TryCreate(Iso8601Parts.YearWeekDay | Iso8601Parts.Separator_Date).ValueOrException();

            Assert.Equal("2019-W52-7", new UtcDateTime(2019, 12, 29).ToIso8601String(weekFmt, TimeSpan.Zero));
            Assert.Equal("2020-W01-1", new UtcDateTime(2019, 12, 30).ToIso8601String(weekFmt, TimeSpan.Zero));
            Assert.Equal("2020-W01-2", new UtcDateTime(2019, 12, 31).ToIso8601String(weekFmt, TimeSpan.Zero));
            Assert.Equal("2020-W01-3", new UtcDateTime(2020, 1, 1).ToIso8601String(weekFmt, TimeSpan.Zero));
            Assert.Equal("2020-W01-4", new UtcDateTime(2020, 1, 2).ToIso8601String(weekFmt, TimeSpan.Zero));
            Assert.Equal("2020-W01-5", new UtcDateTime(2020, 1, 3).ToIso8601String(weekFmt, TimeSpan.Zero));
            Assert.Equal("2020-W01-6", new UtcDateTime(2020, 1, 4).ToIso8601String(weekFmt, TimeSpan.Zero));
            Assert.Equal("2020-W01-7", new UtcDateTime(2020, 1, 5).ToIso8601String(weekFmt, TimeSpan.Zero));
            Assert.Equal("2020-W02-1", new UtcDateTime(2020, 1, 6).ToIso8601String(weekFmt, TimeSpan.Zero));

            UtcDateTime dt = new(2020, 6, 5, 3, 0, 52, 012);

            Assert.Equal("2020-06-05T03:00:52.012Z", dt.ToString());

            Assert.Equal("2020-06-05T03:00:52.012Z", dt.ToIso8601StringUtc(extended: true, millis: true));
            Assert.Equal("20200605T030052.012Z", dt.ToIso8601StringUtc(extended: false, millis: true));
            Assert.Equal("2020-06-05T03:00:52Z", dt.ToIso8601StringUtc(extended: true, millis: false));
            Assert.Equal("20200605T030052Z", dt.ToIso8601StringUtc(extended: false, millis: false));

            Assert.Equal("2020-06-05T13:00:52.012+10:00", dt.ToIso8601StringTz(extended: true, millis: true, new TimeSpan(10, 0, 0)));
            Assert.Equal("20200605T133052.012+1030", dt.ToIso8601StringTz(extended: false, millis: true, new TimeSpan(10, 30, 0)));
            Assert.Equal("2020-06-05T14:00:52+11:00", dt.ToIso8601StringTz(extended: true, millis: false, new TimeSpan(11, 0, 0)));
            Assert.Equal("20200605T150052+1200", dt.ToIso8601StringTz(extended: false, millis: false, new TimeSpan(12, 0, 0)));

            Assert.Equal("2020-06-05T03:00:52.012+00:00", dt.ToIso8601String(Iso8601Format.ExtendedFormat_FullTz, TimeSpan.Zero));
            Assert.Equal("20200605T030052.012Z", dt.ToIso8601String(Iso8601Format.BasicFormat_UtcTz, TimeSpan.Zero));
            Assert.Equal("2020-06-05T03:00:52.012Z", dt.ToIso8601String(Iso8601Format.ExtendedFormat_UtcTz, TimeSpan.Zero));

            Assert.Equal("2020-06-05", dt.ToIso8601String(Iso8601Format.DateOnly, TimeSpan.Zero));
            Assert.Equal("20200605", dt.ToIso8601String(Iso8601Format.DateOnlyWithoutSeparators, TimeSpan.Zero));
            Assert.Equal("2020-157", dt.ToIso8601String(Iso8601Format.DateOrdinal, TimeSpan.Zero));

            Assert.Equal("2020-06-05T03:00:52Z", dt.ToIso8601String(Iso8601Format.ExtendedFormat_NoMillis_UtcTz, TimeSpan.Zero));
            Assert.Equal("20200605T03:00:52Z", dt.TryToIso8601String(Iso8601Parts.YearMonthDay | Iso8601Parts.HourMinuteSecond | Iso8601Parts.Tz_Utc | Iso8601Parts.Separator_Time, TimeSpan.Zero).ValueOrException());

            Assert.Equal("2020-06-05T03:00:52.012Z", dt.ToIso8601String(Iso8601Format.ExtendedFormat_UtcTz, TimeSpan.Zero));
            Assert.Equal("2020-06-05T03", dt.TryToIso8601String(Iso8601Parts.YearMonthDay | Iso8601Parts.Hour | Iso8601Parts.Separator_All, TimeSpan.Zero).ValueOrException());
            Assert.Equal("2020-06-05T03Z", dt.TryToIso8601String(Iso8601Parts.YearMonthDay | Iso8601Parts.Hour | Iso8601Parts.Separator_All | Iso8601Parts.Tz_Utc, TimeSpan.Zero).ValueOrException());
            Assert.Equal("2020-06-05T03+00", dt.TryToIso8601String(Iso8601Parts.YearMonthDay | Iso8601Parts.Hour | Iso8601Parts.Separator_All | Iso8601Parts.Tz_Hour, TimeSpan.Zero).ValueOrException());
            Assert.Equal("2020-06-05T03+00:00", dt.TryToIso8601String(Iso8601Parts.YearMonthDay | Iso8601Parts.Hour | Iso8601Parts.Separator_All | Iso8601Parts.Tz_HourMinute, TimeSpan.Zero).ValueOrException());

            Assert.Equal("2020-06-05T03:00", dt.TryToIso8601String(Iso8601Parts.YearMonthDay | Iso8601Parts.HourMinute | Iso8601Parts.Separator_All, TimeSpan.Zero).ValueOrException());
            Assert.Equal("2020-06-05T03:00Z", dt.TryToIso8601String(Iso8601Parts.YearMonthDay | Iso8601Parts.HourMinute | Iso8601Parts.Separator_All | Iso8601Parts.Tz_Utc, TimeSpan.Zero).ValueOrException());
            Assert.Equal("2020-06-05T03:00+00", dt.TryToIso8601String(Iso8601Parts.YearMonthDay | Iso8601Parts.HourMinute | Iso8601Parts.Separator_All | Iso8601Parts.Tz_Hour, TimeSpan.Zero).ValueOrException());
            Assert.Equal("2020-06-05T03:00+00:00", dt.TryToIso8601String(Iso8601Parts.YearMonthDay | Iso8601Parts.HourMinute | Iso8601Parts.Separator_All | Iso8601Parts.Tz_HourMinute, TimeSpan.Zero).ValueOrException());

            Assert.Equal("2020-06-05T03:00:52", dt.TryToIso8601String(Iso8601Parts.YearMonthDay | Iso8601Parts.HourMinuteSecond | Iso8601Parts.Separator_All, TimeSpan.Zero).ValueOrException());
            Assert.Equal("2020-06-05T03:00:52Z", dt.TryToIso8601String(Iso8601Parts.YearMonthDay | Iso8601Parts.HourMinuteSecond | Iso8601Parts.Separator_All | Iso8601Parts.Tz_Utc, TimeSpan.Zero).ValueOrException());
            Assert.Equal("2020-06-05T03:00:52+00", dt.TryToIso8601String(Iso8601Parts.YearMonthDay | Iso8601Parts.HourMinuteSecond | Iso8601Parts.Separator_All | Iso8601Parts.Tz_Hour, TimeSpan.Zero).ValueOrException());
            Assert.Equal("2020-06-05T03:00:52+00:00", dt.TryToIso8601String(Iso8601Parts.YearMonthDay | Iso8601Parts.HourMinuteSecond | Iso8601Parts.Separator_All | Iso8601Parts.Tz_HourMinute, TimeSpan.Zero).ValueOrException());

            Assert.Equal("2020-06-05T03:00:52.012", dt.TryToIso8601String(Iso8601Parts.YearMonthDay | Iso8601Parts.HourMinuteSecondMillis | Iso8601Parts.Separator_All, TimeSpan.Zero).ValueOrException());
            Assert.Equal("2020-06-05T03:00:52.012Z", dt.TryToIso8601String(Iso8601Parts.YearMonthDay | Iso8601Parts.HourMinuteSecondMillis | Iso8601Parts.Separator_All | Iso8601Parts.Tz_Utc, TimeSpan.Zero).ValueOrException());
            Assert.Equal("2020-06-05T03:00:52.012+00", dt.TryToIso8601String(Iso8601Parts.YearMonthDay | Iso8601Parts.HourMinuteSecondMillis | Iso8601Parts.Separator_All | Iso8601Parts.Tz_Hour, TimeSpan.Zero).ValueOrException());
            Assert.Equal("2020-06-05T03:00:52.012+00:00", dt.TryToIso8601String(Iso8601Parts.YearMonthDay | Iso8601Parts.HourMinuteSecondMillis | Iso8601Parts.Separator_All | Iso8601Parts.Tz_HourMinute, TimeSpan.Zero).ValueOrException());

            Assert.Equal("2020-06-05T06:00:52.012+03:00", dt.TryToIso8601String(Iso8601Parts.YearMonthDay | Iso8601Parts.HourMinuteSecondMillis | Iso8601Parts.Separator_All | Iso8601Parts.Tz_HourMinute, new TimeSpan(3, 0, 0)).ValueOrException());

            Assert.Equal("T03", dt.TryToIso8601String(Iso8601Parts.Hour | Iso8601Parts.Separator_All, TimeSpan.Zero).ValueOrException());
            Assert.Equal("T03Z", dt.TryToIso8601String(Iso8601Parts.Hour | Iso8601Parts.Separator_All | Iso8601Parts.Tz_Utc, TimeSpan.Zero).ValueOrException());
            Assert.Equal("T03+00", dt.TryToIso8601String(Iso8601Parts.Hour | Iso8601Parts.Separator_All | Iso8601Parts.Tz_Hour, TimeSpan.Zero).ValueOrException());
            Assert.Equal("T03+00:00", dt.TryToIso8601String(Iso8601Parts.Hour | Iso8601Parts.Separator_All | Iso8601Parts.Tz_HourMinute, TimeSpan.Zero).ValueOrException());
            Assert.Equal("T03:00", dt.TryToIso8601String(Iso8601Parts.HourMinute | Iso8601Parts.Separator_All, TimeSpan.Zero).ValueOrException());
            Assert.Equal("T03:00Z", dt.TryToIso8601String(Iso8601Parts.HourMinute | Iso8601Parts.Separator_All | Iso8601Parts.Tz_Utc, TimeSpan.Zero).ValueOrException());
            Assert.Equal("T03:00+00", dt.TryToIso8601String(Iso8601Parts.HourMinute | Iso8601Parts.Separator_All | Iso8601Parts.Tz_Hour, TimeSpan.Zero).ValueOrException());
            Assert.Equal("T03:00+00:00", dt.TryToIso8601String(Iso8601Parts.HourMinute | Iso8601Parts.Separator_All | Iso8601Parts.Tz_HourMinute, TimeSpan.Zero).ValueOrException());
            Assert.Equal("T03:00:52", dt.TryToIso8601String(Iso8601Parts.HourMinuteSecond | Iso8601Parts.Separator_All, TimeSpan.Zero).ValueOrException());
            Assert.Equal("T03:00:52Z", dt.TryToIso8601String(Iso8601Parts.HourMinuteSecond | Iso8601Parts.Separator_All | Iso8601Parts.Tz_Utc, TimeSpan.Zero).ValueOrException());
            Assert.Equal("T03:00:52+00", dt.TryToIso8601String(Iso8601Parts.HourMinuteSecond | Iso8601Parts.Separator_All | Iso8601Parts.Tz_Hour, TimeSpan.Zero).ValueOrException());
            Assert.Equal("T03:00:52+00:00", dt.TryToIso8601String(Iso8601Parts.HourMinuteSecond | Iso8601Parts.Separator_All | Iso8601Parts.Tz_HourMinute, TimeSpan.Zero).ValueOrException());
            Assert.Equal("T03:00:52.012", dt.TryToIso8601String(Iso8601Parts.HourMinuteSecondMillis | Iso8601Parts.Separator_All, TimeSpan.Zero).ValueOrException());
            Assert.Equal("T03:00:52.012Z", dt.TryToIso8601String(Iso8601Parts.HourMinuteSecondMillis | Iso8601Parts.Separator_All | Iso8601Parts.Tz_Utc, TimeSpan.Zero).ValueOrException());
            Assert.Equal("T03:00:52.012+00", dt.TryToIso8601String(Iso8601Parts.HourMinuteSecondMillis | Iso8601Parts.Separator_All | Iso8601Parts.Tz_Hour, TimeSpan.Zero).ValueOrException());
            Assert.Equal("T03:00:52.012+00:00", dt.TryToIso8601String(Iso8601Parts.HourMinuteSecondMillis | Iso8601Parts.Separator_All | Iso8601Parts.Tz_HourMinute, TimeSpan.Zero).ValueOrException());

            Assert.Equal("T03", dt.TryToIso8601String(Iso8601Parts.Hour, TimeSpan.Zero).ValueOrException());
            Assert.Equal("T03Z", dt.TryToIso8601String(Iso8601Parts.Hour | Iso8601Parts.Tz_Utc, TimeSpan.Zero).ValueOrException());
            Assert.Equal("T03+00", dt.TryToIso8601String(Iso8601Parts.Hour | Iso8601Parts.Tz_Hour, TimeSpan.Zero).ValueOrException());
            Assert.Equal("T03+0000", dt.TryToIso8601String(Iso8601Parts.Hour | Iso8601Parts.Tz_HourMinute, TimeSpan.Zero).ValueOrException());
            Assert.Equal("T0300", dt.TryToIso8601String(Iso8601Parts.HourMinute, TimeSpan.Zero).ValueOrException());
            Assert.Equal("T0300Z", dt.TryToIso8601String(Iso8601Parts.HourMinute | Iso8601Parts.Tz_Utc, TimeSpan.Zero).ValueOrException());
            Assert.Equal("T0300+00", dt.TryToIso8601String(Iso8601Parts.HourMinute | Iso8601Parts.Tz_Hour, TimeSpan.Zero).ValueOrException());
            Assert.Equal("T0300+0000", dt.TryToIso8601String(Iso8601Parts.HourMinute | Iso8601Parts.Tz_HourMinute, TimeSpan.Zero).ValueOrException());
            Assert.Equal("T030052", dt.TryToIso8601String(Iso8601Parts.HourMinuteSecond, TimeSpan.Zero).ValueOrException());
            Assert.Equal("T030052Z", dt.TryToIso8601String(Iso8601Parts.HourMinuteSecond | Iso8601Parts.Tz_Utc, TimeSpan.Zero).ValueOrException());
            Assert.Equal("T030052+00", dt.TryToIso8601String(Iso8601Parts.HourMinuteSecond | Iso8601Parts.Tz_Hour, TimeSpan.Zero).ValueOrException());
            Assert.Equal("T030052+0000", dt.TryToIso8601String(Iso8601Parts.HourMinuteSecond | Iso8601Parts.Tz_HourMinute, TimeSpan.Zero).ValueOrException());
            Assert.Equal("T030052.012", dt.TryToIso8601String(Iso8601Parts.HourMinuteSecondMillis, TimeSpan.Zero).ValueOrException());
            Assert.Equal("T030052.012Z", dt.TryToIso8601String(Iso8601Parts.HourMinuteSecondMillis | Iso8601Parts.Tz_Utc, TimeSpan.Zero).ValueOrException());
            Assert.Equal("T030052.012+00", dt.TryToIso8601String(Iso8601Parts.HourMinuteSecondMillis | Iso8601Parts.Tz_Hour, TimeSpan.Zero).ValueOrException());
            Assert.Equal("T030052.012+0000", dt.TryToIso8601String(Iso8601Parts.HourMinuteSecondMillis | Iso8601Parts.Tz_HourMinute, TimeSpan.Zero).ValueOrException());

            dt = new(2020, 6, 5, 12, 0, 0);
            Assert.Equal("2020-06-05", dt.ToIso8601String(Iso8601Format.DateOnly, TimeSpan.Zero));
            Assert.Equal("2020-06-04", dt.ToIso8601String(Iso8601Format.DateOnly, new TimeSpan(-13, 0, 0)));
            Assert.Equal("2020-06-06", dt.ToIso8601String(Iso8601Format.DateOnly, new TimeSpan(13, 0, 0)));
        }
Пример #15
0
        public static void CheckInvalid(string errorMsg, Iso8601Parts format)
        {
            string?err = Iso8601Format.TryCreate(format).ErrorOr(null);

            Assert.Equal(err, errorMsg);
        }
Пример #16
0
 /// <summary>
 /// Converts a <see cref="JulianDate"/> to an ISO8601 date string.
 /// </summary>
 /// <param name="date">The date to convert.</param>
 /// <param name="format">The format to use.</param>
 /// <returns>The date represented as an ISO8601 date string.</returns>
 public static string ToIso8601(JulianDate date, Iso8601Format format)
 {
     return date.ToGregorianDate().ToIso8601String(format);
 }