-
Notifications
You must be signed in to change notification settings - Fork 5
/
example_test.go
85 lines (72 loc) · 1.89 KB
/
example_test.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package date_test
import (
"fmt"
"time"
"github.com/fxtlabs/date"
)
func ExampleMax() {
d := date.Max()
fmt.Println(d)
// Output: +5881580-07-11
}
func ExampleMin() {
d := date.Min()
fmt.Println(d)
// Output: -5877641-06-23
}
func ExampleNew() {
d := date.New(9999, time.December, 31)
fmt.Printf("The world ends on %s\n", d)
// Output: The world ends on 9999-12-31
}
func ExampleParse() {
// longForm shows by example how the reference date would be
// represented in the desired layout.
const longForm = "Mon, January 2, 2006"
d, _ := date.Parse(longForm, "Tue, February 3, 2013")
fmt.Println(d)
// shortForm is another way the reference date would be represented
// in the desired layout.
const shortForm = "2006-Jan-02"
d, _ = date.Parse(shortForm, "2013-Feb-03")
fmt.Println(d)
// Output:
// 2013-02-03
// 2013-02-03
}
func ExampleParseISO() {
d, _ := date.ParseISO("+12345-06-07")
year, month, day := d.Date()
fmt.Println(year)
fmt.Println(month)
fmt.Println(day)
// Output:
// 12345
// June
// 7
}
func ExampleDate_AddDate() {
d := date.New(1000, time.January, 1)
// Months and days do not need to be constrained to [1,12] and [1,365].
u := d.AddDate(0, 14, -1)
fmt.Println(u)
// Output: 1001-02-28
}
func ExampleDate_Format() {
// layout shows by example how the reference time should be represented.
const layout = "Jan 2, 2006"
d := date.New(2009, time.November, 10)
fmt.Println(d.Format(layout))
// Output: Nov 10, 2009
}
func ExampleDate_FormatISO() {
// According to legend, Rome was founded on April 21, 753 BC.
// Note that with astronomical year numbering, 753 BC becomes -752
// because 1 BC is actually year 0.
d := date.New(-752, time.April, 21)
fmt.Println(d.FormatISO(5))
// Output: -00752-04-21
}