Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/Metar.Decoder/ChunkDecoder/DatetimeChunkDecoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down Expand Up @@ -39,6 +40,27 @@ public override Dictionary<string, object> 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);
}

Expand Down
10 changes: 8 additions & 2 deletions src/Metar.Decoder/Entity/DecodedMetar.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;

namespace Metar.Decoder.Entity
Expand Down Expand Up @@ -78,10 +79,15 @@ public ReadOnlyCollection<MetarChunkDecoderException> DecodingExceptions
public int? Day { get; set; }

/// <summary>
/// Time of the observation, as a string
/// Time of observation, as a string
/// </summary>
public string Time { get; set; } = string.Empty;

/// <summary>
/// Date and time of observation
/// </summary>
public DateTime? ObservationDateTime { get; set; }

/// <summary>
/// Report status (AUTO or NIL)
/// </summary>
Expand Down
22 changes: 22 additions & 0 deletions src/Taf.Decoder/ChunkDecoder/DatetimeChunkDecoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down Expand Up @@ -38,6 +39,27 @@ public override Dictionary<string, object> 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);
}

Expand Down
8 changes: 7 additions & 1 deletion src/Taf.Decoder/Entity/DecodedTaf.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;

namespace Taf.Decoder.entity
Expand Down Expand Up @@ -69,6 +70,11 @@ public ReadOnlyCollection<TafChunkDecoderException> DecodingExceptions
/// </summary>
public string Time { get; set; } = string.Empty;

/// <summary>
/// Date and time of origin
/// </summary>
public DateTime? OriginDateTime { get; set; }

/// <summary>
/// Forecast period
/// </summary>
Expand Down
Loading