mirror of
https://github.com/Threnklyn/zeit.git
synced 2026-05-18 21:03:30 +02:00
Adding dateparse in helper and support more date/time formats
This commit is contained in:
+16
-1
@@ -10,6 +10,8 @@ import (
|
||||
"time"
|
||||
"math"
|
||||
"errors"
|
||||
|
||||
"github.com/araddon/dateparse"
|
||||
)
|
||||
|
||||
|
||||
@@ -105,7 +107,20 @@ func ParseTime(timeStr string) (time.Time, error) {
|
||||
case TFRelHourMinute, TFRelHourFraction:
|
||||
return RelToTime(timeStr, tfId)
|
||||
default:
|
||||
return time.Now(), errors.New("could not match passed time")
|
||||
loc, err := time.LoadLocation("Local")
|
||||
|
||||
if err != nil {
|
||||
return time.Now(), errors.New("could not load location")
|
||||
}
|
||||
|
||||
time.Local = loc
|
||||
|
||||
tnew, err := dateparse.ParseIn(timeStr, loc)
|
||||
if err != nil {
|
||||
return time.Now(), errors.New("could not match passed time")
|
||||
}
|
||||
|
||||
return tnew, nil
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user