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
            const string first    = "1986-";
            const 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 ParseThrowsWithNullInputWithoutCultureInfo()
        {
            // ReSharper disable once AssignNullToNotNullAttribute
            var exception = Assert.Throws <ArgumentNullException>(() => GregorianDate.Parse(null));

            Assert.AreEqual("s", exception.ParamName);
        }
        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);
        }
        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);
        }
        public void ToIso8601BasicStringProducesCorrectStrings(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.Basic);

            Assert.AreEqual(expectedIsoString, isoString);
            Assert.AreEqual(gregorianDate, GregorianDate.Parse(isoString));
        }
        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 TestToIso8601String()
        {
            // Full format
            const string  isoString = "1985-04-12T10:15:30Z";
            GregorianDate iso       = new GregorianDate(1985, 4, 12, 10, 15, 30);
            GregorianDate result    = GregorianDate.Parse(isoString);

            Assert.AreEqual(iso, result);
            string resultString = result.ToIso8601String();

            Assert.AreEqual(isoString, resultString);
            Assert.AreEqual(isoString, iso.ToIso8601String());
        }
Exemple #9
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)));
        }
Exemple #10
0
        public static void Main(string[] args)
        {
            // use a fixed seed so repeated invocations use the same colors
            var rng = new Random(0);

            var files = new[]
            {
                @"ISS11_07_image_data.csv",
                @"ISS11_11_image_data.csv",
                @"ISS12_01_image_data.csv",
                @"ISS12_07_2_image_data.csv",
                @"ISS12_11_image_data.csv",
                @"ISS13_01_image_data.csv",
                @"ISS11_04_image_data.csv"
            };

            List <KeyValuePair <string, string> > missions = new List <KeyValuePair <string, string> >();

            foreach (var fileName in files)
            {
                string   csvFile = Path.Combine(AssetsDirectory, "CSV", fileName);
                string[] lines   = File.ReadAllLines(csvFile);

                string czmlFile = Path.Combine(AssetsDirectory, "CZML", Path.ChangeExtension(fileName, ".czml"));
                string jsonFile = Path.Combine(AssetsDirectory, "JSON", Path.ChangeExtension(fileName, ".json"));

                using (StreamWriter czmlWriter = new StreamWriter(czmlFile))
                    using (StreamWriter jsonWriter = new StreamWriter(jsonFile))
                        using (CesiumOutputStream czmlOutputStream = new CesiumOutputStream(czmlWriter))
                        {
                            czmlOutputStream.PrettyFormatting = false;
                            czmlOutputStream.WriteStartSequence();

                            List <string> ID          = new List <string>();
                            List <string> Time        = new List <string>();
                            List <string> School      = new List <string>();
                            List <string> ImageUrl    = new List <string>();
                            List <string> LensSize    = new List <string>();
                            List <string> OrbitNumber = new List <string>();
                            List <string> FrameWidth  = new List <string>();
                            List <string> FrameHeight = new List <string>();
                            List <string> Page        = new List <string>();
                            List <string> CZML        = new List <string>();

                            GregorianDate start = new GregorianDate();
                            for (int i = 1; i < lines.Length; i++)
                            {
                                string   line   = lines[i];
                                string[] tokens = line.Split(',');
                                for (int q = 0; q < tokens.Length; q++)
                                {
                                    tokens[q] = tokens[q].Trim('"').Trim();
                                }

                                if (i == 1)
                                {
                                    start = GregorianDate.Parse(tokens[17]);
                                    missions.Add(new KeyValuePair <string, string>(Path.ChangeExtension(fileName, null), tokens[18]));
                                }
                                else if (i == lines.Length - 1)
                                {
                                    Console.WriteLine(Path.GetFileNameWithoutExtension(fileName));
                                    Console.WriteLine(start.ToJulianDate().TotalDays + " JDate");
                                    var stop = GregorianDate.Parse(tokens[17]);
                                    Console.WriteLine(stop.ToJulianDate().TotalDays + " JDate");
                                    Console.WriteLine();
                                    //Console.WriteLine((stop.ToJulianDate() - start.ToJulianDate()).TotalDays);
                                }

                                var writer = new CesiumStreamWriter();
                                using (var packet = writer.OpenPacket(czmlOutputStream))
                                {
                                    packet.WriteId(tokens[0]);
                                    using (var vertexPositions = packet.OpenVertexPositionsProperty())
                                    {
                                        var points = new Cartographic[] {
                                            new Cartographic(double.Parse(tokens[5]), double.Parse(tokens[6]), 0),
                                            new Cartographic(double.Parse(tokens[7]), double.Parse(tokens[8]), 0),
                                            new Cartographic(double.Parse(tokens[9]), double.Parse(tokens[10]), 0),
                                            new Cartographic(double.Parse(tokens[11]), double.Parse(tokens[12]), 0)
                                        };
                                        vertexPositions.WriteCartographicDegrees(points);
                                    }
                                    using (var polygon = packet.OpenPolygonProperty())
                                    {
                                        polygon.WriteShowProperty(true);
                                        using (var material = polygon.OpenMaterialProperty())
                                        {
                                            using (var color = material.OpenSolidColorProperty())
                                            {
                                                color.WriteColorProperty(Color.FromArgb(255, (int)(rng.NextDouble() * 255), (int)(rng.NextDouble() * 255), (int)(rng.NextDouble() * 255)));
                                            }
                                        }
                                    }
                                }

                                for (int q = 0; q < tokens.Length; q++)
                                {
                                    tokens[q] = tokens[q].Replace("\"", "\\\"");
                                }

                                ID.Add(tokens[0]);
                                Time.Add(GregorianDate.Parse(tokens[17]).ToIso8601String(Iso8601Format.Compact));
                                School.Add(tokens[23]);
                                ImageUrl.Add(tokens[21].Split(new[] { '=' })[2]);
                                LensSize.Add(tokens[14]);
                                OrbitNumber.Add(tokens[19]);
                                FrameWidth.Add(tokens[15]);
                                FrameHeight.Add(tokens[16]);
                                Page.Add(tokens[20].Split(new[] { '=' })[1]);
                            }

                            czmlOutputStream.WriteEndSequence();

                            jsonWriter.WriteLine("{");
                            writeJsonArray(jsonWriter, "ID", ID);
                            jsonWriter.WriteLine(",");
                            writeJsonArray(jsonWriter, "Time", Time);
                            jsonWriter.WriteLine(",");
                            writeJsonArray(jsonWriter, "School", School);
                            jsonWriter.WriteLine(",");
                            writeJsonArray(jsonWriter, "ImageUrl", ImageUrl);
                            jsonWriter.WriteLine(",");
                            writeJsonArray(jsonWriter, "LensSize", LensSize);
                            jsonWriter.WriteLine(",");
                            writeJsonArray(jsonWriter, "OrbitNumber", OrbitNumber);
                            jsonWriter.WriteLine(",");
                            writeJsonArray(jsonWriter, "FrameWidth", FrameWidth);
                            jsonWriter.WriteLine(",");
                            writeJsonArray(jsonWriter, "FrameHeight", FrameHeight);
                            jsonWriter.WriteLine(",");
                            writeJsonArray(jsonWriter, "Page", Page);
                            jsonWriter.WriteLine();
                            jsonWriter.WriteLine("}");
                        }
            }

            using (StreamWriter missionsJsonWriter = new StreamWriter(Path.Combine(AssetsDirectory, "missions.json")))
            {
                missionsJsonWriter.Write("[");
                for (int i = 0; i < missions.Count; ++i)
                {
                    missionsJsonWriter.Write("{{\"file\":\"{0}\",\"name\":\"{1}\"}}", missions[i].Key, missions[i].Value);
                    if (i != missions.Count - 1)
                    {
                        missionsJsonWriter.Write(",");
                    }
                }
                missionsJsonWriter.Write("]");
            }
        }
 public void TestParseISO8601DayOfYearOutOfRange()
 {
     GregorianDate unused = GregorianDate.Parse("1985-367T02:00:05.2134");
 }
