From 66fb8cfe35a06d70c0b482c1366a663f63e934d4 Mon Sep 17 00:00:00 2001 From: Aaron Raddon Date: Wed, 26 Jul 2017 22:37:37 -0700 Subject: [PATCH] Doc improvements --- README.md | 19 ++++++++++--------- parseany.go | 32 +++++++++++++++++++------------- 2 files changed, 29 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index f01055a..02fb7ac 100644 --- a/README.md +++ b/README.md @@ -11,24 +11,25 @@ Parse any date string without knowing format in advance. Uses a scanner to read ```go -// Normal parse. If no recognized Timezone/Offset info -// exists in the datestring, it uses UTC. +// Normal parse. Equivalent Timezone rules as time.Parse() t, err := dateparse.ParseAny("3/1/2014") -// Parse with Location. If no recognized Timezone/Offset info -// exists in the datestring, it uses given location. -// IF there IS timezone/offset info it uses the given location -// info for any zone interpretation. That is, MST means one thing -// when using America/Denver and something else in other locations. +// Parse with Location, equivalent to time.ParseInLocation() timezone/offset +// rules. Using location arg, if timezone/offset info exists in the +// datestring, it uses the given location rules for any zone interpretation. +// That is, MST means one thing when using America/Denver and something else +// in other locations. denverLoc, _ := time.LoadLocation("America/Denver") t, err := dateparse.ParseIn("3/1/2014", denverLoc) -// Set Location to time.Local. Same as ParseIn Location but -// Lazily uses a global variable for Location Info. +// Set Location to time.Local. Same as ParseIn Location but lazily uses +// the global time.Local variable for Location argument. denverLoc, _ := time.LoadLocation("America/Denver") // use time.Local global variable to store location time.Local = denverLoc t, err := dateparse.ParseLocal("3/1/2014") +// Equivalent to +t, err := dateparse.ParseIn("3/1/2014", time.Local) ``` diff --git a/parseany.go b/parseany.go index 6bddfa9..3b74a3c 100644 --- a/parseany.go +++ b/parseany.go @@ -59,7 +59,7 @@ var ( shortDates = []string{"01/02/2006", "1/2/2006", "06/01/02", "01/02/06", "1/2/06"} ) -// MustParse Parse a date, and panic if it can't be parsed +// 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 { @@ -68,18 +68,16 @@ func MustParse(datestr string) time.Time { return t } -// ParseAny Given an unknown date format, detect the layout, parse. +// Given an unknown date format, detect the layout, parse. func ParseAny(datestr string) (time.Time, error) { return parseTime(datestr, nil) } -// ParseIn Given an unknown date format, detect the layout, -// using given location, parse. -// -// If no recognized Timezone/Offset info exists in the datestring, it uses -// given location. IF there IS timezone/offset info it uses the given location -// info for any zone interpretation. That is, MST means one thing when using -// America/Denver and something else in other locations. +// Parse with Location, equivalent to time.ParseInLocation() timezone/offset +// rules. Using location arg, if timezone/offset info exists in the +// datestring, it uses the given location rules for any zone interpretation. +// That is, MST means one thing when using America/Denver and something else +// in other locations. func ParseIn(datestr string, loc *time.Location) (time.Time, error) { return parseTime(datestr, loc) } @@ -87,10 +85,18 @@ func ParseIn(datestr string, loc *time.Location) (time.Time, error) { // ParseLocal Given an unknown date format, detect the layout, // using time.Local, parse. // -// If no recognized Timezone/Offset info exists in the datestring, it uses -// given location. IF there IS timezone/offset info it uses the given location -// info for any zone interpretation. That is, MST means one thing when using -// America/Denver and something else in other locations. +// Set Location to time.Local. Same as ParseIn Location but lazily uses +// the global time.Local variable for Location argument. +// +// denverLoc, _ := time.LoadLocation("America/Denver") +// time.Local = denverLoc +// +// t, err := dateparse.ParseLocal("3/1/2014") +// +// Equivalent to: +// +// t, err := dateparse.ParseIn("3/1/2014", denverLoc) +// func ParseLocal(datestr string) (time.Time, error) { return parseTime(datestr, time.Local) }