Example #1
0
        public void WithCulture()
        {
            var pattern = OffsetDateTimePattern.CreateWithInvariantCulture("HH:mm").WithCulture(Cultures.DotTimeSeparator);
            var text    = pattern.Format(Instant.FromUtc(2000, 1, 1, 19, 30).WithOffset(Offset.Zero));

            Assert.AreEqual("19.30", text);
        }
Example #2
0
        public void WithCalendar()
        {
            var pattern = OffsetDateTimePattern.CreateWithInvariantCulture("yyyy-MM-dd")
                          .WithCalendar(CalendarSystem.Coptic);
            var parsed = pattern.Parse("0284-08-29").Value;

            Assert.AreEqual(new LocalDateTime(284, 8, 29, 0, 0, CalendarSystem.Coptic), parsed.LocalDateTime);
        }
Example #3
0
        public void WithPatternText()
        {
            var pattern = OffsetDateTimePattern.CreateWithInvariantCulture("yyyy-MM-dd").WithPatternText("HH:mm");
            var value   = Instant.FromUtc(1970, 1, 1, 11, 30).WithOffset(Offset.FromHours(2));
            var text    = pattern.Format(value);

            Assert.AreEqual("13:30", text);
        }
Example #4
0
        public void CreateWithInvariantCulture()
        {
            var pattern = OffsetDateTimePattern.CreateWithInvariantCulture("yyyy-MM-dd'T'HH:mm:sso<g>");

            Assert.AreSame(NodaFormatInfo.InvariantInfo, pattern.FormatInfo);
            var odt = new LocalDateTime(2017, 8, 23, 12, 34, 56).WithOffset(Offset.FromHours(2));

            Assert.AreEqual("2017-08-23T12:34:56+02", pattern.Format(odt));
        }
Example #5
0
        public void WithTemplateValue()
        {
            var pattern = OffsetDateTimePattern.CreateWithInvariantCulture("yyyy-MM-dd")
                          .WithTemplateValue(Instant.FromUtc(1970, 1, 1, 11, 30).WithOffset(Offset.FromHours(2)));
            var parsed = pattern.Parse("2017-08-23").Value;

            // Local time of template value was 13:30
            Assert.AreEqual(new LocalDateTime(2017, 8, 23, 13, 30, 0), parsed.LocalDateTime);
            Assert.AreEqual(Offset.FromHours(2), parsed.Offset);
        }
 public DateTimeFormatSpecification(string format)
 {
     if (format == null)
     {
         throw new ArgumentNullException(nameof(format));
     }
     _hasOffset = TimeFormatSpecification.HasOffset(format);
     if (_hasOffset)
     {
         _offsetPattern = OffsetDateTimePattern.CreateWithInvariantCulture(TimeFormatSpecification.GetNodaTimePattern(format));
     }
     else
     {
         _localPattern = LocalDateTimePattern.CreateWithInvariantCulture(TimeFormatSpecification.GetNodaTimePattern(format));
     }
 }
Example #7
0
        private bool TryGetOffsetPattern(string format, out IPattern <OffsetDateTime> pattern)
        {
            pattern = default;

            if (!(format.Contains("+o<HH:mm>") || format.EndsWith("Z")))
            {
                return(false);
            }

            try
            {
                pattern = OffsetDateTimePattern.CreateWithInvariantCulture(format);
            }
            catch
            {
                return(false);
            }
            return(true);
        }
        public void ExtractMetadataTest()
        {
            Stream stream = this.RealFileSystem.File.Open(Helpers.FixturesRoot + "/WA_SM4BAT/2.2.1_Normal/S4U09523_20210621_205706.wav", FileMode.Open, FileAccess.Read, FileShare.Read);

            var tryWamdData = Wamd.ExtractMetadata(stream);

            Assert.True(tryWamdData.IsSucc);

            Wamd wamdData = (Wamd)tryWamdData;

            ((OffsetDateTime)wamdData.StartDate).Should().Be(OffsetDateTimePattern.CreateWithInvariantCulture("G").Parse("2021-06-21T20:57:06-03:00").Value);
            wamdData.Name.Should().Be("SM4BAT-FS");
            wamdData.SerialNumber.Should().Be("S4U09523");
            wamdData.Firmware.Should().Be("2.2.1");
            wamdData.Temperature.Should().Be(24.25);
            wamdData.MicrophoneType.Should().AllBe("U2");
            wamdData.MicrophoneSensitivity.Should().AllBeEquivalentTo(13.0);
            wamdData.Latitude.Should().Be(45.7835);
            wamdData.Longitude.Should().Be(-64.23352);
        }
