public void ToIso8601StringWithFractionalSeconds(int year, int month, int day, int hour, int minute, double second, string expectedIsoString) { var gregorianDate = new GregorianDate(year, month, day, hour, minute, second); string isoString = gregorianDate.ToIso8601String(Iso8601Format.Extended, 6); Assert.AreEqual(expectedIsoString, isoString); }
public void FractionalSecondsCloseToZeroAreFormattedCorrectly() { // Based on BUG71966: GregorianDate.ToString(format) produces incorrect value for fractional seconds var date = new GregorianDate(2012, 2, 25, 0, 15, 0.000000000014551915228366852); Assert.AreEqual("001500.0000000", date.ToString("HHmmss.fffffff", m_cultureInfo)); }
public void ToIso8601Validation(GregorianDate date) { // found this regex online var regex = new Regex(@"^([\+-]?\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.IsTrue(regex.IsMatch(s)); s = date.ToIso8601String(Iso8601Format.Basic); Assert.IsTrue(regex.IsMatch(s)); s = date.ToIso8601String(Iso8601Format.Compact); Assert.IsTrue(regex.IsMatch(s)); s = date.ToIso8601String(Iso8601Format.Extended); Assert.IsTrue(regex.IsMatch(s)); for (int numDigits = 0; numDigits <= 15; ++numDigits) { s = date.ToIso8601String(Iso8601Format.Basic, numDigits); Assert.IsTrue(regex.IsMatch(s)); s = date.ToIso8601String(Iso8601Format.Compact, numDigits); Assert.IsTrue(regex.IsMatch(s)); s = date.ToIso8601String(Iso8601Format.Extended, numDigits); Assert.IsTrue(regex.IsMatch(s)); } }
public void PassToIso8601Interval() { //Since ToIso8601Interval is just a simple wrapper around two calls to //CesiumFormattingHelper.ToIso8601, this test is just a smoke screen. string expectedBasicInterval = "19800801T000000Z/20720703T000000Z"; string expectedExtendedInterval = "1980-08-01T00:00:00Z/2072-07-03T00:00:00Z"; string expectedCompactInterval = "19800801T00Z/20720703T00Z"; JulianDate start = new GregorianDate(1980, 08, 01).ToJulianDate(); JulianDate stop = new GregorianDate(2072, 07, 03).ToJulianDate(); string basicInterval = CesiumFormattingHelper.ToIso8601Interval(start, stop, Iso8601Format.Basic); Assert.AreEqual(expectedBasicInterval, basicInterval); string extendedInterval = CesiumFormattingHelper.ToIso8601Interval(start, stop, Iso8601Format.Extended); Assert.AreEqual(expectedExtendedInterval, extendedInterval); string compactInterval = CesiumFormattingHelper.ToIso8601Interval(start, stop, Iso8601Format.Compact); Assert.AreEqual(expectedCompactInterval, compactInterval); TimeInterval interval = new TimeInterval(start, stop); basicInterval = CesiumFormattingHelper.ToIso8601Interval(interval, Iso8601Format.Basic); Assert.AreEqual(expectedBasicInterval, basicInterval); extendedInterval = CesiumFormattingHelper.ToIso8601Interval(interval, Iso8601Format.Extended); Assert.AreEqual(expectedExtendedInterval, extendedInterval); compactInterval = CesiumFormattingHelper.ToIso8601Interval(interval, Iso8601Format.Compact); Assert.AreEqual(expectedCompactInterval, compactInterval); }
public void TestEquality() { GregorianDate first = new GregorianDate(2000, 1, 1, 5, 1, 1); GregorianDate second = new GregorianDate(2000, 1, 1, 5, 1, 1); Assert.AreEqual(first, second); Assert.IsTrue(first.Equals(second)); Assert.IsTrue(second.Equals(first)); Assert.AreEqual(0, first.CompareTo(second)); Assert.AreEqual(0, second.CompareTo(first)); second = new GregorianDate(2000, 1, 1, 6, 1, 1); Assert.AreNotEqual(first, second); Assert.IsFalse(first.Equals(second)); Assert.IsFalse(second.Equals(first)); Assert.AreNotEqual(0, first.CompareTo(second)); Assert.AreNotEqual(0, second.CompareTo(first)); second = new GregorianDate(2000, 2, 1, 5, 1, 1); Assert.AreNotEqual(first, second); Assert.IsFalse(first.Equals(second)); Assert.IsFalse(second.Equals(first)); Assert.AreNotEqual(0, first.CompareTo(second)); Assert.AreNotEqual(0, second.CompareTo(first)); Assert.AreNotEqual(first, 5); }
private static TimeInterval GetTimeSpan(XElement timespan, XNamespace docNamespace) { XElement beginElement = timespan.Element(docNamespace + "begin"); JulianDate begin = new JulianDate(GregorianDate.MinValue); JulianDate end = new JulianDate(GregorianDate.MaxValue); if (beginElement != null) { GregorianDate beginDate; if (!GregorianDate.TryParse(beginElement.Value, out beginDate)) { beginDate = GregorianDate.ParseExact(beginElement.Value, ValidIso8601Formats, CultureInfo.CurrentCulture); } begin = new JulianDate(beginDate); } XElement endElement = timespan.Element(docNamespace + "end"); if (endElement != null) { GregorianDate endDate; if (!GregorianDate.TryParse(endElement.Value, out endDate)) { endDate = GregorianDate.ParseExact(endElement.Value, ValidIso8601Formats, CultureInfo.CurrentCulture); } end = new JulianDate(endDate); } return(new TimeInterval(begin, end)); }
public void ToIso8601CompactStringProducesCorrectStrings(int year, int month, int day, int hour, int minute, double second, string expectedIsoString) { var gregorianDate = new GregorianDate(year, month, day, hour, minute, second); string isoString = gregorianDate.ToIso8601String(Iso8601Format.Compact); Assert.AreEqual(expectedIsoString, isoString); }
public void TestParseISO8601DayOfYear() { GregorianDate iso = new GregorianDate(1985, 2, 11, 2, 0, 5.2134); GregorianDate result = GregorianDate.Parse("1985-042T02:00:05.2134"); Assert.AreEqual(iso, result); iso = new GregorianDate(1985, 2, 11, 2, 0, 5.21345); result = GregorianDate.Parse("1985-042T02:00:05.21345Z"); Assert.AreEqual(iso, result); iso = new GregorianDate(1985, 2, 11, 2, 0, 5); result = GregorianDate.Parse("1985-042T02:00:05"); Assert.AreEqual(iso, result); iso = new GregorianDate(1985, 2, 11); result = GregorianDate.Parse("1985-042"); Assert.AreEqual(iso, result); // Make sure to check each month to ensure we have it right string first = "1986-"; string last = "T02:01:04Z"; JulianDate baseDate = new JulianDate(new GregorianDate(1986, 1, 12, 02, 01, 4)); for (int i = 1; i < 12; i++) { string testString = string.Format(first + "{0:000}" + last, 12 + i * 30); GregorianDate expected = baseDate.AddDays(i * 30).ToGregorianDate(); Assert.AreEqual(expected, GregorianDate.Parse(testString)); } }
public void TestParseIso8601FormatBasic() { GregorianDate date = new GregorianDate(1985, 4, 12, 10, 15, 30); string isoString = date.ToIso8601String(Iso8601Format.Basic); GregorianDate parsed = GregorianDate.Parse(isoString); Assert.AreEqual(date, parsed); }
/// <summary> /// Initializes a <see cref="JulianDate"/> from a <see cref="GregorianDate"/> where the <see cref="GregorianDate"/> /// is expressed in the given <see cref="TimeStandard"/>. If the date is during a leap second, the /// <see cref="JulianDate"/> will be expressed in <see cref="TimeStandard.InternationalAtomicTime"/> (TAI). /// </summary> /// <param name="gregorianDate">The <see cref="GregorianDate"/>.</param> /// <param name="standard"> /// The time standard in which the <paramref name="gregorianDate"/> is expressed. /// </param> public JulianDate(GregorianDate gregorianDate, TimeStandard standard) { JulianDate converted = gregorianDate.ToJulianDate(standard); m_day = converted.m_day; m_secondsOfDay = converted.m_secondsOfDay; m_timeStandard = converted.Standard; }
public void TestCompareToObject() { GregorianDate date = new GregorianDate(2001, 1, 1, 6, 3, 14); object dateAsObject = new GregorianDate(2001, 1, 1, 6, 3, 15); Assert.IsTrue(date.CompareTo(null) > 0); Assert.IsTrue(date.CompareTo(dateAsObject) < 0); }
public void TestCompareTimePortionObject() { GregorianDate gd1 = new GregorianDate(1999, 10, 10, 6, 3, 14); object gd4 = new GregorianDate(1999, 10, 10, 4, 2, 21); Assert.IsTrue(gd1.CompareTo(null) > 0); Assert.IsTrue(gd1.CompareTo(gd4) > 0); }
public void TestSixtySecondsAreNotValidIfTheInstantDoesNotRepresentALeapSecond() { //12/30/2008 was not the day of a leap second day. Assert.IsFalse(GregorianDate.IsValid(2008, 12, 30, 23, 59, 60)); //23:58 is one minute before a valid leap second. Assert.IsFalse(GregorianDate.IsValid(2008, 12, 31, 23, 58, 60)); }
public void SecondsAreCorrectlyFormattedToDifferentNumbersOfDigits() { GregorianDate first = new GregorianDate(2009, 2, 7, 5, 41, 44.408); Assert.AreEqual("44.408", first.ToString("ss.fff", m_cultureInfo)); Assert.AreEqual("44.4080", first.ToString("ss.ffff", m_cultureInfo)); Assert.AreEqual("44.40800", first.ToString("ss.fffff", m_cultureInfo)); }
public void TestParseIso8601FormatBasic() { GregorianDate g1 = new GregorianDate(1985, 4, 12, 10, 15, 30); string s1 = g1.ToIso8601String(Iso8601Format.Basic); GregorianDate gp1 = GregorianDate.Parse(s1); Assert.AreEqual(g1, gp1); }
/// <summary> /// Propagate a Platform using a NumericalPropagator configured with the entered KeplerianElements, /// ForceModels, NumericalIntegrator, and start and stop dates. /// </summary> private void PropagateSatellite() { KeplerianElements orbitalElements = m_keplerianOrbitalElementsEntry.KeplerianElementValues; if (orbitalElements == null) { return; } Motion <Cartesian> initialMotion = orbitalElements.ToCartesian(); PropagationNewtonianPoint point = new PropagationNewtonianPoint(m_elementID, m_forceModelSettings.CurrentCentralBody.InertialFrame, initialMotion.Value, initialMotion.FirstDerivative); point.Mass = new ScalarFixed(double.Parse(m_mass.Text)); m_forceModelSettings.SetForceModelsOnPoint(point, new ScalarFixed(double.Parse(m_area.Text))); CentralBody primaryCentralBody = m_forceModelSettings.CurrentCentralBody; NumericalPropagatorDefinition state = new NumericalPropagatorDefinition(); state.IntegrationElements.Add(point); state.Integrator = m_integratorSettings.GetIntegrator(); JulianDate start = new JulianDate(GregorianDate.ParseExact(m_start.Text, DateFormat, null)); JulianDate end = new JulianDate(GregorianDate.ParseExact(m_end.Text, DateFormat, null)); state.Epoch = start; NumericalPropagator propagator = state.CreatePropagator(); propagator.StepTaken += (sender, args) => { // Telling the propagator to stop if we get too close to the central body Cartesian position = propagator.Converter.ConvertState <Cartesian>(m_elementID, args.CurrentState).Value; if (position.Magnitude <= primaryCentralBody.Shape.SemimajorAxisLength + 10000) { args.Indication = PropagationEventIndication.StopPropagationAfterStep; } }; DateMotionCollection <Cartesian> answer = null; var backgroundCalculation = new BackgroundCalculation(); backgroundCalculation.DoWork += (sender, e) => { // actually propagate var result = propagator.Propagate(end.Subtract(start), 1, backgroundCalculation); answer = result.GetDateMotionCollection <Cartesian>(m_elementID); }; backgroundCalculation.ProgressChanged += (sender, e) => m_propagationProgress.Value = e.ProgressPercentage; backgroundCalculation.RunWorkerCompleted += (sender, e) => { // when finished, draw the satellite DrawSatellite(answer, primaryCentralBody.InertialFrame); m_propagate.Enabled = true; }; m_propagate.Enabled = false; backgroundCalculation.RunWorkerAsync(); }
public void CreateExampleFile() { using (var stringWriter = new StringWriter()) { var output = new CesiumOutputStream(stringWriter) { PrettyFormatting = true }; var writer = new CesiumStreamWriter(); using (var packet = writer.OpenPacket(output)) { packet.WriteId("MyID"); var startDate = new GregorianDate(2012, 4, 2, 12, 0, 0).ToJulianDate(); var stopDate = new GregorianDate(2012, 4, 2, 12, 1, 0).ToJulianDate(); using (var clockWriter = packet.OpenClockProperty()) { using (var intervalClockWriter = clockWriter.OpenInterval(startDate, stopDate)) { intervalClockWriter.WriteCurrentTime(startDate); } } using (var modelWriter = packet.OpenModelProperty()) { modelWriter.WriteGltfProperty(new Uri("example.gltf", UriKind.Relative), CesiumResourceBehavior.LinkTo); using (var nodeTransformationsWriter = modelWriter.OpenNodeTransformationsProperty()) { using (var nodeTransformationWriter = nodeTransformationsWriter.OpenNodeTransformationProperty("node1")) { nodeTransformationWriter.WriteScaleProperty(new Cartesian(1.0, 2.0, 3.0)); nodeTransformationWriter.WriteRotationProperty(UnitQuaternion.Identity); nodeTransformationWriter.WriteTranslationProperty(new Cartesian(4.0, 5.0, 6.0)); } using (var nodeTransformationWriter = nodeTransformationsWriter.OpenNodeTransformationProperty("node2")) { var dates = new List <JulianDate> { startDate, stopDate }; var values = new List <Cartesian> { new Cartesian(1.0, 2.0, 3.0), new Cartesian(10.0, 12.0, 14.0) }; nodeTransformationWriter.WriteScaleProperty(dates, values); } } } } Console.WriteLine(stringWriter.ToString()); } }
public void TestLeapSecondCount() { LeapSeconds leapSeconds = new LeapSeconds(); JulianDate utc = new GregorianDate(1998, 4, 1, 12, 0, 0).ToJulianDate(); JulianDate tai = utc.ToTimeStandard(TimeStandard.InternationalAtomicTime); Assert.AreEqual(31, leapSeconds.GetTaiMinusUtc(utc)); Assert.AreEqual(31, leapSeconds.GetTaiMinusUtc(tai)); }
public 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.AreEqual(expected, iso); }
public void RoundSecondsAllows61SecondsDuringLeapSecond() { GregorianDate gregorianDate = new GregorianDate(2012, 6, 30, 23, 59, 59.9999999); Assert.AreEqual(new GregorianDate(2012, 6, 30, 23, 59, 60.0), gregorianDate.RoundSeconds(6)); gregorianDate = new GregorianDate(2012, 6, 30, 23, 59, 60.9999999); Assert.AreEqual(new GregorianDate(2012, 7, 1, 0, 0, 0.0), gregorianDate.RoundSeconds(6)); }
public void TestGregorianDateNow() { GregorianDate first = GregorianDate.Now; Thread.Sleep(100); GregorianDate second = GregorianDate.Now; Assert.Greater(second, first); }
public void TestToStringStandardFormats(string format) { var dateTime = new DateTime(2002, 02, 25, 05, 25, 13); var gregorianDate = new GregorianDate(dateTime); // .NET Core on Linux uses different standard formats, so we compare against what DateTime does // rather than specific known strings. Assert.AreEqual(dateTime.ToString(format, m_cultureInfo), gregorianDate.ToString(format, m_cultureInfo)); }
public void ParseExactThrowsWithNullFormat() { string format = null; // ReSharper disable once AssignNullToNotNullAttribute var exception = Assert.Throws <FormatException>(() => GregorianDate.ParseExact("1/1/2009", format, m_cultureInfo)); StringAssert.Contains("Invalid format string", exception.Message); }
public void SecondsAreCorrectlyFormattedInTurkey() { var cultureInfo = new CultureInfo("tr-TR"); GregorianDate first = new GregorianDate(2009, 2, 7, 5, 41, 44.408); Assert.AreEqual("44,408", first.ToString("ss.fff", cultureInfo)); Assert.AreEqual("44,4080", first.ToString("ss.ffff", cultureInfo)); Assert.AreEqual("44,40800", first.ToString("ss.fffff", cultureInfo)); }
public void CannotParseInvalidDates() { GregorianDate result; Assert.IsFalse(GregorianDate.TryParse("02/29/2002", m_cultureInfo, out result)); Assert.AreEqual(GregorianDate.MinValue, result); Assert.IsFalse(GregorianDate.TryParse("13/01/2002", m_cultureInfo, out result)); }
public void LocalDateTimesAreConvertedToUTC() { DateTime date = new DateTime(2008, 10, 23, 23, 59, 59, 999, DateTimeKind.Local); GregorianDate constructedFromLocalDateTime = new GregorianDate(date); GregorianDate constructedFromUTCDateTime = new GregorianDate(date.ToUniversalTime()); Assert.AreEqual(constructedFromLocalDateTime, constructedFromUTCDateTime); }
public void TestToStringFormatProvider() { GregorianDate gd1 = new GregorianDate(2001, 1, 1, 6, 3, 14); Assert.AreEqual("1/1/2001 6:03:14 AM", gd1.ToString(new CultureInfo("en-US"))); gd1 = new GregorianDate(2003, 3, 4, 16, 43, 23.23452); Assert.AreEqual("3/4/2003 4:43:23 PM", gd1.ToString(new CultureInfo("en-US"))); }
public void ToStringThrowsOnInvalidFormatSpecifier() { var exception = Assert.Throws <FormatException>(() => { string unused = new GregorianDate(2009, 06, 10).ToString("X"); }); StringAssert.Contains("not one of the format specifier characters", exception.Message); }
public void CantFormatMoreThan15FractionalSeconds() { var exception = Assert.Throws <FormatException>(() => { string unused = new GregorianDate(2009, 06, 10).ToString("ffffffffffffffff"); }); StringAssert.Contains("Invalid format string", exception.Message); }
public void FormatSpecifierCantEndWithABackslash() { var exception = Assert.Throws <FormatException>(() => { string unused = new GregorianDate(2009, 06, 10).ToString(@"f\"); }); StringAssert.Contains(@"Invalid character \ at the end of the format specifier", exception.Message); }
public void FormatSpecifierCantHaveADoublePercent() { var exception = Assert.Throws <FormatException>(() => { string unused = new GregorianDate(2009, 06, 10).ToString("%%"); }); StringAssert.Contains("Invalid character %% in format specifier", exception.Message); }
public void TestParseIso8601InvalidDay() { var exception = Assert.Throws <FormatException>(() => { var unused = GregorianDate.Parse("2009-02-30"); }); StringAssert.Contains("was not recognized as a valid GregorianDate", exception.Message); }
public void TestParseIso8601YearOutOfRange() { var exception = Assert.Throws <FormatException>(() => { var unused = GregorianDate.Parse("21985-167T02:00:05.2134"); }); StringAssert.Contains("was not recognized as a valid GregorianDate", exception.Message); }
public void CanConstructGregorianDate() { GregorianDate gd = new GregorianDate(2000, 1, 2, 6, 30, 15); Assert.AreEqual(2000, gd.Year); Assert.AreEqual(1, gd.Month); Assert.AreEqual(2, gd.Day); Assert.AreEqual(6, gd.Hour); Assert.AreEqual(30, gd.Minute); Assert.AreEqual(15, gd.Second); gd = new GregorianDate(2000, 1, 2); Assert.AreEqual(2000, gd.Year); Assert.AreEqual(1, gd.Month); Assert.AreEqual(2, gd.Day); Assert.AreEqual(0, gd.Hour); Assert.AreEqual(0, gd.Minute); Assert.AreEqual(0, gd.Second); }
public void TestTryParseISO8601DayOfYear() { GregorianDate iso = new GregorianDate(1985, 2, 11, 2, 0, 5.2134); GregorianDate result; if (!GregorianDate.TryParse("1985-042T02:00:05.2134", out result)) Assert.Fail(); Assert.AreEqual(iso, result); iso = new GregorianDate(1985, 2, 11, 2, 0, 5.21345); if (!GregorianDate.TryParse("1985-042T02:00:05.21345Z", out result)) Assert.Fail(); Assert.AreEqual(iso, result); iso = new GregorianDate(1985, 2, 11, 2, 0, 5); if (!GregorianDate.TryParse("1985-042T02:00:05", out result)) Assert.Fail(); Assert.AreEqual(iso, result); iso = new GregorianDate(1985, 2, 11); if (!GregorianDate.TryParse("1985-042", out result)) Assert.Fail(); Assert.AreEqual(iso, result); Assert.IsFalse(GregorianDate.TryParse("1985-367T02:00:05.2134", out result)); Assert.IsFalse(GregorianDate.TryParse("1985-12#T02:00:05.2134", out result)); Assert.IsFalse(GregorianDate.TryParse("21985-167T02:00:05.2134", out result)); }
public void TestComparisons() { GregorianDate date = new GregorianDate(2001, 1, 1, 6, 3, 14); GregorianDate sameDate = new GregorianDate(2001, 1, 1, 6, 3, 14); GregorianDate laterTime = new GregorianDate(2001, 1, 1, 6, 5, 26); GregorianDate laterDay = new GregorianDate(2001, 2, 2, 6, 3, 14); Assert.IsTrue(date == sameDate); Assert.IsTrue(sameDate == date); Assert.IsTrue(date != laterTime); Assert.IsTrue(date >= sameDate); Assert.IsTrue(date <= sameDate); Assert.IsTrue(date.CompareTo(sameDate) == 0); Assert.IsTrue(date.CompareTo(laterDay) < 0); Assert.IsTrue(sameDate < laterTime); Assert.IsTrue(sameDate <= laterTime); Assert.IsTrue(laterTime > sameDate); Assert.IsTrue(laterTime >= sameDate); object dateAsObject = new GregorianDate(2001, 1, 1, 6, 3, 15); Assert.AreNotEqual(date, dateAsObject); }
public void CompareToWithWrongTypeThrows() { GregorianDate gd = new GregorianDate(2001, 1, 1, 6, 3, 14); gd.CompareTo(5); }
public void TestToString() { GregorianDate date = new GregorianDate(2002, 02, 25, 05, 25, 13); Assert.AreEqual("2/25/2002", date.ToString("d", m_cultureInfo)); Assert.AreEqual("Monday, February 25, 2002", date.ToString("D", m_cultureInfo)); Assert.AreEqual("Monday, February 25, 2002 5:25 AM", date.ToString("f", m_cultureInfo)); Assert.AreEqual("Monday, February 25, 2002 5:25:13 AM", date.ToString("F", m_cultureInfo)); Assert.AreEqual("2/25/2002 5:25 AM", date.ToString("g", m_cultureInfo)); Assert.AreEqual("2/25/2002 5:25:13 AM", date.ToString("G", m_cultureInfo)); Assert.AreEqual("February 25", date.ToString("m", m_cultureInfo)); Assert.AreEqual("February 25", date.ToString("M", m_cultureInfo)); Assert.AreEqual("Mon, 25 Feb 2002 05:25:13 GMT", date.ToString("r", m_cultureInfo)); Assert.AreEqual("Mon, 25 Feb 2002 05:25:13 GMT", date.ToString("R", m_cultureInfo)); Assert.AreEqual("2002-02-25T05:25:13", date.ToString("s", m_cultureInfo)); Assert.AreEqual("5:25 AM", date.ToString("t", m_cultureInfo)); Assert.AreEqual("5:25:13 AM", date.ToString("T", m_cultureInfo)); Assert.AreEqual("2002-02-25 05:25:13Z", date.ToString("u", m_cultureInfo)); Assert.AreEqual("February, 2002", date.ToString("y", m_cultureInfo)); Assert.AreEqual("February, 2002", date.ToString("Y", m_cultureInfo)); Assert.AreEqual("2/25/2002 5:25:13 AM", date.ToString("", m_cultureInfo)); Assert.AreEqual("25", date.ToString("%d", m_cultureInfo)); Assert.AreEqual("25", date.ToString("dd", m_cultureInfo)); Assert.AreEqual("Mon", date.ToString("ddd", m_cultureInfo)); Assert.AreEqual("Monday", date.ToString("dddd", m_cultureInfo)); Assert.AreEqual("2", date.ToString("%M", m_cultureInfo)); Assert.AreEqual("02", date.ToString("MM", m_cultureInfo)); Assert.AreEqual("Feb", date.ToString("MMM", m_cultureInfo)); Assert.AreEqual("February", date.ToString("MMMM", m_cultureInfo)); Assert.AreEqual("2", date.ToString("%y", m_cultureInfo)); Assert.AreEqual("02", date.ToString("yy", m_cultureInfo)); Assert.AreEqual("2002", date.ToString("yyyy", m_cultureInfo)); Assert.AreEqual("5", date.ToString("%h", m_cultureInfo)); Assert.AreEqual("05", date.ToString("hh", m_cultureInfo)); Assert.AreEqual("A", date.ToString("%t", m_cultureInfo)); Assert.AreEqual("AM", date.ToString("tt", m_cultureInfo)); date = new GregorianDate(2009, 06, 10, 00, 30, 00); Assert.AreEqual("12", date.ToString("%h", m_cultureInfo)); Assert.AreEqual("0", date.ToString("%H", m_cultureInfo)); date = new GregorianDate(2002, 02, 25, 15, 25, 13); Assert.AreEqual("3", date.ToString("%h", m_cultureInfo)); Assert.AreEqual("03", date.ToString("hh", m_cultureInfo)); Assert.AreEqual("15", date.ToString("%H", m_cultureInfo)); Assert.AreEqual("15", date.ToString("HH", m_cultureInfo)); Assert.AreEqual("25", date.ToString("%m", m_cultureInfo)); Assert.AreEqual("25", date.ToString("mm", m_cultureInfo)); Assert.AreEqual("13", date.ToString("%s", m_cultureInfo)); Assert.AreEqual("13", date.ToString("ss", m_cultureInfo)); Assert.AreEqual("P", date.ToString("%t", m_cultureInfo)); Assert.AreEqual("PM", date.ToString("tt", m_cultureInfo)); Assert.AreEqual("A.D.", date.ToString("%g", m_cultureInfo)); Assert.AreEqual(" : ", date.ToString(" : ", m_cultureInfo)); Assert.AreEqual(" / ", date.ToString(" / ", m_cultureInfo)); Assert.AreEqual(" yyy ", date.ToString(" 'yyy' ", m_cultureInfo)); Assert.AreEqual(" d", date.ToString(" \\d", m_cultureInfo)); Assert.AreEqual("2002", date.ToString("yyy", m_cultureInfo)); Assert.AreEqual("0002002", date.ToString("yyyyyyy", m_cultureInfo)); date = new GregorianDate(999, 1, 2, 3, 4, 5); Assert.AreEqual("999", date.ToString("yyy", m_cultureInfo)); Assert.AreEqual("0999", date.ToString("yyyy", m_cultureInfo)); date = new GregorianDate(2009, 06, 10, 15, 0, 13.012345678912345); Assert.AreEqual("13.012345678912345", date.ToString("ss.fffffffffffffff")); date = new GregorianDate(2009, 06, 10, 15, 0, 13.012); Assert.AreEqual("13.012000000000000", date.ToString("ss.fffffffffffffff")); Assert.AreEqual("13.012", date.ToString("ss.FFFFFFFFFFFFFFF")); }
public void TestJulianSecondsOfDay() { const double julianSecondsOfDay = 0.05486; GregorianDate gd = new GregorianDate(new JulianDate(0, julianSecondsOfDay, TimeStandard.CoordinatedUniversalTime)); Assert.AreEqual(julianSecondsOfDay, gd.JulianSecondsOfDay, Constants.Epsilon11); }
public void CanConstructFromDateTime() { GregorianDate gregorianDate = new GregorianDate(2008, 10, 23, 23, 59, 59.999); GregorianDate constructedFromDateTime = new GregorianDate(new DateTime(2008, 10, 23, 23, 59, 59, 999)); Assert.AreEqual(gregorianDate, constructedFromDateTime); }
public void TestComparisonsOfTimePortion() { GregorianDate gd1 = new GregorianDate(1999, 10, 10, 6, 3, 14); GregorianDate gd2 = new GregorianDate(1999, 10, 10, 6, 3, 14); GregorianDate gd3 = new GregorianDate(1999, 10, 10, 6, 5, 26); object gd4 = new GregorianDate(1999, 10, 10, 4, 2, 21); Assert.IsTrue(gd1 == gd2); Assert.IsTrue(gd2 == gd1); Assert.IsTrue(gd1 != gd3); Assert.IsTrue(gd1 >= gd2); Assert.IsTrue(gd1 <= gd2); Assert.IsTrue(gd1.CompareTo(gd2) == 0); Assert.IsTrue(gd2 < gd3); Assert.IsTrue(gd2 <= gd3); Assert.IsTrue(gd3 > gd2); Assert.IsTrue(gd3 >= gd2); Assert.AreNotEqual(gd1, gd4); }
public void TestDayOfYear() { GregorianDate date = new GregorianDate(2000, 1, 1); Assert.AreEqual(date.DayOfYear, 1); date = new GregorianDate(2000, 2, 1); Assert.AreEqual(date.DayOfYear, 32); date = new GregorianDate(2003, 12, 31); Assert.AreEqual(date.DayOfYear, 365); date = new GregorianDate(2004, 12, 31); Assert.AreEqual(date.DayOfYear, 366); date = new GregorianDate(2000, 250); Assert.AreEqual(date.DayOfYear, 250); date = new GregorianDate(2000, 250.5); Assert.AreEqual(date.DayOfYear, 250); }
public void CanConvertGregorianDateRepresentingLeapSecondToJulianDate() { GregorianDate leapSecondGregorianDate = new GregorianDate(2008, 12, 31, 23, 59, 60); JulianDate leapSecondJulianDate = leapSecondGregorianDate.ToJulianDate(); Assert.AreEqual(leapSecondGregorianDate, leapSecondJulianDate.ToGregorianDate()); GregorianDate oneSecondLater = new GregorianDate(2009, 1, 1, 0, 0, 0); GregorianDate oneSecondBefore = new GregorianDate(2008, 12, 31, 23, 59, 59); Assert.AreEqual(1, oneSecondLater.ToJulianDate().Subtract(leapSecondJulianDate).Seconds); Assert.AreEqual(1, leapSecondJulianDate.Subtract(oneSecondBefore.ToJulianDate()).Seconds); }
public void CanConvertToJulianDate() { { GregorianDate gregorianDate = new GregorianDate(2008, 10, 23, 23, 59, 59.999); JulianDate julianDate = gregorianDate.ToJulianDate(); GregorianDate newGregorianDate = new GregorianDate(julianDate); Assert.AreEqual(gregorianDate.Year, newGregorianDate.Year); Assert.AreEqual(gregorianDate.Month, newGregorianDate.Month); Assert.AreEqual(gregorianDate.Day, newGregorianDate.Day); Assert.AreEqual(gregorianDate.Hour, newGregorianDate.Hour); Assert.AreEqual(gregorianDate.Minute, newGregorianDate.Minute); Assert.AreEqual(gregorianDate.Second, newGregorianDate.Second, Constants.Epsilon11); } { GregorianDate gregorianDate = new GregorianDate(2008, 10, 23, 01, 01, 01); JulianDate julianDate = gregorianDate.ToJulianDate(); GregorianDate newGregorianDate = new GregorianDate(julianDate); Assert.AreEqual(gregorianDate.Year, newGregorianDate.Year); Assert.AreEqual(gregorianDate.Month, newGregorianDate.Month); Assert.AreEqual(gregorianDate.Day, newGregorianDate.Day); Assert.AreEqual(gregorianDate.Hour, newGregorianDate.Hour); Assert.AreEqual(gregorianDate.Minute, newGregorianDate.Minute); Assert.AreEqual(gregorianDate.Second, newGregorianDate.Second, Constants.Epsilon11); } }
public void TestNonStandardTimeStandard() { GregorianDate gregorianDate = new GregorianDate(2008, 12, 31, 23, 59, 40); JulianDate jd = gregorianDate.ToJulianDate(TimeStandard.InternationalAtomicTime); Assert.AreEqual(TimeStandard.InternationalAtomicTime, jd.Standard); GregorianDate roundTrip1 = jd.ToGregorianDate(TimeStandard.InternationalAtomicTime); Assert.AreEqual(gregorianDate, roundTrip1); GregorianDate roundTrip = new GregorianDate(jd); Assert.AreNotEqual(gregorianDate, roundTrip); double expectedDifference = LeapSeconds.Instance.GetTaiMinusUtc(jd); Assert.AreEqual(expectedDifference, gregorianDate.Second - roundTrip.Second); }
public void TestRoundTripDefaultConstructed() { GregorianDate gd = new GregorianDate(); GregorianDate gd2 = new GregorianDate(gd.ToJulianDate()); Assert.AreEqual(gd, gd2); }
public void TestToStringThreadFormatProvider() { CultureInfo originalCulture = Thread.CurrentThread.CurrentCulture; try { Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); GregorianDate gd1 = new GregorianDate(2001, 1, 1, 6, 3, 14); Assert.AreEqual("1/1/2001 6:03:14 AM", gd1.ToString()); Assert.AreEqual("Monday, January 01, 2001", gd1.ToLongDateString()); Assert.AreEqual("6:03:14 AM", gd1.ToLongTimeString()); Assert.AreEqual("1/1/2001", gd1.ToShortDateString()); Assert.AreEqual("6:03 AM", gd1.ToShortTimeString()); gd1 = new GregorianDate(2003, 3, 4, 16, 43, 23.23452); Assert.AreEqual("3/4/2003 4:43:23 PM", gd1.ToString()); Assert.AreEqual("Tuesday, March 04, 2003", gd1.ToLongDateString()); Assert.AreEqual("4:43:23 PM", gd1.ToLongTimeString()); Assert.AreEqual("3/4/2003", gd1.ToShortDateString()); Assert.AreEqual("4:43 PM", gd1.ToShortTimeString()); } finally { Thread.CurrentThread.CurrentCulture = originalCulture; } }
public void GregorianDateToJulian() { GregorianDate gregorianDate = new GregorianDate(2000, 1, 1, 12, 0, 0); JulianDate julianDate = new JulianDate(gregorianDate); Assert.AreEqual(2451545.0, julianDate.TotalDays); gregorianDate = new GregorianDate(2006, 1, 1, 0, 0, 0); julianDate = new JulianDate(gregorianDate); Assert.AreEqual(2453736.5, julianDate.TotalDays); gregorianDate = new GregorianDate(1973, 1, 1, 0, 0, 0); julianDate = new JulianDate(gregorianDate); Assert.AreEqual(2441683.5, julianDate.TotalDays); DateTime localDateTime = new DateTime(2000, 1, 1, 12, 0, 0, DateTimeKind.Local); DateTime utc = localDateTime.ToUniversalTime(); julianDate = new JulianDate(localDateTime); gregorianDate = julianDate.ToGregorianDate(); Assert.AreEqual(new GregorianDate(utc), gregorianDate); }
public void CanConstructGregorianDateRepresentingLeapSecond() { GregorianDate date = new GregorianDate(2008, 12, 31, 23, 59, 60); Assert.AreEqual(60, date.Second, Constants.Epsilon14); }
public void JulianDateGregorianDateRoundTrip() { GregorianDate gregorianDate = new GregorianDate(2008, 1, 1, 1, 1, 1.00000000008); JulianDate julianDate = new JulianDate(gregorianDate); GregorianDate roundTrip = julianDate.ToGregorianDate(); Assert.AreEqual(gregorianDate.Year, roundTrip.Year); Assert.AreEqual(gregorianDate.Month, roundTrip.Month); Assert.AreEqual(gregorianDate.Day, roundTrip.Day); Assert.AreEqual(gregorianDate.Hour, roundTrip.Hour); Assert.AreEqual(gregorianDate.Minute, roundTrip.Minute); Assert.AreEqual(gregorianDate.Second, roundTrip.Second, Constants.Epsilon13); }
public void TestYearDayConstructor() { DateTime aTime = new DateTime(2000, 2, 28, 1, 3, 4); Assert.AreEqual(31 + 28, aTime.DayOfYear);//* January has 31 days, so add 28 to that... GregorianDate sameDate = new GregorianDate(aTime.Year, aTime.DayOfYear); Assert.AreEqual(2000, sameDate.Year); Assert.AreEqual(59, sameDate.DayOfYear); Assert.AreEqual(2, sameDate.Month); Assert.AreEqual(0, sameDate.Hour); Assert.AreEqual(0, sameDate.Minute); Assert.AreEqual(0, sameDate.Second); 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.AreEqual(2000, sameDate.Year); Assert.AreEqual(60, sameDate.DayOfYear); Assert.AreEqual(2, sameDate.Month); //* leap year Assert.AreEqual(14, sameDate.Hour); Assert.AreEqual(24, sameDate.Minute); Assert.AreEqual(0, sameDate.Second, Constants.Epsilon9); //* Richard and Michael both said this is ok }
public void TestFormattingLeapSecond() { GregorianDate date = new GregorianDate(2008, 12, 31, 23, 59, 60.444); Assert.AreEqual("31 Dec 2008 23:59:60.444", date.ToString("d MMM yyyy H:mm:ss.fff", m_cultureInfo)); }
public void ToIso8601StringProducesCorrectStrings() { string iso = new GregorianDate(2012, 4, 2, 1, 2, 3.12345).ToIso8601String(); Assert.AreEqual("2012-04-02T01:02:03.12345Z", iso); iso = new GregorianDate(2012, 4, 2, 1, 2, 3).ToIso8601String(); Assert.AreEqual("2012-04-02T01:02:03Z", iso); iso = new GregorianDate(2012, 4, 2, 1, 2, 3).ToIso8601String(); Assert.AreEqual("2012-04-02T01:02:03Z", iso); iso = new GregorianDate(2012, 4, 2, 1, 2, 0).ToIso8601String(); Assert.AreEqual("2012-04-02T01:02:00Z", iso); iso = new GregorianDate(2012, 4, 2, 1, 2, 0).ToIso8601String(); Assert.AreEqual("2012-04-02T01:02:00Z", iso); iso = new GregorianDate(2012, 6, 30, 23, 59, 60.123).ToIso8601String(); Assert.AreEqual("2012-06-30T23:59:60.123Z", iso); }
public void TestGetHashCode() { GregorianDate date = new GregorianDate(2001, 1, 1, 6, 3, 14); GregorianDate sameDate = new GregorianDate(2001, 1, 1, 6, 3, 14); GregorianDate differentTime = new GregorianDate(2001, 1, 1, 6, 5, 26); GregorianDate differentDay = new GregorianDate(2001, 2, 3, 6, 3, 14); Assert.AreEqual(date.GetHashCode(), sameDate.GetHashCode()); Assert.AreNotEqual(date.GetHashCode(), differentTime.GetHashCode()); Assert.AreNotEqual(date.GetHashCode(), differentDay.GetHashCode()); }
public void TestConversionToJulianDate() { GregorianDate date = new GregorianDate(2008, 12, 31, 23, 59, 0); JulianDate julianDate = date.ToJulianDate(); GregorianDate oneSecondLater = new GregorianDate(2008, 12, 31, 23, 59, 1); GregorianDate oneSecondBefore = new GregorianDate(2008, 12, 31, 23, 58, 59); Assert.AreEqual(1, oneSecondLater.ToJulianDate().Subtract(julianDate).Seconds); Assert.AreEqual(1, julianDate.Subtract(oneSecondBefore.ToJulianDate()).Seconds); }
public void CanConstructFromJulianDate() { { JulianDate jd = new JulianDate(new DateTime(2008, 10, 23, 12, 5, 30, 300)); GregorianDate gd = new GregorianDate(jd); Assert.AreEqual(2008, gd.Year); Assert.AreEqual(10, gd.Month); Assert.AreEqual(23, gd.Day); Assert.AreEqual(12, gd.Hour); Assert.AreEqual(5, gd.Minute); Assert.AreEqual(30.300, gd.Second, Constants.Epsilon11); } { JulianDate jd = new JulianDate(new DateTime(2008, 10, 23, 0, 0, 0)); GregorianDate gd = new GregorianDate(jd); Assert.AreEqual(2008, gd.Year); Assert.AreEqual(10, gd.Month); Assert.AreEqual(23, gd.Day); Assert.AreEqual(0, gd.Hour); Assert.AreEqual(0, gd.Minute); Assert.AreEqual(0.0, gd.Second, Constants.Epsilon11); } { JulianDate jd = new JulianDate(new DateTime(2008, 10, 23, 23, 59, 59, 999)); GregorianDate gd = new GregorianDate(jd); Assert.AreEqual(2008, gd.Year); Assert.AreEqual(10, gd.Month); Assert.AreEqual(23, gd.Day); Assert.AreEqual(23, gd.Hour); Assert.AreEqual(59, gd.Minute); Assert.AreEqual(59.999, gd.Second, Constants.Epsilon11); } }