forked from dromara/carbon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcarbon_test.go
executable file
·43 lines (36 loc) · 1.22 KB
/
carbon_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
package carbon
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestCarbon_FromStdTime(t *testing.T) {
loc, _ := time.LoadLocation("Asia/Shanghai")
tt := time.Now().In(loc)
expected := tt.Format(DateTimeLayout)
actual := FromStdTime(tt).ToDateTimeString()
assert.Equal(t, expected, actual)
}
func TestCarbon_ToStdTime(t *testing.T) {
expected := time.Now().Format(DateTimeLayout)
actual := Now().ToStdTime().Format(DateTimeLayout)
assert.Equal(t, expected, actual)
}
func TestCarbon_Time2Carbon(t *testing.T) {
loc, _ := time.LoadLocation("Asia/Shanghai")
tt := time.Now().In(loc)
expected := tt.Format(DateTimeLayout)
actual := Time2Carbon(tt).ToDateTimeString()
assert.Equal(t, expected, actual)
}
func TestCarbon_Carbon2Time(t *testing.T) {
expected := time.Now().Format(DateTimeLayout)
actual := Now().Carbon2Time().Format(DateTimeLayout)
assert.Equal(t, expected, actual)
}
func TestError_Carbon(t *testing.T) {
timezone := "xxx"
assert.NotNil(t, Now(timezone).Error, "It should catch an exception in Now()")
assert.NotNil(t, Tomorrow(timezone).Error, "It should catch an exception in Tomorrow()")
assert.NotNil(t, Yesterday(timezone).Error, "It should catch an exception in Yesterday()")
}