Implement horodate parsing

This commit is contained in:
nemunaire 2021-02-04 00:51:04 +01:00
parent eb5d587994
commit de686ef53d

31
main.go
View File

@ -55,6 +55,29 @@ func computeChecksum(area []byte) (checksum byte) {
return 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) { func treatLines(c chan []byte) {
for { for {
line := <-c line := <-c
@ -70,7 +93,13 @@ func treatLines(c chan []byte) {
fields := bytes.Fields(line) fields := bytes.Fields(line)
log.Println(fields) horodate, err := getHorodate(&fields)
if err != nil {
log.Println(err)
continue
}
log.Println(horodate, fields)
} }
} }