-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_test.go
More file actions
73 lines (62 loc) · 1.72 KB
/
Copy pathexample_test.go
File metadata and controls
73 lines (62 loc) · 1.72 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
68
69
70
71
72
73
package chronos_test
import (
"fmt"
"time"
"github.com/gomooth/chronos"
)
func ExampleStartOfDay() {
at := time.Date(2023, 5, 15, 14, 30, 45, 0, time.UTC)
fmt.Println(chronos.StartOfDay(at))
// Output: 2023-05-15 00:00:00 +0000 UTC
}
func ExampleEndOfMonth() {
at := time.Date(2023, 2, 10, 0, 0, 0, 0, time.UTC)
fmt.Println(chronos.EndOfMonth(at))
// Output: 2023-02-28 23:59:59.999999999 +0000 UTC
}
func ExampleTomorrow() {
at := time.Date(2023, 5, 15, 14, 30, 0, 0, time.UTC)
fmt.Println(chronos.Tomorrow(at))
// Output: 2023-05-16 14:30:00 +0000 UTC
}
func ExampleDiff() {
t1 := time.Date(2023, 5, 20, 0, 0, 0, 0, time.UTC)
t2 := time.Date(2023, 5, 15, 0, 0, 0, 0, time.UTC)
d := chronos.Diff(t1, t2)
fmt.Println(d.Hours())
// Output: 120
}
func ExampleDiffValue_String() {
d := chronos.DiffValue(90 * 1e9)
fmt.Println(d.String())
// Output: 1m30s
}
func ExampleAddDate_clampControl() {
jan31 := time.Date(2023, 1, 31, 0, 0, 0, 0, time.UTC)
result := chronos.AddDate(jan31, 0, 1, 0, chronos.WithClamp(true))
fmt.Println(result)
// Output: 2023-02-28 00:00:00 +0000 UTC
}
func ExampleFormatDateTime() {
at := time.Date(2023, 5, 15, 14, 30, 45, 0, time.UTC)
fmt.Println(chronos.FormatDateTime(at))
// Output: 2023-05-15 14:30:45
}
func ExampleNewPeriod() {
p := chronos.NewPeriod(
time.Date(2023, 5, 15, 0, 0, 0, 0, time.UTC),
time.Date(2023, 5, 20, 0, 0, 0, 0, time.UTC),
)
fmt.Println(p.Contains(time.Date(2023, 5, 17, 0, 0, 0, 0, time.UTC)))
fmt.Println(p.Duration())
// Output:
// true
// 120h0m0s
}
func ExampleIsLeap() {
fmt.Println(chronos.IsLeap(time.Date(2024, 1, 1, 0, 0, 0, 0, time.UTC)))
fmt.Println(chronos.IsLeap(time.Date(2023, 1, 1, 0, 0, 0, 0, time.UTC)))
// Output:
// true
// false
}