Skip to content

Commit

Permalink
fixed incorrect 24 hours value in temperature forecast
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey committed Jun 10, 2019
1 parent abd5937 commit b370fd3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
8 changes: 7 additions & 1 deletion taf.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,13 @@ func (t *TAFMessage) addTempForecast(input string) bool {
}
tempf.IsMin = matches[1] == "N"
tempf.IsMax = matches[1] == "X"
tempf.DateTime, _ = time.Parse("2006010215Z", CurYearStr+CurMonthStr+matches[4])
if matches[4][2:] == "24Z" {
inputString := matches[4][:2] + "23"
tempf.DateTime, _ = time.Parse("2006010215", CurYearStr+CurMonthStr+inputString)
tempf.DateTime = tempf.DateTime.Add(time.Hour)
} else {
tempf.DateTime, _ = time.Parse("2006010215Z", CurYearStr+CurMonthStr+matches[4])
}
// if date in next month
if tempf.DateTime.Day() < t.DateTime.Day() {
tempf.DateTime = tempf.DateTime.AddDate(0, 1, 0)
Expand Down
13 changes: 13 additions & 0 deletions taf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,19 @@ var tafparsetests = []tafparsetest{
TemperatureForecast{Temp: 29, DateTime: time.Date(curYear, curMonth, 30, 12, 0, 0, 0, time.UTC), IsMax: true, IsMin: false},
TemperatureForecast{Temp: 16, DateTime: time.Date(curYear, curMonth+1, 1, 2, 0, 0, 0, time.UTC), IsMax: false, IsMin: true}},
NotDecodedTokens: nil}},
{"TAF ULLI 080756Z 0809/0909 18005MPS 9999 SCT025 TX30/0810Z TN18/0824Z",
&TAFMessage{rawData: "TAF ULLI 080756Z 0809/0909 18005MPS 9999 SCT025 TX30/0810Z TN18/0824Z",
COR: false, AMD: false, NIL: false, Station: "ULLI",
DateTime: time.Date(curYear, curMonth, 8, 7, 56, 0, 0, time.UTC),
ValidFrom: time.Date(curYear, curMonth, 8, 9, 0, 0, 0, time.UTC),
ValidTo: time.Date(curYear, curMonth, 9, 9, 0, 0, 0, time.UTC),
Visibility: Visibility{Distance: 9999, LowerDistance: 0, LowerDirection: ""},
Wind: getWind("18005MPS"),
Clouds: []clouds.Cloud{getCloud("SCT025")},
Temperature: []TemperatureForecast{
TemperatureForecast{Temp: 30, DateTime: time.Date(curYear, curMonth, 8, 10, 0, 0, 0, time.UTC), IsMax: true, IsMin: false},
TemperatureForecast{Temp: 18, DateTime: time.Date(curYear, curMonth, 9, 0, 0, 0, 0, time.UTC), IsMax: false, IsMin: true}},
NotDecodedTokens: nil}},
}

func TestDecodeTAF(t *testing.T) {
Expand Down

0 comments on commit b370fd3

Please sign in to comment.