Compare commits
2 commits
24cf7fd4cc
...
b67d1ec77b
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b67d1ec77b | ||
|
|
2b8f160b9e |
2 changed files with 27 additions and 1 deletions
26
helper.go
26
helper.go
|
|
@ -6,10 +6,36 @@ import (
|
||||||
|
|
||||||
// Standard
|
// Standard
|
||||||
"time"
|
"time"
|
||||||
|
"regexp"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var rxpTimezone *regexp.Regexp
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
rxpTimezone = regexp.MustCompile(`(\d\d)(\d\d)$`)
|
||||||
|
}
|
||||||
|
|
||||||
func stringToTime(strTime string) (t time.Time, err error) {// {{{
|
func stringToTime(strTime string) (t time.Time, err error) {// {{{
|
||||||
|
// `date` command %z gives timezone like +0200 instead of +02:00.
|
||||||
|
// This can easily be fixed here, not requiring all scripts to be fixed.
|
||||||
t, err = time.Parse(time.RFC3339, strTime)
|
t, err = time.Parse(time.RFC3339, strTime)
|
||||||
|
if err != nil {
|
||||||
|
// Check for aforementioned problem.
|
||||||
|
parseError, ok := err.(*time.ParseError)
|
||||||
|
if ok && parseError != nil && parseError.LayoutElem == "Z07:00" {
|
||||||
|
// Insert the missing colon according to RFC 3339 and try again.
|
||||||
|
patchedTimeStr := rxpTimezone.ReplaceAllString(strTime, `$1:$2`)
|
||||||
|
t, err = time.Parse(time.RFC3339, patchedTimeStr)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Couldn't convert to time.ParseError or the retry
|
||||||
|
// failed. Either way, an error occurs.
|
||||||
|
if err != nil {
|
||||||
|
err = werr.Wrap(err).WithData(strTime)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
}// }}}
|
}// }}}
|
||||||
func parseHTMLDateTime(str string, dflt time.Time) (t time.Time, err error) {
|
func parseHTMLDateTime(str string, dflt time.Time) (t time.Time, err error) {
|
||||||
|
|
|
||||||
2
main.go
2
main.go
|
|
@ -29,7 +29,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
const VERSION = "v23"
|
const VERSION = "v24"
|
||||||
|
|
||||||
var (
|
var (
|
||||||
logger *slog.Logger
|
logger *slog.Logger
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue