Refactored timeparsing from HTML input

This commit is contained in:
Magnus Åhall 2024-06-27 13:45:01 +02:00
parent ab87da256c
commit 530204c1a5
6 changed files with 45 additions and 22 deletions

View file

@ -1,6 +1,9 @@
package main
import (
// External
werr "git.gibonuddevalla.se/go/wrappederror"
// Standard
"time"
)
@ -9,3 +12,18 @@ func stringToTime(strTime string) (t time.Time, err error) {// {{{
t, err = time.Parse(time.RFC3339, strTime)
return
}// }}}
func parseHTMLDateTime(str string, dflt time.Time) (t time.Time, err error) {
// Browser sending 2024-06-27T10:43 (16 characters) when seconds is 00.
if len(str) == 16 {
str += ":00"
}
if str == "" {
return dflt, nil
} else {
t, err = time.ParseInLocation("2006-01-02T15:04:05", str, smonConfig.Timezone())
if err != nil {
err = werr.Wrap(err)
}
}
return
}