代码拉取完成,页面将自动刷新
同步操作将从 dromara/carbon 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
package carbon
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestCarbon_Now(t *testing.T) {
assert := assert.New(t)
actual1 := Now().ToDateString()
expected1 := time.Now().Format(DateFormat)
assert.Equal(expected1, actual1)
actual2 := Now(Local).ToDateString()
expected2 := time.Now().In(time.Local).Format(DateFormat)
assert.Equal(expected2, actual2)
}
func TestError_Now(t *testing.T) {
timezone := "xxx"
c := Now(timezone)
assert.NotNil(t, c.Error, "It should catch an exception in Now()")
}
func TestCarbon_Yesterday(t *testing.T) {
assert := assert.New(t)
c1 := Yesterday()
expected1 := time.Now().AddDate(0, 0, -1).Format(DateFormat)
assert.Nil(c1.Error)
assert.Equal(expected1, c1.ToDateString())
c2 := Yesterday(Local)
expected2 := time.Now().In(time.Local).AddDate(0, 0, -1).Format(DateFormat)
assert.Nil(c2.Error)
assert.Equal(expected2, c2.ToDateString())
c3 := Parse("2020-08-05").Yesterday()
assert.Nil(c3.Error)
assert.Equal("2020-08-04", c3.ToDateString(), "It should be equal to 2020-08-04")
}
func TestError_Yesterday(t *testing.T) {
timezone := "xxx"
c := Yesterday(timezone)
assert.NotNil(t, c.Error, "It should catch an exception in Yesterday()")
}
func TestCarbon_Tomorrow(t *testing.T) {
assert := assert.New(t)
c1 := Tomorrow()
expected1 := time.Now().AddDate(0, 0, 1).Format(DateFormat)
assert.Nil(c1.Error)
assert.Equal(expected1, c1.ToDateString())
c2 := Tomorrow(Local)
expected2 := time.Now().In(time.Local).AddDate(0, 0, 1).Format(DateFormat)
assert.Nil(c2.Error)
assert.Equal(expected2, c2.ToDateString())
c3 := Parse("2020-08-05").Tomorrow()
assert.Nil(c3.Error)
assert.Equal("2020-08-06", c3.ToDateString(), "It should be equal to 2020-08-06")
}
func TestError_Tomorrow(t *testing.T) {
timezone := "xxx"
c := Tomorrow(timezone)
assert.NotNil(t, c.Error, "It should catch an exception in Tomorrow()")
}
func TestCarbon_Time2Carbon(t *testing.T) {
assert := assert.New(t)
expected := time.Now().Format(DateTimeFormat)
actual := Time2Carbon(time.Now()).ToDateTimeString()
assert.Equal(expected, actual)
}
func TestCarbon_Carbon2Time(t *testing.T) {
assert := assert.New(t)
expected := time.Now().Format(DateTimeFormat)
actual := Now().Carbon2Time().Format(DateTimeFormat)
assert.Equal(expected, actual)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。