Improve doc on time.Location usage

This commit is contained in:
Aaron Raddon
2017-07-26 17:08:58 -07:00
parent 3e1f751fed
commit 7dedf040d6
2 changed files with 24 additions and 3 deletions

View File

@@ -11,14 +11,25 @@ Parse any date string without knowing format in advance. Uses a scanner to read
```go
// Normal parse
// Normal parse. If no recognized Timezone/Offset info
// exists in the datestring, it uses UTC.
t, err := dateparse.ParseAny("3/1/2014")
// Parse with Location
// 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.
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.
denverLoc, _ := time.LoadLocation("America/Denver")
// use time.Local global variable to store location
time.Local = denverLoc
t, err := dateparse.ParseLocal("3/1/2014")
```
Extended example https://github.com/araddon/dateparse/blob/master/example/main.go