-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathexamples_test.go
More file actions
67 lines (58 loc) · 1.18 KB
/
examples_test.go
File metadata and controls
67 lines (58 loc) · 1.18 KB
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
57
58
59
60
61
62
63
64
65
66
67
package fuzzytime
import (
"fmt"
)
func ExampleExtract() {
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",
}
for _, inp := range inputs {
dt, spans, err := Extract(inp)
if err != nil {
panic(fmt.Errorf("Extract(%s) error: %s", inp, err))
}
fmt.Println(dt.ISOFormat(), spans)
}
// Output:
// 2014-04-16T17:32:51+12:00 [{0 29}]
// 2010-02-01T13:14:43Z [{0 20}]
// []
// 1999-03-10 [{13 29}]
// T14:51 [{0 6}]
}
func ExampleContext() {
inputs := []string{
"01/02/03",
"12/23/99",
"10:25CST",
}
// USA context:
fmt.Println("in USA:")
for _, inp := range inputs {
dt, _, _ := USContext.Extract(inp)
fmt.Println(dt.ISOFormat())
}
// custom context for Australia:
aussie := Context{
DateResolver: DMYResolver,
TZResolver: DefaultTZResolver("AU"),
}
fmt.Println("in Australia:")
for _, inp := range inputs {
dt, _, _ := aussie.Extract(inp)
fmt.Println(dt.ISOFormat())
}
// Output:
// in USA:
// 2003-01-02
// 1999-12-23
// T10:25-06:00
// in Australia:
// 2003-02-01
//
// T10:25+09:30
}