-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample_local_date_test.go
86 lines (63 loc) ยท 1.73 KB
/
example_local_date_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
86
package chrono_test
import (
"fmt"
"github.com/go-chrono/chrono"
)
func ExampleLocalDateOf() {
d := chrono.LocalDateOf(2007, chrono.May, 20)
fmt.Println(d)
// Output: 2007-05-20
}
func ExampleOfDayOfYear() {
d := chrono.OfDayOfYear(2020, 80)
fmt.Println("The 80th day of 2020 is", d)
// Output: The 80th day of 2020 is 2020-03-20
}
func ExampleOfFirstWeekday() {
d := chrono.OfFirstWeekday(2020, chrono.July, chrono.Friday)
fmt.Println("The first Friday of July 2020 is", d)
// Output: The first Friday of July 2020 is 2020-07-03
}
func ExampleLocalDate_Weekday() {
d := chrono.LocalDateOf(2007, chrono.May, 20)
fmt.Println(d.Weekday())
// Output: Sunday
}
func ExampleLocalDate_compare() {
d1 := chrono.LocalDateOf(2007, chrono.May, 20)
d2 := chrono.LocalDateOf(2009, chrono.June, 5)
if d2 > d1 {
fmt.Println(d2, "is after", d1)
}
// Output: 2009-06-05 is after 2007-05-20
}
func ExampleLocalDate_difference() {
d1 := chrono.LocalDateOf(2007, chrono.May, 20)
d2 := chrono.LocalDateOf(2007, chrono.May, 25)
fmt.Printf("There are %d days from %s to %s\n", d2-d1, d1, d2)
// Output: There are 5 days from 2007-05-20 to 2007-05-25
}
func ExampleLocalDate_add_subtract() {
d := chrono.LocalDateOf(2007, chrono.May, 20)
d += 8
d -= 3
fmt.Println(d)
// Output: 2007-05-25
}
func ExampleLocalDate_AddDate() {
d := chrono.LocalDateOf(2007, chrono.May, 20)
d = d.AddDate(0, 1, 1)
fmt.Println(d)
// Output: 2007-06-21
}
func ExampleLocalDate_Format() {
d := chrono.LocalDateOf(2007, chrono.May, 20)
fmt.Println(d.Format(chrono.ISO8601DateExtended))
// Output: 2007-05-20
}
func ExampleLocalDate_Parse() {
var d chrono.LocalDate
_ = d.Parse(chrono.ISO8601DateExtended, "2007-05-20")
fmt.Println(d)
// Output: 2007-05-20
}