代码拉取完成,页面将自动刷新
同步操作将从 dromara/carbon 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
package carbon
import (
"fmt"
"strconv"
"testing"
"github.com/stretchr/testify/assert"
)
func TestCarbon_String(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string // 输入值
expected string // 期望值
}{
{"", ""},
{"0", ""},
{"0000-00-00", ""},
{"00:00:00", ""},
{"0000-00-00 00:00:00", ""},
{"2020-08-05 13:14:15", "2020-08-05 13:14:15"},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, fmt.Sprintf("%s", Parse(test.input)), "Current test index is "+strconv.Itoa(index))
}
}
func TestCarbon_ToString(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string // 输入值
expected string // 期望值
}{
{"", ""},
{"0", ""},
{"0000-00-00", ""},
{"00:00:00", ""},
{"0000-00-00 00:00:00", ""},
{"2020-08-05 13:14:15", "2020-08-05 13:14:15 +0800 CST"},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToString(), "Current test index is "+strconv.Itoa(index))
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToString(PRC), "Current test index is "+strconv.Itoa(index))
}
}
func TestCarbon_ToMonthString(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string // 输入值
expected string // 期望值
}{
{"", ""},
{"0", ""},
{"0000-00-00", ""},
{"00:00:00", ""},
{"0000-00-00 00:00:00", ""},
{"2020-01-05", "January"},
{"2020-02-05", "February"},
{"2020-03-05", "March"},
{"2020-04-05", "April"},
{"2020-05-05", "May"},
{"2020-06-05", "June"},
{"2020-07-05", "July"},
{"2020-08-05", "August"},
{"2020-09-05", "September"},
{"2020-10-05", "October"},
{"2020-11-05", "November"},
{"2020-12-05", "December"},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToMonthString(), "Current test index is "+strconv.Itoa(index))
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToMonthString(PRC), "Current test index is "+strconv.Itoa(index))
}
}
func TestCarbon_ToShortMonthString(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string // 输入值
expected string // 期望值
}{
{"", ""},
{"0", ""},
{"0000-00-00", ""},
{"00:00:00", ""},
{"0000-00-00 00:00:00", ""},
{"2020-01-05", "Jan"},
{"2020-02-05", "Feb"},
{"2020-03-05", "Mar"},
{"2020-04-05", "Apr"},
{"2020-05-05", "May"},
{"2020-06-05", "Jun"},
{"2020-07-05", "Jul"},
{"2020-08-05", "Aug"},
{"2020-09-05", "Sep"},
{"2020-10-05", "Oct"},
{"2020-11-05", "Nov"},
{"2020-12-05", "Dec"},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToShortMonthString(), "Current test index is "+strconv.Itoa(index))
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToShortMonthString(PRC), "Current test index is "+strconv.Itoa(index))
}
}
func TestCarbon_ToWeekString(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string // 输入值
expected string // 期望值
}{
{"", ""},
{"0", ""},
{"0000-00-00", ""},
{"00:00:00", ""},
{"0000-00-00 00:00:00", ""},
{"2020-08-01", "Saturday"},
{"2020-08-02", "Sunday"},
{"2020-08-03", "Monday"},
{"2020-08-04", "Tuesday"},
{"2020-08-05", "Wednesday"},
{"2020-08-06", "Thursday"},
{"2020-08-07", "Friday"},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToWeekString(), "Current test index is "+strconv.Itoa(index))
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToWeekString(PRC), "Current test index is "+strconv.Itoa(index))
}
}
func TestCarbon_ToShortWeekString(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string // 输入值
expected string // 期望值
}{
{"", ""},
{"0", ""},
{"0000-00-00", ""},
{"00:00:00", ""},
{"0000-00-00 00:00:00", ""},
{"2020-08-01", "Sat"},
{"2020-08-02", "Sun"},
{"2020-08-03", "Mon"},
{"2020-08-04", "Tue"},
{"2020-08-05", "Wed"},
{"2020-08-06", "Thu"},
{"2020-08-07", "Fri"},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToShortWeekString(), "Current test index is "+strconv.Itoa(index))
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToShortWeekString(PRC), "Current test index is "+strconv.Itoa(index))
}
}
func TestCarbon_ToDayDateTimeString(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string // 输入值
expected string // 期望值
}{
{"", ""},
{"0", ""},
{"0000-00-00", ""},
{"00:00:00", ""},
{"0000-00-00 00:00:00", ""},
{"2020-08-05 13:14:15", "Wed, Aug 5, 2020 1:14 PM"},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToDayDateTimeString(), "Current test index is "+strconv.Itoa(index))
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToDayDateTimeString(PRC), "Current test index is "+strconv.Itoa(index))
}
}
func TestCarbon_ToDateTimeString(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string // 输入值
expected string // 期望值
}{
{"", ""},
{"0", ""},
{"0000-00-00", ""},
{"00:00:00", ""},
{"0000-00-00 00:00:00", ""},
{"2020-08-05 13:14:15", "2020-08-05 13:14:15"},
{"2020-08-05", "2020-08-05 00:00:00"},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToDateTimeString(), "Current test index is "+strconv.Itoa(index))
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToDateTimeString(PRC), "Current test index is "+strconv.Itoa(index))
}
}
func TestCarbon_ToShortDateTimeString(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string // 输入值
expected string // 期望值
}{
{"", ""},
{"0", ""},
{"0000-00-00", ""},
{"00:00:00", ""},
{"0000-00-00 00:00:00", ""},
{"2020-08-05 13:14:15", "20200805131415"},
{"2020-08-05", "20200805000000"},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToShortDateTimeString(), "Current test index is "+strconv.Itoa(index))
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToShortDateTimeString(PRC), "Current test index is "+strconv.Itoa(index))
}
}
func TestCarbon_ToDateString(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string // 输入值
expected string // 期望值
}{
{"", ""},
{"0", ""},
{"0000-00-00", ""},
{"00:00:00", ""},
{"0000-00-00 00:00:00", ""},
{"2020-08-05 13:14:15", "2020-08-05"},
{"2020-08-05", "2020-08-05"},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToDateString(), "Current test index is "+strconv.Itoa(index))
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToDateString(PRC), "Current test index is "+strconv.Itoa(index))
}
}
func TestCarbon_ToShortDateString(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string // 输入值
expected string // 期望值
}{
{"", ""},
{"0", ""},
{"0000-00-00", ""},
{"00:00:00", ""},
{"0000-00-00 00:00:00", ""},
{"2020-08-05 13:14:15", "20200805"},
{"2020-08-05", "20200805"},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToShortDateString(), "Current test index is "+strconv.Itoa(index))
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToShortDateString(PRC), "Current test index is "+strconv.Itoa(index))
}
}
func TestCarbon_ToTimeString(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string // 输入值
expected string // 期望值
}{
{"", ""},
{"0", ""},
{"0000-00-00", ""},
{"00:00:00", ""},
{"0000-00-00 00:00:00", ""},
{"2020-08-05 13:14:15", "13:14:15"},
{"2020-08-05", "00:00:00"},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToTimeString(), "Current test index is "+strconv.Itoa(index))
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToTimeString(PRC), "Current test index is "+strconv.Itoa(index))
}
}
func TestCarbon_ToShortTimeString(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string // 输入值
expected string // 期望值
}{
{"", ""},
{"0", ""},
{"0000-00-00", ""},
{"00:00:00", ""},
{"0000-00-00 00:00:00", ""},
{"2020-08-05 13:14:15", "131415"},
{"2020-08-05", "000000"},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToShortTimeString(), "Current test index is "+strconv.Itoa(index))
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToShortTimeString(PRC), "Current test index is "+strconv.Itoa(index))
}
}
func TestCarbon_ToAtomString(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string // 输入值
expected string // 期望值
}{
{"", ""},
{"0", ""},
{"0000-00-00", ""},
{"00:00:00", ""},
{"0000-00-00 00:00:00", ""},
{"2020-08-05 13:14:15", "2020-08-05T13:14:15+08:00"},
{"2020-08-05", "2020-08-05T00:00:00+08:00"},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToAtomString(), "Current test index is "+strconv.Itoa(index))
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToAtomString(PRC), "Current test index is "+strconv.Itoa(index))
}
}
func TestCarbon_ToAnsicString(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string // 输入值
expected string // 期望值
}{
{"", ""},
{"0", ""},
{"0000-00-00", ""},
{"00:00:00", ""},
{"0000-00-00 00:00:00", ""},
{"2020-08-05 13:14:15", "Wed Aug 5 13:14:15 2020"},
{"2020-08-05", "Wed Aug 5 00:00:00 2020"},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToAnsicString(), "Current test index is "+strconv.Itoa(index))
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToAnsicString(PRC), "Current test index is "+strconv.Itoa(index))
}
}
func TestCarbon_ToCookieString(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string // 输入值
expected string // 期望值
}{
{"", ""},
{"0", ""},
{"0000-00-00", ""},
{"00:00:00", ""},
{"0000-00-00 00:00:00", ""},
{"2020-08-05 13:14:15", "Wednesday, 05-Aug-2020 13:14:15 CST"},
{"2020-08-05", "Wednesday, 05-Aug-2020 00:00:00 CST"},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToCookieString(), "Current test index is "+strconv.Itoa(index))
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToCookieString(PRC), "Current test index is "+strconv.Itoa(index))
}
}
func TestCarbon_ToRssString(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string // 输入值
expected string // 期望值
}{
{"", ""},
{"0", ""},
{"0000-00-00", ""},
{"00:00:00", ""},
{"0000-00-00 00:00:00", ""},
{"2020-08-05 13:14:15", "Wed, 05 Aug 2020 13:14:15 +0800"},
{"2020-08-05", "Wed, 05 Aug 2020 00:00:00 +0800"},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToRssString(), "Current test index is "+strconv.Itoa(index))
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToRssString(PRC), "Current test index is "+strconv.Itoa(index))
}
}
func TestCarbon_ToW3cString(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string // 输入值
expected string // 期望值
}{
{"", ""},
{"0", ""},
{"0000-00-00", ""},
{"00:00:00", ""},
{"0000-00-00 00:00:00", ""},
{"2020-08-05 13:14:15", "2020-08-05T13:14:15+08:00"},
{"2020-08-05", "2020-08-05T00:00:00+08:00"},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToW3cString(), "Current test index is "+strconv.Itoa(index))
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToW3cString(PRC), "Current test index is "+strconv.Itoa(index))
}
}
func TestCarbon_ToUnixDateString(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string // 输入值
expected string // 期望值
}{
{"", ""},
{"0", ""},
{"0000-00-00", ""},
{"00:00:00", ""},
{"0000-00-00 00:00:00", ""},
{"2020-08-05 13:14:15", "Wed Aug 5 13:14:15 CST 2020"},
{"2020-08-05", "Wed Aug 5 00:00:00 CST 2020"},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToUnixDateString(), "Current test index is "+strconv.Itoa(index))
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToUnixDateString(PRC), "Current test index is "+strconv.Itoa(index))
}
}
func TestCarbon_ToRubyDateString(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string // 输入值
expected string // 期望值
}{
{"", ""},
{"0", ""},
{"0000-00-00", ""},
{"00:00:00", ""},
{"0000-00-00 00:00:00", ""},
{"2020-08-05 13:14:15", "Wed Aug 05 13:14:15 +0800 2020"},
{"2020-08-05", "Wed Aug 05 00:00:00 +0800 2020"},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToRubyDateString(), "Current test index is "+strconv.Itoa(index))
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToRubyDateString(PRC), "Current test index is "+strconv.Itoa(index))
}
}
func TestCarbon_ToKitchenString(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string // 输入值
expected string // 期望值
}{
{"", ""},
{"0", ""},
{"0000-00-00", ""},
{"00:00:00", ""},
{"0000-00-00 00:00:00", ""},
{"2020-08-05 13:14:15", "1:14PM"},
{"2020-08-05", "12:00AM"},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, test.expected, c.ToKitchenString(), "Current test index is "+strconv.Itoa(index))
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, test.expected, c.ToKitchenString(PRC), "Current test index is "+strconv.Itoa(index))
}
}
func TestCarbon_ToIso8601String(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string // 输入值
expected string // 期望值
}{
{"", ""},
{"0", ""},
{"0000-00-00", ""},
{"00:00:00", ""},
{"0000-00-00 00:00:00", ""},
{"2020-08-05 13:14:15", "2020-08-05T13:14:15+08:00"},
{"2020-08-05", "2020-08-05T00:00:00+08:00"},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToIso8601String(), "Current test index is "+strconv.Itoa(index))
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToIso8601String(PRC), "Current test index is "+strconv.Itoa(index))
}
}
func TestCarbon_ToRfc822String(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string // 输入值
expected string // 期望值
}{
{"", ""},
{"0", ""},
{"0000-00-00", ""},
{"00:00:00", ""},
{"0000-00-00 00:00:00", ""},
{"2020-08-05 13:14:15", "05 Aug 20 13:14 CST"},
{"2020-08-05", "05 Aug 20 00:00 CST"},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToRfc822String(), "Current test index is "+strconv.Itoa(index))
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToRfc822String(PRC), "Current test index is "+strconv.Itoa(index))
}
}
func TestCarbon_ToRfc822zString(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string // 输入值
expected string // 期望值
}{
{"", ""},
{"0", ""},
{"0000-00-00", ""},
{"00:00:00", ""},
{"0000-00-00 00:00:00", ""},
{"2020-08-05 13:14:15", "05 Aug 20 13:14 +0800"},
{"2020-08-05", "05 Aug 20 00:00 +0800"},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToRfc822zString(), "Current test index is "+strconv.Itoa(index))
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToRfc822zString(PRC), "Current test index is "+strconv.Itoa(index))
}
}
func TestCarbon_ToRfc850String(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string // 输入值
expected string // 期望值
}{
{"", ""},
{"0", ""},
{"0000-00-00", ""},
{"00:00:00", ""},
{"0000-00-00 00:00:00", ""},
{"2020-08-05 13:14:15", "Wednesday, 05-Aug-20 13:14:15 CST"},
{"2020-08-05", "Wednesday, 05-Aug-20 00:00:00 CST"},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToRfc850String(), "Current test index is "+strconv.Itoa(index))
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToRfc850String(PRC), "Current test index is "+strconv.Itoa(index))
}
}
func TestCarbon_ToRfc1036String(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string // 输入值
expected string // 期望值
}{
{"", ""},
{"0", ""},
{"0000-00-00", ""},
{"00:00:00", ""},
{"0000-00-00 00:00:00", ""},
{"2020-08-05 13:14:15", "Wed, 05 Aug 20 13:14:15 +0800"},
{"2020-08-05", "Wed, 05 Aug 20 00:00:00 +0800"},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToRfc1036String(), "Current test index is "+strconv.Itoa(index))
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToRfc1036String(PRC), "Current test index is "+strconv.Itoa(index))
}
}
func TestCarbon_ToRfc1123String(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string // 输入值
expected string // 期望值
}{
{"", ""},
{"0", ""},
{"0000-00-00", ""},
{"00:00:00", ""},
{"0000-00-00 00:00:00", ""},
{"2020-08-05 13:14:15", "Wed, 05 Aug 2020 13:14:15 CST"},
{"2020-08-05", "Wed, 05 Aug 2020 00:00:00 CST"},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToRfc1123String(), "Current test index is "+strconv.Itoa(index))
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToRfc1123String(PRC), "Current test index is "+strconv.Itoa(index))
}
}
func TestCarbon_ToRfc1123zString(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string // 输入值
expected string // 期望值
}{
{"", ""},
{"0", ""},
{"0000-00-00", ""},
{"00:00:00", ""},
{"0000-00-00 00:00:00", ""},
{"2020-08-05 13:14:15", "Wed, 05 Aug 2020 13:14:15 +0800"},
{"2020-08-05", "Wed, 05 Aug 2020 00:00:00 +0800"},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToRfc1123zString(), "Current test index is "+strconv.Itoa(index))
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToRfc1123zString(PRC), "Current test index is "+strconv.Itoa(index))
}
}
func TestCarbon_ToRfc2822String(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string // 输入值
expected string // 期望值
}{
{"", ""},
{"0", ""},
{"0000-00-00", ""},
{"00:00:00", ""},
{"0000-00-00 00:00:00", ""},
{"2020-08-05 13:14:15", "Wed, 05 Aug 2020 13:14:15 +0800"},
{"2020-08-05", "Wed, 05 Aug 2020 00:00:00 +0800"},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToRfc2822String(), "Current test index is "+strconv.Itoa(index))
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToRfc2822String(PRC), "Current test index is "+strconv.Itoa(index))
}
}
func TestCarbon_ToRfc3339String(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string // 输入值
expected string // 期望值
}{
{"", ""},
{"0", ""},
{"0000-00-00", ""},
{"00:00:00", ""},
{"0000-00-00 00:00:00", ""},
{"2020-08-05 13:14:15", "2020-08-05T13:14:15+08:00"},
{"2020-08-05", "2020-08-05T00:00:00+08:00"},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToRfc3339String(), "Current test index is "+strconv.Itoa(index))
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToRfc3339String(PRC), "Current test index is "+strconv.Itoa(index))
}
}
func TestCarbon_ToRfc7231String(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string // 输入值
expected string // 期望值
}{
{"", ""},
{"0", ""},
{"0000-00-00", ""},
{"00:00:00", ""},
{"0000-00-00 00:00:00", ""},
{"2020-08-05 13:14:15", "Wed, 05 Aug 2020 13:14:15 GMT"},
{"2020-08-05", "Wed, 05 Aug 2020 00:00:00 GMT"},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToRfc7231String(), "Current test index is "+strconv.Itoa(index))
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToRfc7231String(PRC), "Current test index is "+strconv.Itoa(index))
}
}
func TestCarbon_Layout(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string // 输入值
param string // 参数值
expected string // 期望值
}{
{"", "2006年01月02日", ""},
{"0", "2006年01月02日", ""},
{"0000-00-00", "2006年01月02日", ""},
{"00:00:00", "2006年01月02日", ""},
{"0000-00-00 00:00:00", "Y年m月d日", ""},
{"2020-08-05 13:14:15", "2006年01月02日", "2020年08月05日"},
{"2020-08-05 13:14:15", "Mon, 02 Jan 2006 15:04:05 GMT", "Wed, 05 Aug 2020 13:14:15 GMT"},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.Layout(test.param), "Current test index is "+strconv.Itoa(index))
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToLayoutString(test.param), "Current test index is "+strconv.Itoa(index))
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.Layout(test.param, PRC), "Current test index is "+strconv.Itoa(index))
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToLayoutString(test.param, PRC), "Current test index is "+strconv.Itoa(index))
}
}
func TestCarbon_Format(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string // 输入值
param string // 参数值
expected string // 期望值
}{
{"", "Y年m月d日", ""},
{"0", "Y年m月d日", ""},
{"0000-00-00", "Y年m月d日", ""},
{"00:00:00", "Y年m月d日", ""},
{"0000-00-00 00:00:00", "Y年m月d日", ""},
{"2020-08-05 13:14:15", "Y年m月d日", "2020年08月05日"},
{"2020-08-05 01:14:15", "j", "5"},
{"2020-08-05 01:14:15", "W", "32"},
{"2020-08-05 01:14:15", "M", "Aug"},
{"2020-08-05 01:14:15", "F", "August"},
{"2020-08-05 01:14:15", "N", "3"},
{"2020-08-05 01:14:15", "L", "1"},
{"2020-08-05 01:14:15", "L", "1"},
{"2021-08-05 01:14:15", "L", "0"},
{"2020-08-05 01:14:15", "G", "1"},
{"2020-08-05 13:14:15", "U", "1596604455"},
{"2020-08-05 13:14:15.999", "u", "999"},
{"2020-08-05 13:14:15", "w", "2"},
{"2020-08-05 13:14:15", "t", "31"},
{"2020-08-05 13:14:15", "z", "217"},
{"2020-08-05 13:14:15", "e", "PRC"},
{"2020-08-05 13:14:15", "Q", "3"},
{"2020-08-05 13:14:15", "C", "21"},
{"2020-08-05 13:14:15", "jS", "5th"},
{"2020-08-22 13:14:15", "jS", "22nd"},
{"2020-08-23 13:14:15", "jS", "23rd"},
{"2020-08-31 13:14:15", "jS", "31st"},
{"2020-08-31 13:14:15", "I\\t \\i\\s Y-m-d H:i:s", "It is 2020-08-31 13:14:15"},
{"2020-08-05 13:14:15", "上次上报时间:Y-m-d H:i:s,请每日按时打卡", "上次上报时间:2020-08-05 13:14:15,请每日按时打卡"},
{"2020-08-05 13:14:15", "l jS of F Y h:i:s A", "Wednesday 5th of August 2020 01:14:15 PM"},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.Format(test.param), "Current test index is "+strconv.Itoa(index))
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToFormatString(test.param), "Current test index is "+strconv.Itoa(index))
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToFormatString(test.param, PRC), "Current test index is "+strconv.Itoa(index))
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。