-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathdoc.go
56 lines (38 loc) · 1.34 KB
/
doc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
Package fuzzytime helps with the parsing and representation of dates and times.
Fuzzytime defines types (Date, Time, DateTime) which have optional fields.
So you can represent a date with a year and month, but no day.
A quick parsing example:
package main
import (
"fmt"
"github.com/bcampbell/fuzzytime"
)
func main() {
inputs := []string{
"Wed Apr 16 17:32:51 NZST 2014",
"2010-02-01T13:14:43Z", // an iso 8601 form
"no date or time info here",
"Published on March 10th, 1999 by Brian Credability",
"2:51pm",
"April 2004",
}
for _, s := range inputs {
dt, _, _ := fuzzytime.Extract(s)
fmt.Println(dt.ISOFormat())
}
}
This should output:
2014-04-16T17:32:51+12:00
2010-02-01T13:14:43Z
1999-03-10
T14:51
2004-04
Timezones, once resolved, are stored as an offset from UTC (in seconds).
Sometimes dates and times are ambiguous and can't be parsed without
extra information (eg "dd/mm/yy" vs "mm/dd/yy"). The default behaviour when
such a data is encountered is for Extract() function to just return an error.
This can be overriden by using a Context struct, which provides
functions to perform the decisions required in otherwise-ambiguous cases.
*/
package fuzzytime