Example #9
0
        public static Record ParseRecord(Dictionary <string, string> pairs)
        {
            var pattern   = OffsetDateTimePattern.CreateWithInvariantCulture("yyyy-MM-dd HH:mm:ss o<M>");
            var startDate = pattern.Parse(pairs["startDate"]).Value.ToInstant();
            var endDate   = pattern.Parse(pairs["endDate"]).Value.ToInstant();

            pairs.TryGetValue("value", out var value);
            pairs.TryGetValue("unit", out var unit);
            pairs.TryGetValue("sourceName", out var sourceName);

            return(new Record
            {
                Type = pairs["type"],
                EndDate = endDate,
                StartDate = startDate,
                DateRange = new InstantRange(startDate, endDate),
                Value = value,
                Unit = unit,
                SourceName = sourceName,
            });
        }
Example #10
0
            public static Workout ParseWorkout(Dictionary <string, string> r)
            {
                var pattern = OffsetDateTimePattern.CreateWithInvariantCulture("yyyy-MM-dd HH:mm:ss o<M>");

                var startDate = pattern.Parse(r["startDate"]).Value.ToInstant();
                var endDate   = pattern.Parse(r["endDate"]).Value.ToInstant();

                r.TryGetValue("sourceName", out var sourceName);
                r.TryGetValue("device", out var device);

                return(new Workout
                {
                    WorkoutType = r["workoutActivityType"],
                    SourceName = sourceName,
                    EndDate = endDate,
                    StartDate = startDate,
                    Duration = WorkoutDuration(r),
                    Distance = Distance(r),
                    Energy = EnergyBurned(r),
                    Device = device,
                });
            }
Example #11
0
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine("Error: Expected at least 1 file");
                return;
            }

            OffsetDateTimePattern pattern = OffsetDateTimePattern.CreateWithInvariantCulture("uuuu'-'MM'-'dd'T'HH':'mm':'ss.FFFo<m>");

            List <XmlDocument> docs = new List <XmlDocument>();
            List <(OffsetDateTime, XmlDocument)> unorderedDocs = new List <(OffsetDateTime, XmlDocument)>();

            foreach (var file in args)
            {
                XmlDocument doc = new XmlDocument();
                try
                {
                    doc.Load(file);
                }
                catch (XmlException ex)
                {
                    Console.WriteLine(ex.Message);
                    return;
                }
                catch (FileNotFoundException ex)
                {
                    Console.WriteLine(ex.Message);
                    return;
                }

                var nodeList = doc.GetElementsByTagName("Id");
                var node     = nodeList.Item(0);
                ParseResult <OffsetDateTime> time = pattern.Parse(node.InnerText);
                if (!time.Success)
                {
                    Console.WriteLine($"Couldn't parse time: {node.InnerText}");
                    continue;
                }
                unorderedDocs.Add((time.Value, doc));
            }

            unorderedDocs.Sort((d1, d2) => {
                return(OffsetDateTime.Comparer.Local.Compare(d1.Item1, d2.Item1));
            });

            Console.WriteLine("Loaded in files");
            Console.Write("New file name: ");
            string newFileName = Console.ReadLine();

            foreach (var doc in unorderedDocs)
            {
                docs.Add(doc.Item2);
            }

            double totalTimeSeconds = 0;
            double distanceMeters   = 0;
            int    calories         = 0;

            foreach (var doc in docs)
            {
                var node = doc.GetElementsByTagName("TotalTimeSeconds").Item(0);
                totalTimeSeconds += double.Parse(node.InnerText);
                distanceMeters   += double.Parse(doc.GetElementsByTagName("DistanceMeters").Item(0).InnerText);
                calories         += int.Parse(doc.GetElementsByTagName("Calories").Item(0).InnerText);
            }

            docs[0].GetElementsByTagName("TotalTimeSeconds").Item(0).InnerText = totalTimeSeconds.ToString();
            docs[0].GetElementsByTagName("DistanceMeters").Item(0).InnerText   = distanceMeters.ToString();
            docs[0].GetElementsByTagName("Calories").Item(0).InnerText         = calories.ToString();

            XmlNode firstDocNode = docs[0].GetElementsByTagName("Track").Item(0);

            for (int i = 1; i < docs.Count; i++)
            {
                XmlDocument doc      = docs[i];
                var         nodeList = doc.GetElementsByTagName("Track").Item(0);
                foreach (XmlNode node in nodeList)
                {
                    XmlNode importedNode = docs[0].ImportNode(node, true);
                    firstDocNode.AppendChild(importedNode);
                }
            }

            docs[0].Save($"{newFileName}.tcx");
            Console.WriteLine("Done");
        }