mirror of
https://github.com/jimeh/go-tyme.git
synced 2026-02-19 09:56:42 +00:00
feat(tyme): add basic tyme package
This commit is contained in:
27
parse.go
Normal file
27
parse.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package tyme
|
||||
|
||||
import "github.com/araddon/dateparse"
|
||||
|
||||
var (
|
||||
// RetryAmbiguousDateWithSwap is option available in dateparse. This var
|
||||
// controls if Time's unmarshalers enables it or not.
|
||||
RetryAmbiguousDateWithSwap = false
|
||||
|
||||
// PreferMonthFirst is option available in dateparse. This var
|
||||
// controls if Time's unmarshalers enables it or not.
|
||||
PreferMonthFirst = false
|
||||
)
|
||||
|
||||
// Parse is a helper function to parse a wide range of string date and time formats using dateparse.ParseAny.
|
||||
func Parse(s string) (Time, error) {
|
||||
t, err := dateparse.ParseAny(
|
||||
s,
|
||||
dateparse.RetryAmbiguousDateWithSwap(RetryAmbiguousDateWithSwap),
|
||||
dateparse.PreferMonthFirst(PreferMonthFirst),
|
||||
)
|
||||
if err != nil {
|
||||
return Time{}, err
|
||||
}
|
||||
|
||||
return Time(t), nil
|
||||
}
|
||||
Reference in New Issue
Block a user