diff --git a/src/Metar.Decoder/ChunkDecoder/DatetimeChunkDecoder.cs b/src/Metar.Decoder/ChunkDecoder/DatetimeChunkDecoder.cs index 816fc36..f2ff3b5 100644 --- a/src/Metar.Decoder/ChunkDecoder/DatetimeChunkDecoder.cs +++ b/src/Metar.Decoder/ChunkDecoder/DatetimeChunkDecoder.cs @@ -7,6 +7,7 @@ public sealed class DatetimeChunkDecoder : MetarChunkDecoder { public const string DayParameterName = "Day"; public const string TimeParameterName = "Time"; + public const string ObservationDateTimeParameterName = "ObservationDateTime"; public override string GetRegex() { @@ -39,6 +40,27 @@ public override Dictionary Parse(string remainingMetar, bool wit result.Add(DayParameterName, day); result.Add(TimeParameterName, $"{hour:00}:{minute:00} UTC"); + // Create DateTime from parsed components + var currentYear = DateTime.Now.Year; + var month = DateTime.Now.Month; + + // Handle day/year rollover - if day > current day, assume previous month + if (day > DateTime.Now.Day) + { + if (month == 1) + { + month = 12; + currentYear--; + } + else + { + month--; + } + } + + var observationDateTime = new DateTime(currentYear, month, day, hour, minute, 0, DateTimeKind.Utc); + result.Add(ObservationDateTimeParameterName, observationDateTime); + return GetResults(newRemainingMetar, result); } diff --git a/src/Metar.Decoder/Entity/DecodedMetar.cs b/src/Metar.Decoder/Entity/DecodedMetar.cs index 554d665..039fe02 100644 --- a/src/Metar.Decoder/Entity/DecodedMetar.cs +++ b/src/Metar.Decoder/Entity/DecodedMetar.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Collections.ObjectModel; namespace Metar.Decoder.Entity @@ -78,10 +79,15 @@ public ReadOnlyCollection DecodingExceptions public int? Day { get; set; } /// - /// Time of the observation, as a string + /// Time of observation, as a string /// public string Time { get; set; } = string.Empty; + /// + /// Date and time of observation + /// + public DateTime? ObservationDateTime { get; set; } + /// /// Report status (AUTO or NIL) /// diff --git a/src/Taf.Decoder/ChunkDecoder/DatetimeChunkDecoder.cs b/src/Taf.Decoder/ChunkDecoder/DatetimeChunkDecoder.cs index 456bbc8..cb93602 100644 --- a/src/Taf.Decoder/ChunkDecoder/DatetimeChunkDecoder.cs +++ b/src/Taf.Decoder/ChunkDecoder/DatetimeChunkDecoder.cs @@ -7,6 +7,7 @@ public sealed class DatetimeChunkDecoder : TafChunkDecoder { public const string DayParameterName = "Day"; public const string TimeParameterName = "Time"; + public const string OriginDateTimeParameterName = "OriginDateTime"; public override string GetRegex() { @@ -38,6 +39,27 @@ public override Dictionary Parse(string remainingTaf, bool withC result.Add(DayParameterName, day); result.Add(TimeParameterName, $"{hour:00}:{minute:00} UTC"); + // Create DateTime from parsed components + var currentYear = DateTime.Now.Year; + var month = DateTime.Now.Month; + + // Handle day/year rollover - if day > current day, assume previous month + if (day > DateTime.Now.Day) + { + if (month == 1) + { + month = 12; + currentYear--; + } + else + { + month--; + } + } + + var originDateTime = new DateTime(currentYear, month, day, hour, minute, 0, DateTimeKind.Utc); + result.Add(OriginDateTimeParameterName, originDateTime); + return GetResults(newRemainingTaf, result); } diff --git a/src/Taf.Decoder/Entity/DecodedTaf.cs b/src/Taf.Decoder/Entity/DecodedTaf.cs index 81b1897..9fed6b9 100644 --- a/src/Taf.Decoder/Entity/DecodedTaf.cs +++ b/src/Taf.Decoder/Entity/DecodedTaf.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Collections.ObjectModel; namespace Taf.Decoder.entity @@ -69,6 +70,11 @@ public ReadOnlyCollection DecodingExceptions /// public string Time { get; set; } = string.Empty; + /// + /// Date and time of origin + /// + public DateTime? OriginDateTime { get; set; } + /// /// Forecast period ///