-
-
Notifications
You must be signed in to change notification settings - Fork 262
Expand file tree
/
Copy pathfrozen_example_test.go
More file actions
47 lines (36 loc) · 935 Bytes
/
frozen_example_test.go
File metadata and controls
47 lines (36 loc) · 935 Bytes
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
package carbon_test
import (
"fmt"
"github.com/dromara/carbon/v2"
)
func ExampleSetTestNow() {
defer carbon.ClearTestNow()
now := carbon.Parse("2020-08-05")
carbon.SetTestNow(now)
fmt.Println(carbon.Now().ToDateString())
fmt.Println(carbon.Yesterday().ToDateString())
fmt.Println(carbon.Tomorrow().ToDateString())
fmt.Println(carbon.Now().DiffForHumans())
fmt.Println(carbon.Yesterday().DiffForHumans())
fmt.Println(carbon.Tomorrow().DiffForHumans())
fmt.Println(carbon.Parse("2020-10-05").DiffForHumans())
fmt.Println(now.DiffForHumans(carbon.Parse("2020-10-05")))
// Output:
// 2020-08-05
// 2020-08-04
// 2020-08-06
// just now
// 1 day ago
// 1 day from now
// 2 months from now
// 2 months before
}
func ExampleClearTestNow() {
carbon.SetTestNow(carbon.Parse("2020-08-05"))
fmt.Println(carbon.IsTestNow())
carbon.ClearTestNow()
fmt.Println(carbon.IsTestNow())
// Output:
// true
// false
}