Exemple #12
0
 public void ParseThrowsOnNullInput()
 {
     GregorianDate.Parse(null, m_cultureInfo);
 }
        public void ParseThrowsFormatExceptionWhenNoMatch()
        {
            var exception = Assert.Throws <FormatException>(() => GregorianDate.Parse("February Q, 2009", m_cultureInfo));

            StringAssert.Contains("was not recognized as a valid GregorianDate", exception.Message);
        }
        public void TestParse()
        {
            GregorianDate expected = new GregorianDate(2002, 02, 25);

            Assert.AreEqual(expected, GregorianDate.Parse("02/25/2002", m_cultureInfo));
            Assert.AreEqual(expected, GregorianDate.Parse("2/25/2002", m_cultureInfo));
            Assert.AreEqual(expected, GregorianDate.Parse("2002-02-25", m_cultureInfo));
            Assert.AreEqual(expected, GregorianDate.Parse("2002-2-25", m_cultureInfo));
            Assert.AreEqual(expected, GregorianDate.Parse("Monday, 25 February 2002", m_cultureInfo));
            Assert.AreEqual(expected, GregorianDate.Parse("Mon,02/25/2002", m_cultureInfo));
            Assert.AreEqual(expected, GregorianDate.Parse("Mon,2/25/2002", m_cultureInfo));

            expected = new GregorianDate(2002, 02, 25, 05, 25, 00);
            Assert.AreEqual(expected, GregorianDate.Parse("Monday, 25 February 2002 05:25", m_cultureInfo));
            Assert.AreEqual(expected, GregorianDate.Parse("02/25/2002 05:25", m_cultureInfo));
            Assert.AreEqual(expected, GregorianDate.Parse("2/25/2002 05:25", m_cultureInfo));
            Assert.AreEqual(expected, GregorianDate.Parse("2/25/2002 5:25", m_cultureInfo));
            Assert.AreEqual(expected, GregorianDate.Parse("2002-02-25T05:25", m_cultureInfo));
            Assert.AreEqual(expected, GregorianDate.Parse("2002-2-25T05:25", m_cultureInfo));
            Assert.AreEqual(expected, GregorianDate.Parse("02-2002-25 05:25", m_cultureInfo));
            Assert.AreEqual(expected, GregorianDate.Parse("2-2002-25 05:25", m_cultureInfo));
            Assert.AreEqual(expected, GregorianDate.Parse("2-2002-25 5:25", m_cultureInfo));

            expected = new GregorianDate(2002, 02, 25, 05, 25, 13);
            Assert.AreEqual(expected, GregorianDate.Parse("Monday, 25 February 2002 05:25:13", m_cultureInfo));
            Assert.AreEqual(expected, GregorianDate.Parse("02/25/2002 05:25:13", m_cultureInfo));
            Assert.AreEqual(expected, GregorianDate.Parse("02/25/2002 5:25:13", m_cultureInfo));
            Assert.AreEqual(expected, GregorianDate.Parse("2/25/2002 5:25:13", m_cultureInfo));
            Assert.AreEqual(expected, GregorianDate.Parse("2002-02-25T05:25:13", m_cultureInfo));
            Assert.AreEqual(expected, GregorianDate.Parse("02-2002-25T05:25:13", m_cultureInfo));
            Assert.AreEqual(expected, GregorianDate.Parse("02-2002-25 05:25:13", m_cultureInfo));
            Assert.AreEqual(expected, GregorianDate.Parse("02-2002-25 5:25:13", m_cultureInfo));
            Assert.AreEqual(expected, GregorianDate.Parse("02-2002-25 05:25:13 Mon", m_cultureInfo));
            Assert.AreEqual(expected, GregorianDate.Parse("02-2002-25 5:25:13 Mon", m_cultureInfo));
            Assert.AreEqual(expected, GregorianDate.Parse("02-2002-25 05:25:13 Monday", m_cultureInfo));
            Assert.AreEqual(expected, GregorianDate.Parse("02-2002-25 5:25:13 Monday", m_cultureInfo));

            expected = new GregorianDate(2002, 02, 25, 04, 25, 13);
            Assert.AreEqual(expected, GregorianDate.Parse("2002-02-25 04:25:13Z", m_cultureInfo));
            Assert.AreEqual(expected, GregorianDate.Parse("Mon, 25 Feb 2002 04:25:13 GMT", m_cultureInfo));

            expected = new GregorianDate(2002, 02, 25, 05, 25, 13.008);
            Assert.AreEqual(expected, GregorianDate.Parse("02/25/2002 05:25:13.008", m_cultureInfo));
            Assert.AreEqual(expected, GregorianDate.Parse("02/25/2002 5:25:13.008", m_cultureInfo));
            Assert.AreEqual(expected, GregorianDate.Parse("2002-02-25T05:25:13.008", m_cultureInfo));
            Assert.AreEqual(expected, GregorianDate.Parse("02-2002-25T05:25:13.008", m_cultureInfo));
            Assert.AreEqual(expected, GregorianDate.Parse("02-2002-25 05:25:13.008", m_cultureInfo));
            Assert.AreEqual(expected, GregorianDate.Parse("02-2002-25 5:25:13.008", m_cultureInfo));

            expected = new GregorianDate(DateTime.Today.Year, 02, 25);
            Assert.AreEqual(expected, GregorianDate.Parse("February 25", m_cultureInfo));

            expected = new GregorianDate(DateTime.Today.Year, 02, 8);
            Assert.AreEqual(expected, GregorianDate.Parse("February 08", m_cultureInfo));
            Assert.AreEqual(expected, GregorianDate.Parse("February 8", m_cultureInfo));

            expected = new GregorianDate(2002, 02, 1);
            Assert.AreEqual(expected, GregorianDate.Parse("2002 February", m_cultureInfo));

            expected = new GregorianDate(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day, 05, 25, 13.4444444);
            Assert.AreEqual(expected, GregorianDate.Parse("05:25:13.4444444", m_cultureInfo));

            expected = new GregorianDate(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day, 05, 25, 13.1234567);
            Assert.AreEqual(expected, GregorianDate.Parse("05:25:13.1234567", m_cultureInfo));

            expected = new GregorianDate(2009, 06, 30, 05, 25, 13.1234567890);
            Assert.AreEqual(expected, GregorianDate.Parse("06/30/2009 05:25:13.1234567890", m_cultureInfo));

            expected = new GregorianDate(2009, 06, 30, 05, 25, 13.44444444444444);
            Assert.AreEqual(expected, GregorianDate.Parse("06/30/2009 05:25:13.44444444444444", m_cultureInfo));

            expected = new GregorianDate(2009, 06, 30, 05, 25, 13.12345678901234);
            Assert.AreEqual(expected, GregorianDate.Parse("06/30/2009 05:25:13.12345678901234", m_cultureInfo));
            Assert.AreNotEqual(expected, GregorianDate.Parse("06/30/2009 05:25:13.12345678901239", m_cultureInfo));

            expected = new GregorianDate(2009, 06, 30, 05, 25, 13.444444444444444);
            Assert.AreEqual(expected, GregorianDate.Parse("06/30/2009 05:25:13.444444444444444", m_cultureInfo));
            Assert.AreNotEqual(expected, GregorianDate.Parse("06/30/2009 05:25:13.444444444444446", m_cultureInfo));

            expected = new GregorianDate(2009, 06, 30, 05, 25, 0.1234567890123456);
            Assert.AreEqual(expected, GregorianDate.Parse("06/30/2009 05:25:00.1234567890123456", m_cultureInfo));
            Assert.AreNotEqual(expected, GregorianDate.Parse("06/30/2009 05:25:00.1234567890123459", m_cultureInfo));

            expected = new GregorianDate(2009, 06, 30, 05, 25, 0.1234567890123456);

            GregorianDate parsed;

            GregorianDate.TryParse("06/30/2009 05:25:00.1234567890123456", out parsed);
            Assert.AreEqual(expected, parsed);
        }
Exemple #15
0
 public void ParseThrowsOnNullInputWithoutCultureInfo()
 {
     GregorianDate.Parse(null);
 }
Exemple #16
0
 public void ParseThrowsFormatExceptionWhenNoMatch()
 {
     GregorianDate.Parse("February Q, 2009", m_cultureInfo);
 }
Exemple #17
0
 public void TestParseISO8601DayOfYearError()
 {
     GregorianDate result = GregorianDate.Parse("1985-12#T02:00:05.2134");
 }
Exemple #18
0
 public void TestParseISO8601YearOutOfRange()
 {
     GregorianDate result = GregorianDate.Parse("21985-167T02:00:05.2134");
 }