From b370fd3787ee68db58dd30931409f556bc9a324a Mon Sep 17 00:00:00 2001 From: Andrey Date: Mon, 10 Jun 2019 12:35:55 +0300 Subject: [PATCH] fixed incorrect 24 hours value in temperature forecast --- taf.go | 8 +++++++- taf_test.go | 13 +++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/taf.go b/taf.go index 8db7890..6846e13 100644 --- a/taf.go +++ b/taf.go @@ -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) diff --git a/taf_test.go b/taf_test.go index 78d4035..b5a49df 100644 --- a/taf_test.go +++ b/taf_test.go @@ -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) {