From de686ef53d068a51ab2f0131645e880829dd4a52 Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Thu, 4 Feb 2021 00:51:04 +0100 Subject: [PATCH] Implement horodate parsing --- main.go | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 2d290c8..781023b 100644 --- a/main.go +++ b/main.go @@ -55,6 +55,29 @@ func computeChecksum(area []byte) (checksum byte) { return } +func getHorodate(fields *[][]byte) (horodate time.Time, err error) { + if len(*fields) == 4 && len((*fields)[1]) == 13 { + horodate, err = time.Parse("060102150405", string((*fields)[1][1:])) + if err != nil { + horodate = time.Now().Truncate(time.Second).UTC() + } + + // Handle "saison" + if (*fields)[1][0] == 'E' || (*fields)[1][0] == 'e' { + horodate = horodate.Add(2 * time.Hour) + } else { + horodate = horodate.Add(1 * time.Hour) + } + + // Mark field as treated + *fields = append((*fields)[:1], (*fields)[2:]...) + } else { + horodate = time.Now().Truncate(time.Second).UTC() + } + + return +} + func treatLines(c chan []byte) { for { line := <-c @@ -70,7 +93,13 @@ func treatLines(c chan []byte) { fields := bytes.Fields(line) - log.Println(fields) + horodate, err := getHorodate(&fields) + if err != nil { + log.Println(err) + continue + } + + log.Println(horodate, fields) } }