Implement horodate parsing
This commit is contained in:
parent
eb5d587994
commit
de686ef53d
31
main.go
31
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)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user