mirror of
https://github.com/araddon/dateparse.git
synced 2024-11-10 11:51:54 +08:00
Doc improvements
This commit is contained in:
parent
66fb8cfe35
commit
a1537bb044
20
parseany.go
20
parseany.go
@ -59,16 +59,8 @@ var (
|
|||||||
shortDates = []string{"01/02/2006", "1/2/2006", "06/01/02", "01/02/06", "1/2/06"}
|
shortDates = []string{"01/02/2006", "1/2/2006", "06/01/02", "01/02/06", "1/2/06"}
|
||||||
)
|
)
|
||||||
|
|
||||||
// Parse a date, and panic if it can't be parsed
|
|
||||||
func MustParse(datestr string) time.Time {
|
|
||||||
t, err := parseTime(datestr, nil)
|
|
||||||
if err != nil {
|
|
||||||
panic(err.Error())
|
|
||||||
}
|
|
||||||
return t
|
|
||||||
}
|
|
||||||
|
|
||||||
// Given an unknown date format, detect the layout, parse.
|
// Given an unknown date format, detect the layout, parse.
|
||||||
|
// Normal parse. Equivalent Timezone rules as time.Parse()
|
||||||
func ParseAny(datestr string) (time.Time, error) {
|
func ParseAny(datestr string) (time.Time, error) {
|
||||||
return parseTime(datestr, nil)
|
return parseTime(datestr, nil)
|
||||||
}
|
}
|
||||||
@ -101,6 +93,16 @@ func ParseLocal(datestr string) (time.Time, error) {
|
|||||||
return parseTime(datestr, time.Local)
|
return parseTime(datestr, time.Local)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Parse a date, and panic if it can't be parsed. Used for testing.
|
||||||
|
// Not recomended for most use-cases.
|
||||||
|
func MustParse(datestr string) time.Time {
|
||||||
|
t, err := parseTime(datestr, nil)
|
||||||
|
if err != nil {
|
||||||
|
panic(err.Error())
|
||||||
|
}
|
||||||
|
return t
|
||||||
|
}
|
||||||
|
|
||||||
func parse(layout, datestr string, loc *time.Location) (time.Time, error) {
|
func parse(layout, datestr string, loc *time.Location) (time.Time, error) {
|
||||||
if loc == nil {
|
if loc == nil {
|
||||||
return time.Parse(layout, datestr)
|
return time.Parse(layout, datestr)
|
||||||
|
Loading…
Reference in New Issue
Block a user