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 ParseExactThrowsWithNullInput() { // ReSharper disable once AssignNullToNotNullAttribute var exception = Assert.Throws <ArgumentNullException>(() => GregorianDate.ParseExact(null, "dddd, dd MMMM yyyy HH:mm:ss", m_cultureInfo)); Assert.AreEqual("s", exception.ParamName); }
/// <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 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); }
private JulianDate ToJulianDate(string when) { GregorianDate whenDate; if (!GregorianDate.TryParse(when, out whenDate)) { whenDate = GregorianDate.ParseExact(when, Utility.ValidIso8601Formats, CultureInfo.CurrentCulture); } return(new JulianDate(whenDate)); }
private static TimeInterval GetTimeStamp(XElement timestamp, XNamespace docNamespace) { XElement whenElement = timestamp.Element(docNamespace + "when"); if (whenElement != null) { GregorianDate whenDate; if (!GregorianDate.TryParse(whenElement.Value, out whenDate)) { whenDate = GregorianDate.ParseExact(whenElement.Value, ValidIso8601Formats, CultureInfo.CurrentCulture); } return(new TimeInterval(new JulianDate(whenDate), new JulianDate(GregorianDate.MaxValue))); } return(null); }
public void TestParsingLeapSecond() { GregorianDate expected = new GregorianDate(2008, 12, 31, 23, 59, 60.444); Assert.AreEqual(expected, GregorianDate.ParseExact("31 Dec 2008 23:59:60.444", "dd MMM yyyy HH:mm:ss.fff", m_cultureInfo)); }
public void ParseExactThrowsOnInvalidFormat() { Assert.Throws <FormatException>(() => GregorianDate.ParseExact("1/1/2009", "dddd, dd MMMM yyyy HH:mm:ss", m_cultureInfo)); }
public void TestParseExact() { GregorianDate expected = new GregorianDate(2002, 02, 25); Assert.AreEqual(expected, GregorianDate.ParseExact(expected.ToString("d", m_cultureInfo), "d", m_cultureInfo)); Assert.AreEqual(expected, GregorianDate.ParseExact(expected.ToString("D", m_cultureInfo), "D", m_cultureInfo)); expected = new GregorianDate(2002, 02, 25, 05, 25, 00); Assert.AreEqual(expected, GregorianDate.ParseExact(expected.ToString("f", m_cultureInfo), "f", m_cultureInfo)); Assert.AreEqual(expected, GregorianDate.ParseExact(expected.ToString("g", m_cultureInfo), "g", m_cultureInfo)); expected = new GregorianDate(2002, 02, 25, 05, 25, 13); Assert.AreEqual(expected, GregorianDate.ParseExact(expected.ToString("F", m_cultureInfo), "F", m_cultureInfo)); Assert.AreEqual(expected, GregorianDate.ParseExact(expected.ToString("G", m_cultureInfo), "G", m_cultureInfo)); Assert.AreEqual(expected, GregorianDate.ParseExact(expected.ToString("s", m_cultureInfo), "s", m_cultureInfo)); Assert.AreEqual(expected, GregorianDate.ParseExact("Monday, 25 February 2002 05:25:13", "dddd, dd MMMM yyyy HH:mm:ss", m_cultureInfo)); expected = new GregorianDate(2002, 02, 25, 04, 25, 13); Assert.AreEqual(expected, GregorianDate.ParseExact(expected.ToString("U", m_cultureInfo), "U", m_cultureInfo)); Assert.AreEqual(expected, GregorianDate.ParseExact(expected.ToString("u", m_cultureInfo), "u", m_cultureInfo)); Assert.AreEqual(expected, GregorianDate.ParseExact(expected.ToString("r", m_cultureInfo), "r", m_cultureInfo)); Assert.AreEqual(expected, GregorianDate.ParseExact(expected.ToString("R", m_cultureInfo), "R", m_cultureInfo)); expected = new GregorianDate(DateTime.Today.Year, 02, 25); Assert.AreEqual(expected, GregorianDate.ParseExact(expected.ToString("m", m_cultureInfo), "m", m_cultureInfo)); Assert.AreEqual(expected, GregorianDate.ParseExact(expected.ToString("M", m_cultureInfo), "M", m_cultureInfo)); expected = new GregorianDate(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day, 05, 25, 00); Assert.AreEqual(expected, GregorianDate.ParseExact(expected.ToString("t", m_cultureInfo), "t", m_cultureInfo)); expected = new GregorianDate(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day, 05, 25, 13); Assert.AreEqual(expected, GregorianDate.ParseExact(expected.ToString("T", m_cultureInfo), "T", m_cultureInfo)); expected = new GregorianDate(2002, 02, 1); Assert.AreEqual(expected, GregorianDate.ParseExact(expected.ToString("y", m_cultureInfo), "y", m_cultureInfo)); Assert.AreEqual(expected, GregorianDate.ParseExact(expected.ToString("Y", m_cultureInfo), "Y", m_cultureInfo)); expected = new GregorianDate(DateTime.Today.Year, 1, 25); Assert.AreEqual(expected, GregorianDate.ParseExact("25", "%d", m_cultureInfo)); Assert.AreEqual(expected, GregorianDate.ParseExact("25", "dd", m_cultureInfo)); expected = new GregorianDate(DateTime.Today.Year, 2, 1); Assert.AreEqual(expected, GregorianDate.ParseExact("2", "%M", m_cultureInfo)); Assert.AreEqual(expected, GregorianDate.ParseExact("02", "MM", m_cultureInfo)); Assert.AreEqual(expected, GregorianDate.ParseExact("Feb", "MMM", m_cultureInfo)); Assert.AreEqual(expected, GregorianDate.ParseExact("February", "MMMM", m_cultureInfo)); expected = new GregorianDate(2005, 1, 1); Assert.AreEqual(expected, GregorianDate.ParseExact("5", "%y", m_cultureInfo)); Assert.AreEqual(expected, GregorianDate.ParseExact("05", "yy", m_cultureInfo)); Assert.AreEqual(expected, GregorianDate.ParseExact("2005", "yyyy", m_cultureInfo)); expected = new GregorianDate(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day, 5, 0, 0); Assert.AreEqual(expected, GregorianDate.ParseExact("5A", "ht", m_cultureInfo)); Assert.AreEqual(expected, GregorianDate.ParseExact("05A", "hht", m_cultureInfo)); Assert.AreEqual(expected, GregorianDate.ParseExact("5", "%H", m_cultureInfo)); Assert.AreEqual(expected, GregorianDate.ParseExact("05", "HH", m_cultureInfo)); expected = new GregorianDate(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day, 15, 0, 0); Assert.AreEqual(expected, GregorianDate.ParseExact("3P", "ht", m_cultureInfo)); Assert.AreEqual(expected, GregorianDate.ParseExact("03P", "hht", m_cultureInfo)); Assert.AreEqual(expected, GregorianDate.ParseExact("15", "%H", m_cultureInfo)); Assert.AreEqual(expected, GregorianDate.ParseExact("15", "HH", m_cultureInfo)); expected = new GregorianDate(2002, 02, 25, 05, 25, 13.444); Assert.AreEqual(expected, GregorianDate.ParseExact("Monday, 25 February 2002 05:25:13.444", "dddd, dd MMMM yyyy HH:mm:ss.fff", m_cultureInfo)); expected = new GregorianDate(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day, 05, 25, 13.4444444); Assert.AreEqual(expected, GregorianDate.ParseExact("05:25:13.4444444", "HH:mm:ss.fffffff", m_cultureInfo)); expected = new GregorianDate(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day, 05, 25, 13.1234567); Assert.AreEqual(expected, GregorianDate.ParseExact("05:25:13.1234567", "HH:mm:ss.fffffff", m_cultureInfo)); expected = new GregorianDate(2009, 06, 30, 05, 25, 13.1234567890); Assert.AreEqual(expected, GregorianDate.ParseExact("06/30/2009 05:25:13.1234567890", "MM/dd/yyyy HH:mm:ss.ffffffffff", m_cultureInfo)); expected = new GregorianDate(2009, 06, 30, 05, 25, 13.44444444444444); Assert.AreEqual(expected, GregorianDate.ParseExact("06/30/2009 05:25:13.44444444444444", "MM/dd/yyyy HH:mm:ss.ffffffffffffff", m_cultureInfo)); expected = new GregorianDate(2009, 06, 30, 05, 25, 13.12345678901234); Assert.AreEqual(expected, GregorianDate.ParseExact("06/30/2009 05:25:13.12345678901234", "MM/dd/yyyy HH:mm:ss.ffffffffffffff", m_cultureInfo)); Assert.AreNotEqual(expected, GregorianDate.ParseExact("06/30/2009 05:25:13.123456789012345", "MM/dd/yyyy HH:mm:ss.fffffffffffffff", m_cultureInfo)); expected = new GregorianDate(2009, 06, 30, 05, 25, 13.444444444444444); Assert.AreEqual(expected, GregorianDate.ParseExact("06/30/2009 05:25:13.444444444444444", "MM/dd/yyyy HH:mm:ss.fffffffffffffff", m_cultureInfo)); Assert.AreNotEqual(expected, GregorianDate.ParseExact("06/30/2009 05:25:13.444444444444446", "MM/dd/yyyy HH:mm:ss.fffffffffffffff", m_cultureInfo)); expected = new GregorianDate(2009, 06, 30, 05, 25, 0.1234567890123456); Assert.AreEqual(expected, GregorianDate.ParseExact("06/30/2009 05:25:00.1234567890123456", "MM/dd/yyyy HH:mm:ss.ffffffffffffffff", m_cultureInfo)); Assert.AreNotEqual(expected, GregorianDate.ParseExact("06/30/2009 05:25:00.1234567890123459", "MM/dd/yyyy HH:mm:ss.ffffffffffffffff", m_cultureInfo)); }
public void ParseExactThrowsOnNullInput() { GregorianDate.ParseExact(null, "dddd, dd MMMM yyyy HH:mm:ss", m_cultureInfo); }
public void ParseExactThrowsOnNullFormat() { GregorianDate.ParseExact("1/1/2009", (string)null, m_cultureInfo); }
public void ParseExactThrowsOnInvalidFormat() { GregorianDate.ParseExact("1/1/2009", "dddd, dd MMMM yyyy HH:mm:ss", m_cultureInfo); }
public void ParseExactThrowsOnNullFormat() { string format = null; GregorianDate.ParseExact("1/1/2009", format, m_cultureInfo); }