2021-02-18 14:32:31 +08:00
|
|
|
package carbon
|
|
|
|
|
|
|
|
import (
|
2021-07-19 09:33:57 +08:00
|
|
|
"fmt"
|
2021-07-19 14:33:53 +08:00
|
|
|
"strconv"
|
2021-02-18 14:32:31 +08:00
|
|
|
"testing"
|
2021-07-19 09:33:57 +08:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2021-02-18 14:32:31 +08:00
|
|
|
)
|
|
|
|
|
2021-02-23 09:32:55 +08:00
|
|
|
func TestCarbon_ToTimestamp(t *testing.T) {
|
2021-07-19 09:33:57 +08:00
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
tests := []struct {
|
2021-07-23 10:59:53 +08:00
|
|
|
input string // 输入值
|
|
|
|
expected int64 // 期望值
|
2021-02-18 14:32:31 +08:00
|
|
|
}{
|
2021-08-10 11:01:46 +08:00
|
|
|
{"", 0},
|
|
|
|
{"0", 0},
|
|
|
|
{"0000-00-00", 0},
|
|
|
|
{"00:00:00", 0},
|
|
|
|
{"0000-00-00 00:00:00", 0},
|
2021-07-19 09:33:57 +08:00
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
{"2020-01-01 13:14:15", 1577855655},
|
|
|
|
{"2020-01-31 13:14:15", 1580447655},
|
|
|
|
{"2020-02-01 13:14:15", 1580534055},
|
|
|
|
{"2020-02-28 13:14:15", 1582866855},
|
|
|
|
{"2020-02-29 13:14:15", 1582953255},
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
for index, test := range tests {
|
2021-07-23 10:59:53 +08:00
|
|
|
c := Parse(test.input, PRC)
|
2021-07-19 09:33:57 +08:00
|
|
|
assert.Nil(c.Error)
|
2021-08-10 11:01:46 +08:00
|
|
|
assert.Equal(test.expected, c.ToTimestamp(), "Current test index is "+strconv.Itoa(index))
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-23 09:32:55 +08:00
|
|
|
func TestCarbon_ToTimestampWithSecond(t *testing.T) {
|
2021-07-19 09:33:57 +08:00
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
tests := []struct {
|
2021-07-23 10:59:53 +08:00
|
|
|
input string // 输入值
|
|
|
|
expected int64 // 期望值
|
2021-02-18 14:32:31 +08:00
|
|
|
}{
|
2021-08-10 11:01:46 +08:00
|
|
|
{"", 0},
|
|
|
|
{"0", 0},
|
|
|
|
{"0000-00-00", 0},
|
|
|
|
{"00:00:00", 0},
|
|
|
|
{"0000-00-00 00:00:00", 0},
|
2021-07-19 09:33:57 +08:00
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
{"2020-01-01 13:14:15", 1577855655},
|
|
|
|
{"2020-01-31 13:14:15", 1580447655},
|
|
|
|
{"2020-02-01 13:14:15", 1580534055},
|
|
|
|
{"2020-02-28 13:14:15", 1582866855},
|
|
|
|
{"2020-02-29 13:14:15", 1582953255},
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
for index, test := range tests {
|
2021-07-23 10:59:53 +08:00
|
|
|
c := Parse(test.input, PRC)
|
2021-07-19 09:33:57 +08:00
|
|
|
assert.Nil(c.Error)
|
2021-08-10 11:01:46 +08:00
|
|
|
assert.Equal(test.expected, c.ToTimestampWithSecond(), "Current test index is "+strconv.Itoa(index))
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-23 09:32:55 +08:00
|
|
|
func TestCarbon_ToTimestampWithMillisecond(t *testing.T) {
|
2021-07-19 09:33:57 +08:00
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
tests := []struct {
|
2021-07-23 10:59:53 +08:00
|
|
|
input string // 输入值
|
|
|
|
expected int64 // 期望值
|
2021-02-18 14:32:31 +08:00
|
|
|
}{
|
2021-08-10 11:01:46 +08:00
|
|
|
{"", 0},
|
|
|
|
{"0", 0},
|
|
|
|
{"0000-00-00", 0},
|
|
|
|
{"00:00:00", 0},
|
|
|
|
{"0000-00-00 00:00:00", 0},
|
2021-07-19 09:33:57 +08:00
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
{"2020-01-01 13:14:15", 1577855655000},
|
|
|
|
{"2020-01-31 13:14:15", 1580447655000},
|
|
|
|
{"2020-02-01 13:14:15", 1580534055000},
|
|
|
|
{"2020-02-28 13:14:15", 1582866855000},
|
|
|
|
{"2020-02-29 13:14:15", 1582953255000},
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
for index, test := range tests {
|
2021-07-23 10:59:53 +08:00
|
|
|
c := Parse(test.input, PRC)
|
2021-07-19 09:33:57 +08:00
|
|
|
assert.Nil(c.Error)
|
2021-08-10 11:01:46 +08:00
|
|
|
assert.Equal(test.expected, c.ToTimestampWithMillisecond(), "Current test index is "+strconv.Itoa(index))
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-23 09:32:55 +08:00
|
|
|
func TestCarbon_ToTimestampWithMicrosecond(t *testing.T) {
|
2021-07-19 09:33:57 +08:00
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
tests := []struct {
|
2021-07-23 10:59:53 +08:00
|
|
|
input string // 输入值
|
|
|
|
expected int64 // 期望值
|
2021-02-18 14:32:31 +08:00
|
|
|
}{
|
2021-08-10 11:01:46 +08:00
|
|
|
{"", 0},
|
|
|
|
{"0", 0},
|
|
|
|
{"0000-00-00", 0},
|
|
|
|
{"00:00:00", 0},
|
|
|
|
{"0000-00-00 00:00:00", 0},
|
2021-07-19 09:33:57 +08:00
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
{"2020-01-01 13:14:15", 1577855655000000},
|
|
|
|
{"2020-01-31 13:14:15", 1580447655000000},
|
|
|
|
{"2020-02-01 13:14:15", 1580534055000000},
|
|
|
|
{"2020-02-28 13:14:15", 1582866855000000},
|
|
|
|
{"2020-02-29 13:14:15", 1582953255000000},
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
for index, test := range tests {
|
2021-07-23 10:59:53 +08:00
|
|
|
c := Parse(test.input, PRC)
|
2021-07-19 09:33:57 +08:00
|
|
|
assert.Nil(c.Error)
|
2021-08-10 11:01:46 +08:00
|
|
|
assert.Equal(test.expected, c.ToTimestampWithMicrosecond(), "Current test index is "+strconv.Itoa(index))
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-23 09:32:55 +08:00
|
|
|
func TestCarbon_ToTimestampWithNanosecond(t *testing.T) {
|
2021-07-19 09:33:57 +08:00
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
tests := []struct {
|
2021-07-23 10:59:53 +08:00
|
|
|
input string // 输入值
|
|
|
|
expected int64 // 期望值
|
2021-02-18 14:32:31 +08:00
|
|
|
}{
|
2021-08-10 11:01:46 +08:00
|
|
|
{"", 0},
|
|
|
|
{"0", 0},
|
|
|
|
{"0000-00-00", 0},
|
|
|
|
{"00:00:00", 0},
|
|
|
|
{"0000-00-00 00:00:00", 0},
|
2021-07-19 09:33:57 +08:00
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
{"2020-01-01 13:14:15", 1577855655000000000},
|
|
|
|
{"2020-01-31 13:14:15", 1580447655000000000},
|
|
|
|
{"2020-02-01 13:14:15", 1580534055000000000},
|
|
|
|
{"2020-02-28 13:14:15", 1582866855000000000},
|
|
|
|
{"2020-02-29 13:14:15", 1582953255000000000},
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
for index, test := range tests {
|
2021-07-23 10:59:53 +08:00
|
|
|
c := Parse(test.input, PRC)
|
2021-07-19 09:33:57 +08:00
|
|
|
assert.Nil(c.Error)
|
2021-08-10 11:01:46 +08:00
|
|
|
assert.Equal(test.expected, c.ToTimestampWithNanosecond(), "Current test index is "+strconv.Itoa(index))
|
2021-07-19 09:33:57 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_String(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
2021-02-18 14:32:31 +08:00
|
|
|
|
2021-07-19 09:33:57 +08:00
|
|
|
tests := []struct {
|
2021-07-23 10:59:53 +08:00
|
|
|
input string // 输入值
|
|
|
|
expected string // 期望值
|
2021-07-19 09:33:57 +08:00
|
|
|
}{
|
2021-08-10 11:01:46 +08:00
|
|
|
{"", ""},
|
|
|
|
{"0", ""},
|
|
|
|
{"0000-00-00", ""},
|
|
|
|
{"00:00:00", ""},
|
|
|
|
{"0000-00-00 00:00:00", ""},
|
2021-07-19 09:33:57 +08:00
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
{"2020-08-05 13:14:15", "2020-08-05 13:14:15"},
|
2021-07-19 09:33:57 +08:00
|
|
|
}
|
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
for index, test := range tests {
|
2021-07-23 10:59:53 +08:00
|
|
|
c := Parse(test.input, PRC)
|
2021-07-19 09:33:57 +08:00
|
|
|
assert.Nil(c.Error)
|
2021-08-10 11:01:46 +08:00
|
|
|
assert.Equal(test.expected, fmt.Sprintf("%s", Parse(test.input)), "Current test index is "+strconv.Itoa(index))
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-23 09:32:55 +08:00
|
|
|
func TestCarbon_ToString(t *testing.T) {
|
2021-07-19 09:33:57 +08:00
|
|
|
assert := assert.New(t)
|
2021-07-19 14:33:53 +08:00
|
|
|
|
2021-07-19 09:33:57 +08:00
|
|
|
tests := []struct {
|
2021-07-23 10:59:53 +08:00
|
|
|
input string // 输入值
|
|
|
|
expected string // 期望值
|
2021-02-23 09:32:55 +08:00
|
|
|
}{
|
2021-08-10 11:01:46 +08:00
|
|
|
{"", ""},
|
|
|
|
{"0", ""},
|
|
|
|
{"0000-00-00", ""},
|
|
|
|
{"00:00:00", ""},
|
|
|
|
{"0000-00-00 00:00:00", ""},
|
2021-07-19 09:33:57 +08:00
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
{"2020-08-05 13:14:15", "2020-08-05 13:14:15 +0800 CST"},
|
2021-02-23 09:32:55 +08:00
|
|
|
}
|
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
for index, test := range tests {
|
2021-07-23 10:59:53 +08:00
|
|
|
c := Parse(test.input, PRC)
|
2021-07-19 09:33:57 +08:00
|
|
|
assert.Nil(c.Error)
|
2021-08-10 11:01:46 +08:00
|
|
|
assert.Equal(test.expected, c.ToString(), "Current test index is "+strconv.Itoa(index))
|
2021-07-19 09:33:57 +08:00
|
|
|
}
|
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
for index, test := range tests {
|
2021-07-23 10:59:53 +08:00
|
|
|
c := Parse(test.input, PRC)
|
2021-07-19 09:33:57 +08:00
|
|
|
assert.Nil(c.Error)
|
2021-08-10 11:01:46 +08:00
|
|
|
assert.Equal(test.expected, c.ToString(PRC), "Current test index is "+strconv.Itoa(index))
|
2021-07-19 09:33:57 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-31 13:28:08 +08:00
|
|
|
func TestCarbon_ToMonthString(t *testing.T) {
|
2021-07-19 09:33:57 +08:00
|
|
|
assert := assert.New(t)
|
2021-02-23 09:32:55 +08:00
|
|
|
|
2021-07-19 09:33:57 +08:00
|
|
|
tests := []struct {
|
2021-07-23 10:59:53 +08:00
|
|
|
input string // 输入值
|
|
|
|
expected string // 期望值
|
2021-07-19 09:33:57 +08:00
|
|
|
}{
|
2021-08-10 11:01:46 +08:00
|
|
|
{"", ""},
|
|
|
|
{"0", ""},
|
|
|
|
{"0000-00-00", ""},
|
|
|
|
{"00:00:00", ""},
|
|
|
|
{"0000-00-00 00:00:00", ""},
|
2021-07-19 14:33:53 +08:00
|
|
|
|
2021-08-10 11:01:46 +08: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"},
|
2021-07-19 09:33:57 +08:00
|
|
|
}
|
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
for index, test := range tests {
|
2021-07-23 10:59:53 +08:00
|
|
|
c := Parse(test.input, PRC)
|
2021-07-19 09:33:57 +08:00
|
|
|
assert.Nil(c.Error)
|
2021-08-10 11:01:46 +08:00
|
|
|
assert.Equal(test.expected, c.ToMonthString(), "Current test index is "+strconv.Itoa(index))
|
2021-07-23 10:59:53 +08:00
|
|
|
}
|
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
for index, test := range tests {
|
2021-07-23 10:59:53 +08:00
|
|
|
c := Parse(test.input, PRC)
|
|
|
|
assert.Nil(c.Error)
|
2021-08-10 11:01:46 +08:00
|
|
|
assert.Equal(test.expected, c.ToMonthString(PRC), "Current test index is "+strconv.Itoa(index))
|
2021-02-23 09:32:55 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-31 13:28:08 +08:00
|
|
|
func TestCarbon_ToShortMonthString(t *testing.T) {
|
2021-07-19 09:33:57 +08:00
|
|
|
assert := assert.New(t)
|
2021-02-23 09:32:55 +08:00
|
|
|
|
2021-07-19 09:33:57 +08:00
|
|
|
tests := []struct {
|
2021-07-23 10:59:53 +08:00
|
|
|
input string // 输入值
|
|
|
|
expected string // 期望值
|
2021-07-19 09:33:57 +08:00
|
|
|
}{
|
2021-08-10 11:01:46 +08:00
|
|
|
{"", ""},
|
|
|
|
{"0", ""},
|
|
|
|
{"0000-00-00", ""},
|
|
|
|
{"00:00:00", ""},
|
|
|
|
{"0000-00-00 00:00:00", ""},
|
2021-07-19 14:33:53 +08:00
|
|
|
|
2021-08-10 11:01:46 +08: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"},
|
2021-07-19 09:33:57 +08:00
|
|
|
}
|
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
for index, test := range tests {
|
2021-07-23 10:59:53 +08:00
|
|
|
c := Parse(test.input, PRC)
|
|
|
|
assert.Nil(c.Error)
|
2021-08-10 11:01:46 +08:00
|
|
|
assert.Equal(test.expected, c.ToShortMonthString(), "Current test index is "+strconv.Itoa(index))
|
2021-07-23 10:59:53 +08:00
|
|
|
}
|
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
for index, test := range tests {
|
2021-07-23 10:59:53 +08:00
|
|
|
c := Parse(test.input, PRC)
|
2021-07-19 09:33:57 +08:00
|
|
|
assert.Nil(c.Error)
|
2021-08-10 11:01:46 +08:00
|
|
|
assert.Equal(test.expected, c.ToShortMonthString(PRC), "Current test index is "+strconv.Itoa(index))
|
2021-02-23 09:32:55 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-31 13:28:08 +08:00
|
|
|
func TestCarbon_ToWeekString(t *testing.T) {
|
2021-07-19 09:33:57 +08:00
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
tests := []struct {
|
2021-07-23 10:59:53 +08:00
|
|
|
input string // 输入值
|
|
|
|
expected string // 期望值
|
2021-07-19 09:33:57 +08:00
|
|
|
}{
|
2021-08-10 11:01:46 +08:00
|
|
|
{"", ""},
|
|
|
|
{"0", ""},
|
|
|
|
{"0000-00-00", ""},
|
|
|
|
{"00:00:00", ""},
|
|
|
|
{"0000-00-00 00:00:00", ""},
|
2021-07-19 09:33:57 +08:00
|
|
|
|
2021-08-10 11:01:46 +08: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"},
|
2021-07-19 09:33:57 +08:00
|
|
|
}
|
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
for index, test := range tests {
|
2021-07-23 10:59:53 +08:00
|
|
|
c := Parse(test.input, PRC)
|
2021-07-19 09:33:57 +08:00
|
|
|
assert.Nil(c.Error)
|
2021-08-10 11:01:46 +08:00
|
|
|
assert.Equal(test.expected, c.ToWeekString(), "Current test index is "+strconv.Itoa(index))
|
2021-07-23 10:59:53 +08:00
|
|
|
}
|
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
for index, test := range tests {
|
2021-07-23 10:59:53 +08:00
|
|
|
c := Parse(test.input, PRC)
|
|
|
|
assert.Nil(c.Error)
|
2021-08-10 11:01:46 +08:00
|
|
|
assert.Equal(test.expected, c.ToWeekString(PRC), "Current test index is "+strconv.Itoa(index))
|
2021-02-23 09:32:55 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-31 13:28:08 +08:00
|
|
|
func TestCarbon_ToShortWeekString(t *testing.T) {
|
2021-07-19 09:33:57 +08:00
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
tests := []struct {
|
2021-07-23 10:59:53 +08:00
|
|
|
input string // 输入值
|
|
|
|
expected string // 期望值
|
2021-07-19 09:33:57 +08:00
|
|
|
}{
|
2021-08-10 11:01:46 +08:00
|
|
|
{"", ""},
|
|
|
|
{"0", ""},
|
|
|
|
{"0000-00-00", ""},
|
|
|
|
{"00:00:00", ""},
|
|
|
|
{"0000-00-00 00:00:00", ""},
|
2021-07-19 09:33:57 +08:00
|
|
|
|
2021-08-10 11:01:46 +08: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"},
|
2021-07-19 09:33:57 +08:00
|
|
|
}
|
2021-02-23 09:32:55 +08:00
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
for index, test := range tests {
|
2021-07-23 10:59:53 +08:00
|
|
|
c := Parse(test.input, PRC)
|
2021-07-19 09:33:57 +08:00
|
|
|
assert.Nil(c.Error)
|
2021-08-10 11:01:46 +08:00
|
|
|
assert.Equal(test.expected, c.ToShortWeekString(), "Current test index is "+strconv.Itoa(index))
|
2021-07-23 10:59:53 +08:00
|
|
|
}
|
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
for index, test := range tests {
|
2021-07-23 10:59:53 +08:00
|
|
|
c := Parse(test.input, PRC)
|
|
|
|
assert.Nil(c.Error)
|
2021-08-10 11:01:46 +08:00
|
|
|
assert.Equal(test.expected, c.ToShortWeekString(PRC), "Current test index is "+strconv.Itoa(index))
|
2021-02-23 09:32:55 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-18 14:32:31 +08:00
|
|
|
func TestCarbon_ToDayDateTimeString(t *testing.T) {
|
2021-07-19 09:33:57 +08:00
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
tests := []struct {
|
2021-07-23 10:59:53 +08:00
|
|
|
input string // 输入值
|
|
|
|
expected string // 期望值
|
2021-02-18 14:32:31 +08:00
|
|
|
}{
|
2021-08-10 11:01:46 +08:00
|
|
|
{"", ""},
|
|
|
|
{"0", ""},
|
|
|
|
{"0000-00-00", ""},
|
|
|
|
{"00:00:00", ""},
|
|
|
|
{"0000-00-00 00:00:00", ""},
|
2021-07-19 09:33:57 +08:00
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
{"2020-08-05 13:14:15", "Wed, Aug 5, 2020 1:14 PM"},
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
for index, test := range tests {
|
2021-07-23 10:59:53 +08:00
|
|
|
c := Parse(test.input, PRC)
|
2021-07-19 09:33:57 +08:00
|
|
|
assert.Nil(c.Error)
|
2021-08-10 11:01:46 +08:00
|
|
|
assert.Equal(test.expected, c.ToDayDateTimeString(), "Current test index is "+strconv.Itoa(index))
|
2021-07-19 09:33:57 +08:00
|
|
|
}
|
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
for index, test := range tests {
|
2021-07-23 10:59:53 +08:00
|
|
|
c := Parse(test.input, PRC)
|
2021-07-19 09:33:57 +08:00
|
|
|
assert.Nil(c.Error)
|
2021-08-10 11:01:46 +08:00
|
|
|
assert.Equal(test.expected, c.ToDayDateTimeString(PRC), "Current test index is "+strconv.Itoa(index))
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_ToDateTimeString(t *testing.T) {
|
2021-07-19 09:33:57 +08:00
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
tests := []struct {
|
2021-07-23 10:59:53 +08:00
|
|
|
input string // 输入值
|
|
|
|
expected string // 期望值
|
2021-02-18 14:32:31 +08:00
|
|
|
}{
|
2021-08-10 11:01:46 +08:00
|
|
|
{"", ""},
|
|
|
|
{"0", ""},
|
|
|
|
{"0000-00-00", ""},
|
|
|
|
{"00:00:00", ""},
|
|
|
|
{"0000-00-00 00:00:00", ""},
|
2021-07-19 09:33:57 +08:00
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
{"2020-08-05 13:14:15", "2020-08-05 13:14:15"},
|
|
|
|
{"2020-08-05", "2020-08-05 00:00:00"},
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
for index, test := range tests {
|
2021-07-23 10:59:53 +08:00
|
|
|
c := Parse(test.input, PRC)
|
|
|
|
assert.Nil(c.Error)
|
2021-08-10 11:01:46 +08:00
|
|
|
assert.Equal(test.expected, c.ToDateTimeString(), "Current test index is "+strconv.Itoa(index))
|
2021-07-23 10:59:53 +08:00
|
|
|
}
|
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
for index, test := range tests {
|
2021-07-23 10:59:53 +08:00
|
|
|
c := Parse(test.input, PRC)
|
2021-07-19 09:33:57 +08:00
|
|
|
assert.Nil(c.Error)
|
2021-08-10 11:01:46 +08:00
|
|
|
assert.Equal(test.expected, c.ToDateTimeString(PRC), "Current test index is "+strconv.Itoa(index))
|
2021-07-19 09:33:57 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-23 10:59:53 +08:00
|
|
|
func TestCarbon_ToShortDateTimeString(t *testing.T) {
|
2021-07-19 09:33:57 +08:00
|
|
|
assert := assert.New(t)
|
2021-02-18 14:32:31 +08:00
|
|
|
|
2021-07-19 09:33:57 +08:00
|
|
|
tests := []struct {
|
2021-07-23 10:59:53 +08:00
|
|
|
input string // 输入值
|
|
|
|
expected string // 期望值
|
2021-07-19 09:33:57 +08:00
|
|
|
}{
|
2021-08-10 11:01:46 +08:00
|
|
|
{"", ""},
|
|
|
|
{"0", ""},
|
|
|
|
{"0000-00-00", ""},
|
|
|
|
{"00:00:00", ""},
|
|
|
|
{"0000-00-00 00:00:00", ""},
|
2021-07-19 09:33:57 +08:00
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
{"2020-08-05 13:14:15", "20200805131415"},
|
|
|
|
{"2020-08-05", "20200805000000"},
|
2021-07-19 09:33:57 +08:00
|
|
|
}
|
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
for index, test := range tests {
|
2021-07-23 10:59:53 +08:00
|
|
|
c := Parse(test.input, PRC)
|
2021-07-19 09:33:57 +08:00
|
|
|
assert.Nil(c.Error)
|
2021-08-10 11:01:46 +08:00
|
|
|
assert.Equal(test.expected, c.ToShortDateTimeString(), "Current test index is "+strconv.Itoa(index))
|
2021-07-23 10:59:53 +08:00
|
|
|
}
|
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
for index, test := range tests {
|
2021-07-23 10:59:53 +08:00
|
|
|
c := Parse(test.input, PRC)
|
|
|
|
assert.Nil(c.Error)
|
2021-08-10 11:01:46 +08:00
|
|
|
assert.Equal(test.expected, c.ToShortDateTimeString(PRC), "Current test index is "+strconv.Itoa(index))
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_ToDateString(t *testing.T) {
|
2021-07-19 09:33:57 +08:00
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
tests := []struct {
|
2021-07-23 10:59:53 +08:00
|
|
|
input string // 输入值
|
|
|
|
expected string // 期望值
|
2021-02-18 14:32:31 +08:00
|
|
|
}{
|
2021-08-10 11:01:46 +08:00
|
|
|
{"", ""},
|
|
|
|
{"0", ""},
|
|
|
|
{"0000-00-00", ""},
|
|
|
|
{"00:00:00", ""},
|
|
|
|
{"0000-00-00 00:00:00", ""},
|
2021-07-19 09:33:57 +08:00
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
{"2020-08-05 13:14:15", "2020-08-05"},
|
|
|
|
{"2020-08-05", "2020-08-05"},
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
for index, test := range tests {
|
2021-07-23 10:59:53 +08:00
|
|
|
c := Parse(test.input, PRC)
|
|
|
|
assert.Nil(c.Error)
|
2021-08-10 11:01:46 +08:00
|
|
|
assert.Equal(test.expected, c.ToDateString(), "Current test index is "+strconv.Itoa(index))
|
2021-07-23 10:59:53 +08:00
|
|
|
}
|
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
for index, test := range tests {
|
2021-07-23 10:59:53 +08:00
|
|
|
c := Parse(test.input, PRC)
|
2021-07-19 09:33:57 +08:00
|
|
|
assert.Nil(c.Error)
|
2021-08-10 11:01:46 +08:00
|
|
|
assert.Equal(test.expected, c.ToDateString(PRC), "Current test index is "+strconv.Itoa(index))
|
2021-07-19 09:33:57 +08:00
|
|
|
}
|
|
|
|
}
|
2021-02-18 14:32:31 +08:00
|
|
|
|
2021-07-23 10:59:53 +08:00
|
|
|
func TestCarbon_ToShortDateString(t *testing.T) {
|
2021-07-19 09:33:57 +08:00
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
tests := []struct {
|
2021-07-23 10:59:53 +08:00
|
|
|
input string // 输入值
|
|
|
|
expected string // 期望值
|
2021-07-19 09:33:57 +08:00
|
|
|
}{
|
2021-08-10 11:01:46 +08:00
|
|
|
{"", ""},
|
|
|
|
{"0", ""},
|
|
|
|
{"0000-00-00", ""},
|
|
|
|
{"00:00:00", ""},
|
|
|
|
{"0000-00-00 00:00:00", ""},
|
2021-07-19 09:33:57 +08:00
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
{"2020-08-05 13:14:15", "20200805"},
|
|
|
|
{"2020-08-05", "20200805"},
|
2021-07-23 10:59:53 +08:00
|
|
|
}
|
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
for index, test := range tests {
|
2021-07-23 10:59:53 +08:00
|
|
|
c := Parse(test.input, PRC)
|
|
|
|
assert.Nil(c.Error)
|
2021-08-10 11:01:46 +08:00
|
|
|
assert.Equal(test.expected, c.ToShortDateString(), "Current test index is "+strconv.Itoa(index))
|
2021-07-19 09:33:57 +08:00
|
|
|
}
|
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
for index, test := range tests {
|
2021-07-23 10:59:53 +08:00
|
|
|
c := Parse(test.input, PRC)
|
2021-07-19 09:33:57 +08:00
|
|
|
assert.Nil(c.Error)
|
2021-08-10 11:01:46 +08:00
|
|
|
assert.Equal(test.expected, c.ToShortDateString(PRC), "Current test index is "+strconv.Itoa(index))
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_ToTimeString(t *testing.T) {
|
2021-07-19 09:33:57 +08:00
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
tests := []struct {
|
2021-07-23 10:59:53 +08:00
|
|
|
input string // 输入值
|
|
|
|
expected string // 期望值
|
2021-02-18 14:32:31 +08:00
|
|
|
}{
|
2021-08-10 11:01:46 +08:00
|
|
|
{"", ""},
|
|
|
|
{"0", ""},
|
|
|
|
{"0000-00-00", ""},
|
|
|
|
{"00:00:00", ""},
|
|
|
|
{"0000-00-00 00:00:00", ""},
|
2021-07-19 09:33:57 +08:00
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
{"2020-08-05 13:14:15", "13:14:15"},
|
|
|
|
{"2020-08-05", "00:00:00"},
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
for index, test := range tests {
|
2021-07-23 10:59:53 +08:00
|
|
|
c := Parse(test.input, PRC)
|
2021-07-19 09:33:57 +08:00
|
|
|
assert.Nil(c.Error)
|
2021-08-10 11:01:46 +08:00
|
|
|
assert.Equal(test.expected, c.ToTimeString(), "Current test index is "+strconv.Itoa(index))
|
2021-07-23 10:59:53 +08:00
|
|
|
}
|
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
for index, test := range tests {
|
2021-07-23 10:59:53 +08:00
|
|
|
c := Parse(test.input, PRC)
|
|
|
|
assert.Nil(c.Error)
|
2021-08-10 11:01:46 +08:00
|
|
|
assert.Equal(test.expected, c.ToTimeString(PRC), "Current test index is "+strconv.Itoa(index))
|
2021-07-19 09:33:57 +08:00
|
|
|
}
|
|
|
|
}
|
2021-02-18 14:32:31 +08:00
|
|
|
|
2021-07-23 10:59:53 +08:00
|
|
|
func TestCarbon_ToShortTimeString(t *testing.T) {
|
2021-07-19 09:33:57 +08:00
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
tests := []struct {
|
2021-07-23 10:59:53 +08:00
|
|
|
input string // 输入值
|
|
|
|
expected string // 期望值
|
2021-07-19 09:33:57 +08:00
|
|
|
}{
|
2021-08-10 11:01:46 +08:00
|
|
|
{"", ""},
|
|
|
|
{"0", ""},
|
|
|
|
{"0000-00-00", ""},
|
|
|
|
{"00:00:00", ""},
|
|
|
|
{"0000-00-00 00:00:00", ""},
|
2021-07-19 09:33:57 +08:00
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
{"2020-08-05 13:14:15", "131415"},
|
|
|
|
{"2020-08-05", "000000"},
|
2021-07-19 09:33:57 +08:00
|
|
|
}
|
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
for index, test := range tests {
|
2021-07-23 10:59:53 +08:00
|
|
|
c := Parse(test.input, PRC)
|
2021-07-19 09:33:57 +08:00
|
|
|
assert.Nil(c.Error)
|
2021-08-10 11:01:46 +08:00
|
|
|
assert.Equal(test.expected, c.ToShortTimeString(), "Current test index is "+strconv.Itoa(index))
|
2021-07-23 10:59:53 +08:00
|
|
|
}
|
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
for index, test := range tests {
|
2021-07-23 10:59:53 +08:00
|
|
|
c := Parse(test.input, PRC)
|
|
|
|
assert.Nil(c.Error)
|
2021-08-10 11:01:46 +08:00
|
|
|
assert.Equal(test.expected, c.ToShortTimeString(PRC), "Current test index is "+strconv.Itoa(index))
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_ToAtomString(t *testing.T) {
|
2021-07-19 09:33:57 +08:00
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
tests := []struct {
|
2021-07-23 10:59:53 +08:00
|
|
|
input string // 输入值
|
|
|
|
expected string // 期望值
|
2021-02-18 14:32:31 +08:00
|
|
|
}{
|
2021-08-10 11:01:46 +08:00
|
|
|
{"", ""},
|
|
|
|
{"0", ""},
|
|
|
|
{"0000-00-00", ""},
|
|
|
|
{"00:00:00", ""},
|
|
|
|
{"0000-00-00 00:00:00", ""},
|
2021-07-19 09:33:57 +08:00
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
{"2020-08-05 13:14:15", "2020-08-05T13:14:15+08:00"},
|
|
|
|
{"2020-08-05", "2020-08-05T00:00:00+08:00"},
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
for index, test := range tests {
|
2021-07-23 10:59:53 +08:00
|
|
|
c := Parse(test.input, PRC)
|
2021-07-19 09:33:57 +08:00
|
|
|
assert.Nil(c.Error)
|
2021-08-10 11:01:46 +08:00
|
|
|
assert.Equal(test.expected, c.ToAtomString(), "Current test index is "+strconv.Itoa(index))
|
2021-07-19 09:33:57 +08:00
|
|
|
}
|
2021-02-18 14:32:31 +08:00
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
for index, test := range tests {
|
2021-07-23 10:59:53 +08:00
|
|
|
c := Parse(test.input, PRC)
|
2021-07-19 09:33:57 +08:00
|
|
|
assert.Nil(c.Error)
|
2021-08-10 11:01:46 +08:00
|
|
|
assert.Equal(test.expected, c.ToAtomString(PRC), "Current test index is "+strconv.Itoa(index))
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_ToAnsicString(t *testing.T) {
|
2021-07-19 09:33:57 +08:00
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
tests := []struct {
|
2021-07-23 10:59:53 +08:00
|
|
|
input string // 输入值
|
|
|
|
expected string // 期望值
|
2021-02-18 14:32:31 +08:00
|
|
|
}{
|
2021-08-10 11:01:46 +08:00
|
|
|
{"", ""},
|
|
|
|
{"0", ""},
|
|
|
|
{"0000-00-00", ""},
|
|
|
|
{"00:00:00", ""},
|
|
|
|
{"0000-00-00 00:00:00", ""},
|
2021-07-19 09:33:57 +08:00
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
{"2020-08-05 13:14:15", "Wed Aug 5 13:14:15 2020"},
|
|
|
|
{"2020-08-05", "Wed Aug 5 00:00:00 2020"},
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
for index, test := range tests {
|
2021-07-23 10:59:53 +08:00
|
|
|
c := Parse(test.input, PRC)
|
2021-07-19 09:33:57 +08:00
|
|
|
assert.Nil(c.Error)
|
2021-08-10 11:01:46 +08:00
|
|
|
assert.Equal(test.expected, c.ToAnsicString(), "Current test index is "+strconv.Itoa(index))
|
2021-07-19 09:33:57 +08:00
|
|
|
}
|
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
for index, test := range tests {
|
2021-07-23 10:59:53 +08:00
|
|
|
c := Parse(test.input, PRC)
|
2021-07-19 09:33:57 +08:00
|
|
|
assert.Nil(c.Error)
|
2021-08-10 11:01:46 +08:00
|
|
|
assert.Equal(test.expected, c.ToAnsicString(PRC), "Current test index is "+strconv.Itoa(index))
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_ToCookieString(t *testing.T) {
|
2021-07-19 09:33:57 +08:00
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
tests := []struct {
|
2021-07-23 10:59:53 +08:00
|
|
|
input string // 输入值
|
|
|
|
expected string // 期望值
|
2021-02-18 14:32:31 +08:00
|
|
|
}{
|
2021-08-10 11:01:46 +08:00
|
|
|
{"", ""},
|
|
|
|
{"0", ""},
|
|
|
|
{"0000-00-00", ""},
|
|
|
|
{"00:00:00", ""},
|
|
|
|
{"0000-00-00 00:00:00", ""},
|
2021-07-19 09:33:57 +08:00
|
|
|
|
2021-08-10 11:01:46 +08: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"},
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
for index, test := range tests {
|
2021-07-23 10:59:53 +08:00
|
|
|
c := Parse(test.input, PRC)
|
2021-07-19 09:33:57 +08:00
|
|
|
assert.Nil(c.Error)
|
2021-08-10 11:01:46 +08:00
|
|
|
assert.Equal(test.expected, c.ToCookieString(), "Current test index is "+strconv.Itoa(index))
|
2021-07-19 09:33:57 +08:00
|
|
|
}
|
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
for index, test := range tests {
|
2021-07-23 10:59:53 +08:00
|
|
|
c := Parse(test.input, PRC)
|
2021-07-19 09:33:57 +08:00
|
|
|
assert.Nil(c.Error)
|
2021-08-10 11:01:46 +08:00
|
|
|
assert.Equal(test.expected, c.ToCookieString(PRC), "Current test index is "+strconv.Itoa(index))
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_ToRssString(t *testing.T) {
|
2021-07-19 09:33:57 +08:00
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
tests := []struct {
|
2021-07-23 10:59:53 +08:00
|
|
|
input string // 输入值
|
|
|
|
expected string // 期望值
|
2021-02-18 14:32:31 +08:00
|
|
|
}{
|
2021-08-10 11:01:46 +08:00
|
|
|
{"", ""},
|
|
|
|
{"0", ""},
|
|
|
|
{"0000-00-00", ""},
|
|
|
|
{"00:00:00", ""},
|
|
|
|
{"0000-00-00 00:00:00", ""},
|
2021-07-19 09:33:57 +08:00
|
|
|
|
2021-08-10 11:01:46 +08: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"},
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
for index, test := range tests {
|
2021-07-23 10:59:53 +08:00
|
|
|
c := Parse(test.input, PRC)
|
2021-07-19 09:33:57 +08:00
|
|
|
assert.Nil(c.Error)
|
2021-08-10 11:01:46 +08:00
|
|
|
assert.Equal(test.expected, c.ToRssString(), "Current test index is "+strconv.Itoa(index))
|
2021-07-19 09:33:57 +08:00
|
|
|
}
|
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
for index, test := range tests {
|
2021-07-23 10:59:53 +08:00
|
|
|
c := Parse(test.input, PRC)
|
2021-07-19 09:33:57 +08:00
|
|
|
assert.Nil(c.Error)
|
2021-08-10 11:01:46 +08:00
|
|
|
assert.Equal(test.expected, c.ToRssString(PRC), "Current test index is "+strconv.Itoa(index))
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_ToW3cString(t *testing.T) {
|
2021-07-19 09:33:57 +08:00
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
tests := []struct {
|
2021-07-23 10:59:53 +08:00
|
|
|
input string // 输入值
|
|
|
|
expected string // 期望值
|
2021-02-18 14:32:31 +08:00
|
|
|
}{
|
2021-08-10 11:01:46 +08:00
|
|
|
{"", ""},
|
|
|
|
{"0", ""},
|
|
|
|
{"0000-00-00", ""},
|
|
|
|
{"00:00:00", ""},
|
|
|
|
{"0000-00-00 00:00:00", ""},
|
2021-07-19 09:33:57 +08:00
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
{"2020-08-05 13:14:15", "2020-08-05T13:14:15+08:00"},
|
|
|
|
{"2020-08-05", "2020-08-05T00:00:00+08:00"},
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
for index, test := range tests {
|
2021-07-23 10:59:53 +08:00
|
|
|
c := Parse(test.input, PRC)
|
2021-07-19 09:33:57 +08:00
|
|
|
assert.Nil(c.Error)
|
2021-08-10 11:01:46 +08:00
|
|
|
assert.Equal(test.expected, c.ToW3cString(), "Current test index is "+strconv.Itoa(index))
|
2021-07-19 09:33:57 +08:00
|
|
|
}
|
2021-02-18 14:32:31 +08:00
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
for index, test := range tests {
|
2021-07-23 10:59:53 +08:00
|
|
|
c := Parse(test.input, PRC)
|
2021-07-19 09:33:57 +08:00
|
|
|
assert.Nil(c.Error)
|
2021-08-10 11:01:46 +08:00
|
|
|
assert.Equal(test.expected, c.ToW3cString(PRC), "Current test index is "+strconv.Itoa(index))
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_ToUnixDateString(t *testing.T) {
|
2021-07-19 09:33:57 +08:00
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
tests := []struct {
|
2021-07-23 10:59:53 +08:00
|
|
|
input string // 输入值
|
|
|
|
expected string // 期望值
|
2021-02-18 14:32:31 +08:00
|
|
|
}{
|
2021-08-10 11:01:46 +08:00
|
|
|
{"", ""},
|
|
|
|
{"0", ""},
|
|
|
|
{"0000-00-00", ""},
|
|
|
|
{"00:00:00", ""},
|
|
|
|
{"0000-00-00 00:00:00", ""},
|
2021-07-19 09:33:57 +08:00
|
|
|
|
2021-08-10 11:01:46 +08: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"},
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
for index, test := range tests {
|
2021-07-23 10:59:53 +08:00
|
|
|
c := Parse(test.input, PRC)
|
2021-07-19 09:33:57 +08:00
|
|
|
assert.Nil(c.Error)
|
2021-08-10 11:01:46 +08:00
|
|
|
assert.Equal(test.expected, c.ToUnixDateString(), "Current test index is "+strconv.Itoa(index))
|
2021-07-19 09:33:57 +08:00
|
|
|
}
|
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
for index, test := range tests {
|
2021-07-23 10:59:53 +08:00
|
|
|
c := Parse(test.input, PRC)
|
2021-07-19 09:33:57 +08:00
|
|
|
assert.Nil(c.Error)
|
2021-08-10 11:01:46 +08:00
|
|
|
assert.Equal(test.expected, c.ToUnixDateString(PRC), "Current test index is "+strconv.Itoa(index))
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_ToRubyDateString(t *testing.T) {
|
2021-07-19 09:33:57 +08:00
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
tests := []struct {
|
2021-07-23 10:59:53 +08:00
|
|
|
input string // 输入值
|
|
|
|
expected string // 期望值
|
2021-02-18 14:32:31 +08:00
|
|
|
}{
|
2021-08-10 11:01:46 +08:00
|
|
|
{"", ""},
|
|
|
|
{"0", ""},
|
|
|
|
{"0000-00-00", ""},
|
|
|
|
{"00:00:00", ""},
|
|
|
|
{"0000-00-00 00:00:00", ""},
|
2021-07-19 09:33:57 +08:00
|
|
|
|
2021-08-10 11:01:46 +08: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"},
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
for index, test := range tests {
|
2021-07-23 10:59:53 +08:00
|
|
|
c := Parse(test.input, PRC)
|
2021-07-19 09:33:57 +08:00
|
|
|
assert.Nil(c.Error)
|
2021-08-10 11:01:46 +08:00
|
|
|
assert.Equal(test.expected, c.ToRubyDateString(), "Current test index is "+strconv.Itoa(index))
|
2021-07-19 09:33:57 +08:00
|
|
|
}
|
2021-02-18 14:32:31 +08:00
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
for index, test := range tests {
|
2021-07-23 10:59:53 +08:00
|
|
|
c := Parse(test.input, PRC)
|
2021-07-19 09:33:57 +08:00
|
|
|
assert.Nil(c.Error)
|
2021-08-10 11:01:46 +08:00
|
|
|
assert.Equal(test.expected, c.ToRubyDateString(PRC), "Current test index is "+strconv.Itoa(index))
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_ToKitchenString(t *testing.T) {
|
2021-07-19 09:33:57 +08:00
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
tests := []struct {
|
2021-07-23 10:59:53 +08:00
|
|
|
input string // 输入值
|
|
|
|
expected string // 期望值
|
2021-02-18 14:32:31 +08:00
|
|
|
}{
|
2021-08-10 11:01:46 +08:00
|
|
|
{"", ""},
|
|
|
|
{"0", ""},
|
|
|
|
{"0000-00-00", ""},
|
|
|
|
{"00:00:00", ""},
|
|
|
|
{"0000-00-00 00:00:00", ""},
|
2021-07-19 09:33:57 +08:00
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
{"2020-08-05 13:14:15", "1:14PM"},
|
|
|
|
{"2020-08-05", "12:00AM"},
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
for index, test := range tests {
|
2021-07-23 10:59:53 +08:00
|
|
|
c := Parse(test.input, PRC)
|
2021-07-19 09:33:57 +08:00
|
|
|
assert.Nil(c.Error)
|
2021-08-10 11:01:46 +08:00
|
|
|
assert.Equal(test.expected, test.expected, c.ToKitchenString(), "Current test index is "+strconv.Itoa(index))
|
2021-07-23 10:59:53 +08:00
|
|
|
}
|
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
for index, test := range tests {
|
2021-07-23 10:59:53 +08:00
|
|
|
c := Parse(test.input, PRC)
|
|
|
|
assert.Nil(c.Error)
|
2021-08-10 11:01:46 +08:00
|
|
|
assert.Equal(test.expected, test.expected, c.ToKitchenString(PRC), "Current test index is "+strconv.Itoa(index))
|
2021-07-19 09:33:57 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-23 10:59:53 +08:00
|
|
|
func TestCarbon_ToIso8601String(t *testing.T) {
|
2021-07-19 09:33:57 +08:00
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
tests := []struct {
|
2021-07-23 10:59:53 +08:00
|
|
|
input string // 输入值
|
|
|
|
expected string // 期望值
|
2021-07-19 09:33:57 +08:00
|
|
|
}{
|
2021-08-10 11:01:46 +08:00
|
|
|
{"", ""},
|
|
|
|
{"0", ""},
|
|
|
|
{"0000-00-00", ""},
|
|
|
|
{"00:00:00", ""},
|
|
|
|
{"0000-00-00 00:00:00", ""},
|
2021-07-19 09:33:57 +08:00
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
{"2020-08-05 13:14:15", "2020-08-05T13:14:15+08:00"},
|
|
|
|
{"2020-08-05", "2020-08-05T00:00:00+08:00"},
|
2021-07-19 09:33:57 +08:00
|
|
|
}
|
2021-02-18 14:32:31 +08:00
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
for index, test := range tests {
|
2021-07-23 10:59:53 +08:00
|
|
|
c := Parse(test.input, PRC)
|
2021-07-19 09:33:57 +08:00
|
|
|
assert.Nil(c.Error)
|
2021-08-10 11:01:46 +08:00
|
|
|
assert.Equal(test.expected, c.ToIso8601String(), "Current test index is "+strconv.Itoa(index))
|
2021-07-23 10:59:53 +08:00
|
|
|
}
|
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
for index, test := range tests {
|
2021-07-23 10:59:53 +08:00
|
|
|
c := Parse(test.input, PRC)
|
|
|
|
assert.Nil(c.Error)
|
2021-08-10 11:01:46 +08:00
|
|
|
assert.Equal(test.expected, c.ToIso8601String(PRC), "Current test index is "+strconv.Itoa(index))
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_ToRfc822String(t *testing.T) {
|
2021-07-19 09:33:57 +08:00
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
tests := []struct {
|
2021-07-23 10:59:53 +08:00
|
|
|
input string // 输入值
|
|
|
|
expected string // 期望值
|
2021-02-18 14:32:31 +08:00
|
|
|
}{
|
2021-08-10 11:01:46 +08:00
|
|
|
{"", ""},
|
|
|
|
{"0", ""},
|
|
|
|
{"0000-00-00", ""},
|
|
|
|
{"00:00:00", ""},
|
|
|
|
{"0000-00-00 00:00:00", ""},
|
2021-07-19 09:33:57 +08:00
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
{"2020-08-05 13:14:15", "05 Aug 20 13:14 CST"},
|
|
|
|
{"2020-08-05", "05 Aug 20 00:00 CST"},
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
for index, test := range tests {
|
2021-07-23 10:59:53 +08:00
|
|
|
c := Parse(test.input, PRC)
|
2021-07-19 09:33:57 +08:00
|
|
|
assert.Nil(c.Error)
|
2021-08-10 11:01:46 +08:00
|
|
|
assert.Equal(test.expected, c.ToRfc822String(), "Current test index is "+strconv.Itoa(index))
|
2021-07-19 09:33:57 +08:00
|
|
|
}
|
2021-02-18 14:32:31 +08:00
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
for index, test := range tests {
|
2021-07-23 10:59:53 +08:00
|
|
|
c := Parse(test.input, PRC)
|
2021-07-19 09:33:57 +08:00
|
|
|
assert.Nil(c.Error)
|
2021-08-10 11:01:46 +08:00
|
|
|
assert.Equal(test.expected, c.ToRfc822String(PRC), "Current test index is "+strconv.Itoa(index))
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_ToRfc822zString(t *testing.T) {
|
2021-07-19 09:33:57 +08:00
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
tests := []struct {
|
2021-07-23 10:59:53 +08:00
|
|
|
input string // 输入值
|
|
|
|
expected string // 期望值
|
2021-02-18 14:32:31 +08:00
|
|
|
}{
|
2021-08-10 11:01:46 +08:00
|
|
|
{"", ""},
|
|
|
|
{"0", ""},
|
|
|
|
{"0000-00-00", ""},
|
|
|
|
{"00:00:00", ""},
|
|
|
|
{"0000-00-00 00:00:00", ""},
|
2021-07-19 09:33:57 +08:00
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
{"2020-08-05 13:14:15", "05 Aug 20 13:14 +0800"},
|
|
|
|
{"2020-08-05", "05 Aug 20 00:00 +0800"},
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
for index, test := range tests {
|
2021-07-23 10:59:53 +08:00
|
|
|
c := Parse(test.input, PRC)
|
2021-07-19 09:33:57 +08:00
|
|
|
assert.Nil(c.Error)
|
2021-08-10 11:01:46 +08:00
|
|
|
assert.Equal(test.expected, c.ToRfc822zString(), "Current test index is "+strconv.Itoa(index))
|
2021-07-19 09:33:57 +08:00
|
|
|
}
|
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
for index, test := range tests {
|
2021-07-23 10:59:53 +08:00
|
|
|
c := Parse(test.input, PRC)
|
2021-07-19 09:33:57 +08:00
|
|
|
assert.Nil(c.Error)
|
2021-08-10 11:01:46 +08:00
|
|
|
assert.Equal(test.expected, c.ToRfc822zString(PRC), "Current test index is "+strconv.Itoa(index))
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_ToRfc850String(t *testing.T) {
|
2021-07-19 09:33:57 +08:00
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
tests := []struct {
|
2021-07-23 10:59:53 +08:00
|
|
|
input string // 输入值
|
|
|
|
expected string // 期望值
|
2021-02-18 14:32:31 +08:00
|
|
|
}{
|
2021-08-10 11:01:46 +08:00
|
|
|
{"", ""},
|
|
|
|
{"0", ""},
|
|
|
|
{"0000-00-00", ""},
|
|
|
|
{"00:00:00", ""},
|
|
|
|
{"0000-00-00 00:00:00", ""},
|
2021-07-19 09:33:57 +08:00
|
|
|
|
2021-08-10 11:01:46 +08: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"},
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
for index, test := range tests {
|
2021-07-23 10:59:53 +08:00
|
|
|
c := Parse(test.input, PRC)
|
2021-07-19 09:33:57 +08:00
|
|
|
assert.Nil(c.Error)
|
2021-08-10 11:01:46 +08:00
|
|
|
assert.Equal(test.expected, c.ToRfc850String(), "Current test index is "+strconv.Itoa(index))
|
2021-07-19 09:33:57 +08:00
|
|
|
}
|
2021-02-18 14:32:31 +08:00
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
for index, test := range tests {
|
2021-07-23 10:59:53 +08:00
|
|
|
c := Parse(test.input, PRC)
|
2021-07-19 09:33:57 +08:00
|
|
|
assert.Nil(c.Error)
|
2021-08-10 11:01:46 +08:00
|
|
|
assert.Equal(test.expected, c.ToRfc850String(PRC), "Current test index is "+strconv.Itoa(index))
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_ToRfc1036String(t *testing.T) {
|
2021-07-19 09:33:57 +08:00
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
tests := []struct {
|
2021-07-23 10:59:53 +08:00
|
|
|
input string // 输入值
|
|
|
|
expected string // 期望值
|
2021-02-18 14:32:31 +08:00
|
|
|
}{
|
2021-08-10 11:01:46 +08:00
|
|
|
{"", ""},
|
|
|
|
{"0", ""},
|
|
|
|
{"0000-00-00", ""},
|
|
|
|
{"00:00:00", ""},
|
|
|
|
{"0000-00-00 00:00:00", ""},
|
2021-07-19 09:33:57 +08:00
|
|
|
|
2021-08-10 11:01:46 +08: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"},
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
for index, test := range tests {
|
2021-07-23 10:59:53 +08:00
|
|
|
c := Parse(test.input, PRC)
|
2021-07-19 09:33:57 +08:00
|
|
|
assert.Nil(c.Error)
|
2021-08-10 11:01:46 +08:00
|
|
|
assert.Equal(test.expected, c.ToRfc1036String(), "Current test index is "+strconv.Itoa(index))
|
2021-07-19 09:33:57 +08:00
|
|
|
}
|
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
for index, test := range tests {
|
2021-07-23 10:59:53 +08:00
|
|
|
c := Parse(test.input, PRC)
|
2021-07-19 09:33:57 +08:00
|
|
|
assert.Nil(c.Error)
|
2021-08-10 11:01:46 +08:00
|
|
|
assert.Equal(test.expected, c.ToRfc1036String(PRC), "Current test index is "+strconv.Itoa(index))
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_ToRfc1123String(t *testing.T) {
|
2021-07-19 09:33:57 +08:00
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
tests := []struct {
|
2021-07-23 10:59:53 +08:00
|
|
|
input string // 输入值
|
|
|
|
expected string // 期望值
|
2021-02-18 14:32:31 +08:00
|
|
|
}{
|
2021-08-10 11:01:46 +08:00
|
|
|
{"", ""},
|
|
|
|
{"0", ""},
|
|
|
|
{"0000-00-00", ""},
|
|
|
|
{"00:00:00", ""},
|
|
|
|
{"0000-00-00 00:00:00", ""},
|
2021-07-19 09:33:57 +08:00
|
|
|
|
2021-08-10 11:01:46 +08: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"},
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
for index, test := range tests {
|
2021-07-23 10:59:53 +08:00
|
|
|
c := Parse(test.input, PRC)
|
2021-07-19 09:33:57 +08:00
|
|
|
assert.Nil(c.Error)
|
2021-08-10 11:01:46 +08:00
|
|
|
assert.Equal(test.expected, c.ToRfc1123String(), "Current test index is "+strconv.Itoa(index))
|
2021-07-19 09:33:57 +08:00
|
|
|
}
|
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
for index, test := range tests {
|
2021-07-23 10:59:53 +08:00
|
|
|
c := Parse(test.input, PRC)
|
2021-07-19 09:33:57 +08:00
|
|
|
assert.Nil(c.Error)
|
2021-08-10 11:01:46 +08:00
|
|
|
assert.Equal(test.expected, c.ToRfc1123String(PRC), "Current test index is "+strconv.Itoa(index))
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-28 09:20:33 +08:00
|
|
|
func TestCarbon_ToRfc1123zString(t *testing.T) {
|
2021-07-19 09:33:57 +08:00
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
tests := []struct {
|
2021-07-23 10:59:53 +08:00
|
|
|
input string // 输入值
|
|
|
|
expected string // 期望值
|
2021-02-18 14:32:31 +08:00
|
|
|
}{
|
2021-08-10 11:01:46 +08:00
|
|
|
{"", ""},
|
|
|
|
{"0", ""},
|
|
|
|
{"0000-00-00", ""},
|
|
|
|
{"00:00:00", ""},
|
|
|
|
{"0000-00-00 00:00:00", ""},
|
2021-07-19 09:33:57 +08:00
|
|
|
|
2021-08-10 11:01:46 +08: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"},
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
for index, test := range tests {
|
2021-07-23 10:59:53 +08:00
|
|
|
c := Parse(test.input, PRC)
|
2021-07-19 09:33:57 +08:00
|
|
|
assert.Nil(c.Error)
|
2021-08-10 11:01:46 +08:00
|
|
|
assert.Equal(test.expected, c.ToRfc1123zString(), "Current test index is "+strconv.Itoa(index))
|
2021-07-19 09:33:57 +08:00
|
|
|
}
|
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
for index, test := range tests {
|
2021-07-23 10:59:53 +08:00
|
|
|
c := Parse(test.input, PRC)
|
2021-07-19 09:33:57 +08:00
|
|
|
assert.Nil(c.Error)
|
2021-08-10 11:01:46 +08:00
|
|
|
assert.Equal(test.expected, c.ToRfc1123zString(PRC), "Current test index is "+strconv.Itoa(index))
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_ToRfc2822String(t *testing.T) {
|
2021-07-19 09:33:57 +08:00
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
tests := []struct {
|
2021-07-23 10:59:53 +08:00
|
|
|
input string // 输入值
|
|
|
|
expected string // 期望值
|
2021-02-18 14:32:31 +08:00
|
|
|
}{
|
2021-08-10 11:01:46 +08:00
|
|
|
{"", ""},
|
|
|
|
{"0", ""},
|
|
|
|
{"0000-00-00", ""},
|
|
|
|
{"00:00:00", ""},
|
|
|
|
{"0000-00-00 00:00:00", ""},
|
2021-07-19 09:33:57 +08:00
|
|
|
|
2021-08-10 11:01:46 +08: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"},
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
for index, test := range tests {
|
2021-07-23 10:59:53 +08:00
|
|
|
c := Parse(test.input, PRC)
|
2021-07-19 09:33:57 +08:00
|
|
|
assert.Nil(c.Error)
|
2021-08-10 11:01:46 +08:00
|
|
|
assert.Equal(test.expected, c.ToRfc2822String(), "Current test index is "+strconv.Itoa(index))
|
2021-07-19 09:33:57 +08:00
|
|
|
}
|
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
for index, test := range tests {
|
2021-07-23 10:59:53 +08:00
|
|
|
c := Parse(test.input, PRC)
|
2021-07-19 09:33:57 +08:00
|
|
|
assert.Nil(c.Error)
|
2021-08-10 11:01:46 +08:00
|
|
|
assert.Equal(test.expected, c.ToRfc2822String(PRC), "Current test index is "+strconv.Itoa(index))
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_ToRfc3339String(t *testing.T) {
|
2021-07-19 09:33:57 +08:00
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
tests := []struct {
|
2021-07-23 10:59:53 +08:00
|
|
|
input string // 输入值
|
|
|
|
expected string // 期望值
|
2021-02-18 14:32:31 +08:00
|
|
|
}{
|
2021-08-10 11:01:46 +08:00
|
|
|
{"", ""},
|
|
|
|
{"0", ""},
|
|
|
|
{"0000-00-00", ""},
|
|
|
|
{"00:00:00", ""},
|
|
|
|
{"0000-00-00 00:00:00", ""},
|
2021-07-19 09:33:57 +08:00
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
{"2020-08-05 13:14:15", "2020-08-05T13:14:15+08:00"},
|
|
|
|
{"2020-08-05", "2020-08-05T00:00:00+08:00"},
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
for index, test := range tests {
|
2021-07-23 10:59:53 +08:00
|
|
|
c := Parse(test.input, PRC)
|
|
|
|
assert.Nil(c.Error)
|
2021-08-10 11:01:46 +08:00
|
|
|
assert.Equal(test.expected, c.ToRfc3339String(), "Current test index is "+strconv.Itoa(index))
|
2021-07-23 10:59:53 +08:00
|
|
|
}
|
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
for index, test := range tests {
|
2021-07-23 10:59:53 +08:00
|
|
|
c := Parse(test.input, PRC)
|
2021-07-19 09:33:57 +08:00
|
|
|
assert.Nil(c.Error)
|
2021-08-10 11:01:46 +08:00
|
|
|
assert.Equal(test.expected, c.ToRfc3339String(PRC), "Current test index is "+strconv.Itoa(index))
|
2021-07-19 09:33:57 +08:00
|
|
|
}
|
|
|
|
}
|
2021-02-18 14:32:31 +08:00
|
|
|
|
2021-07-23 10:59:53 +08:00
|
|
|
func TestCarbon_ToRfc7231String(t *testing.T) {
|
2021-07-19 09:33:57 +08:00
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
tests := []struct {
|
2021-07-23 10:59:53 +08:00
|
|
|
input string // 输入值
|
|
|
|
expected string // 期望值
|
2021-07-19 09:33:57 +08:00
|
|
|
}{
|
2021-08-10 11:01:46 +08:00
|
|
|
{"", ""},
|
|
|
|
{"0", ""},
|
|
|
|
{"0000-00-00", ""},
|
|
|
|
{"00:00:00", ""},
|
|
|
|
{"0000-00-00 00:00:00", ""},
|
2021-07-19 09:33:57 +08:00
|
|
|
|
2021-08-10 11:01:46 +08: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"},
|
2021-07-23 10:59:53 +08:00
|
|
|
}
|
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
for index, test := range tests {
|
2021-07-23 10:59:53 +08:00
|
|
|
c := Parse(test.input, PRC)
|
|
|
|
assert.Nil(c.Error)
|
2021-08-10 11:01:46 +08:00
|
|
|
assert.Equal(test.expected, c.ToRfc7231String(), "Current test index is "+strconv.Itoa(index))
|
2021-07-19 09:33:57 +08:00
|
|
|
}
|
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
for index, test := range tests {
|
2021-07-23 10:59:53 +08:00
|
|
|
c := Parse(test.input, PRC)
|
2021-07-19 09:33:57 +08:00
|
|
|
assert.Nil(c.Error)
|
2021-08-10 11:01:46 +08:00
|
|
|
assert.Equal(test.expected, c.ToRfc7231String(PRC), "Current test index is "+strconv.Itoa(index))
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-23 10:59:53 +08:00
|
|
|
func TestCarbon_Layout(t *testing.T) {
|
2021-07-19 09:33:57 +08:00
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
tests := []struct {
|
2021-07-23 10:59:53 +08:00
|
|
|
input string // 输入值
|
|
|
|
param string // 参数值
|
|
|
|
expected string // 期望值
|
2021-02-18 14:32:31 +08:00
|
|
|
}{
|
2021-08-10 11:01:46 +08:00
|
|
|
{"", "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日", ""},
|
2021-07-19 09:33:57 +08:00
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
{"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"},
|
2021-07-23 10:59:53 +08:00
|
|
|
}
|
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
for index, test := range tests {
|
2021-07-23 10:59:53 +08:00
|
|
|
c := Parse(test.input, PRC)
|
|
|
|
assert.Nil(c.Error)
|
2021-08-10 11:01:46 +08:00
|
|
|
assert.Equal(test.expected, c.Layout(test.param), "Current test index is "+strconv.Itoa(index))
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
for index, test := range tests {
|
2021-07-23 10:59:53 +08:00
|
|
|
c := Parse(test.input, PRC)
|
2021-07-19 09:33:57 +08:00
|
|
|
assert.Nil(c.Error)
|
2021-08-10 11:01:46 +08:00
|
|
|
assert.Equal(test.expected, c.ToLayoutString(test.param), "Current test index is "+strconv.Itoa(index))
|
2021-07-23 10:59:53 +08:00
|
|
|
}
|
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
for index, test := range tests {
|
2021-07-23 10:59:53 +08:00
|
|
|
c := Parse(test.input, PRC)
|
|
|
|
assert.Nil(c.Error)
|
2021-08-10 11:01:46 +08:00
|
|
|
assert.Equal(test.expected, c.Layout(test.param, PRC), "Current test index is "+strconv.Itoa(index))
|
2021-07-23 10:59:53 +08:00
|
|
|
}
|
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
for index, test := range tests {
|
2021-07-23 10:59:53 +08:00
|
|
|
c := Parse(test.input, PRC)
|
|
|
|
assert.Nil(c.Error)
|
2021-08-10 11:01:46 +08:00
|
|
|
assert.Equal(test.expected, c.ToLayoutString(test.param, PRC), "Current test index is "+strconv.Itoa(index))
|
2021-07-19 09:33:57 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-23 10:59:53 +08:00
|
|
|
func TestCarbon_Format(t *testing.T) {
|
2021-07-19 09:33:57 +08:00
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
tests := []struct {
|
2021-07-23 10:59:53 +08:00
|
|
|
input string // 输入值
|
|
|
|
param string // 参数值
|
|
|
|
expected string // 期望值
|
2021-07-19 09:33:57 +08:00
|
|
|
}{
|
2021-08-10 11:01:46 +08:00
|
|
|
{"", "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日", ""},
|
2021-07-23 10:59:53 +08:00
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
{"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", "l jS of F Y h:i:s A", "Wednesday 5th of August 2020 01:14:15 PM"},
|
2021-07-23 10:59:53 +08:00
|
|
|
}
|
2021-07-19 09:33:57 +08:00
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
for index, test := range tests {
|
2021-07-23 10:59:53 +08:00
|
|
|
c := Parse(test.input, PRC)
|
|
|
|
assert.Nil(c.Error)
|
2021-08-10 11:01:46 +08:00
|
|
|
assert.Equal(test.expected, c.Format(test.param), "Current test index is "+strconv.Itoa(index))
|
2021-07-23 10:59:53 +08:00
|
|
|
}
|
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
for index, test := range tests {
|
2021-07-23 10:59:53 +08:00
|
|
|
c := Parse(test.input, PRC)
|
|
|
|
assert.Nil(c.Error)
|
2021-08-10 11:01:46 +08:00
|
|
|
assert.Equal(test.expected, c.ToFormatString(test.param), "Current test index is "+strconv.Itoa(index))
|
2021-07-19 09:33:57 +08:00
|
|
|
}
|
2021-02-18 14:32:31 +08:00
|
|
|
|
2021-08-10 11:01:46 +08:00
|
|
|
for index, test := range tests {
|
2021-07-23 10:59:53 +08:00
|
|
|
c := Parse(test.input, PRC)
|
2021-07-19 09:33:57 +08:00
|
|
|
assert.Nil(c.Error)
|
2021-08-10 11:01:46 +08:00
|
|
|
assert.Equal(test.expected, c.ToFormatString(test.param, PRC), "Current test index is "+strconv.Itoa(index))
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|