feat(tyme): add basic tyme package

This commit is contained in:
2022-10-30 03:30:34 +00:00
parent b34d102e09
commit 572d532b77
12 changed files with 945 additions and 0 deletions

27
parse.go Normal file
View 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
}