Added options and passthrough to public functions

This commit is contained in:
troyspencer 2019-08-07 22:24:47 -05:00
parent f8deff45a7
commit ae62f1889d

View File

@ -120,8 +120,8 @@ func unknownErr(datestr string) error {
// ParseAny parse an unknown date format, detect the layout. // ParseAny parse an unknown date format, detect the layout.
// Normal parse. Equivalent Timezone rules as time.Parse(). // Normal parse. Equivalent Timezone rules as time.Parse().
// NOTE: please see readme on mmdd vs ddmm ambiguous dates. // NOTE: please see readme on mmdd vs ddmm ambiguous dates.
func ParseAny(datestr string) (time.Time, error) { func ParseAny(datestr string, opts ...ParserOption) (time.Time, error) {
p, err := parseTime(datestr, nil) p, err := parseTime(datestr, nil, opts...)
if err != nil { if err != nil {
return time.Time{}, err return time.Time{}, err
} }
@ -133,8 +133,8 @@ func ParseAny(datestr string) (time.Time, error) {
// datestring, it uses the given location rules for any zone interpretation. // datestring, it uses the given location rules for any zone interpretation.
// That is, MST means one thing when using America/Denver and something else // That is, MST means one thing when using America/Denver and something else
// in other locations. // in other locations.
func ParseIn(datestr string, loc *time.Location) (time.Time, error) { func ParseIn(datestr string, loc *time.Location, opts ...ParserOption) (time.Time, error) {
p, err := parseTime(datestr, loc) p, err := parseTime(datestr, loc, opts...)
if err != nil { if err != nil {
return time.Time{}, err return time.Time{}, err
} }
@ -156,8 +156,8 @@ func ParseIn(datestr string, loc *time.Location) (time.Time, error) {
// //
// t, err := dateparse.ParseIn("3/1/2014", denverLoc) // t, err := dateparse.ParseIn("3/1/2014", denverLoc)
// //
func ParseLocal(datestr string) (time.Time, error) { func ParseLocal(datestr string, opts ...ParserOption) (time.Time, error) {
p, err := parseTime(datestr, time.Local) p, err := parseTime(datestr, time.Local, opts...)
if err != nil { if err != nil {
return time.Time{}, err return time.Time{}, err
} }
@ -166,8 +166,8 @@ func ParseLocal(datestr string) (time.Time, error) {
// MustParse parse a date, and panic if it can't be parsed. Used for testing. // MustParse parse a date, and panic if it can't be parsed. Used for testing.
// Not recommended for most use-cases. // Not recommended for most use-cases.
func MustParse(datestr string) time.Time { func MustParse(datestr string, opts ...ParserOption) time.Time {
p, err := parseTime(datestr, nil) p, err := parseTime(datestr, nil, opts...)
if err != nil { if err != nil {
panic(err.Error()) panic(err.Error())
} }
@ -184,8 +184,8 @@ func MustParse(datestr string) time.Time {
// layout, err := dateparse.ParseFormat("2013-02-01 00:00:00") // layout, err := dateparse.ParseFormat("2013-02-01 00:00:00")
// // layout = "2006-01-02 15:04:05" // // layout = "2006-01-02 15:04:05"
// //
func ParseFormat(datestr string) (string, error) { func ParseFormat(datestr string, opts ...ParserOption) (string, error) {
p, err := parseTime(datestr, nil) p, err := parseTime(datestr, nil, opts...)
if err != nil { if err != nil {
return "", err return "", err
} }
@ -198,8 +198,8 @@ func ParseFormat(datestr string) (string, error) {
// ParseStrict parse an unknown date format. IF the date is ambigous // ParseStrict parse an unknown date format. IF the date is ambigous
// mm/dd vs dd/mm then return an error. These return errors: 3.3.2014 , 8/8/71 etc // mm/dd vs dd/mm then return an error. These return errors: 3.3.2014 , 8/8/71 etc
func ParseStrict(datestr string) (time.Time, error) { func ParseStrict(datestr string, opts ...ParserOption) (time.Time, error) {
p, err := parseTime(datestr, nil) p, err := parseTime(datestr, nil, opts...)
if err != nil { if err != nil {
return time.Time{}, err return time.Time{}, err
} }