From 12de94fbc62ddba6866ed5e47cac843bc1616d17 Mon Sep 17 00:00:00 2001 From: gouguoyin <245629560@qq.com> Date: Mon, 19 Jul 2021 14:35:19 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8github.com/stretchr/testify/a?= =?UTF-8?q?ssert=E5=BA=93=E6=9B=BF=E4=BB=A3=E5=8E=9F=E7=94=9Ftesting?= =?UTF-8?q?=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- display_test.go | 1222 ++++++++++++++++++++++++---------------------- language_test.go | 69 +-- modifier_test.go | 673 ++++++++++++------------- 3 files changed, 1026 insertions(+), 938 deletions(-) diff --git a/display_test.go b/display_test.go index 8a9b6986..35165340 100755 --- a/display_test.go +++ b/display_test.go @@ -2,6 +2,7 @@ package carbon import ( "fmt" + "strconv" "testing" "github.com/stretchr/testify/assert" @@ -11,26 +12,27 @@ func TestCarbon_ToTimestamp(t *testing.T) { assert := assert.New(t) tests := []struct { + id int // 测试id input string // 输入值 output int64 // 期望输出值 }{ - {"", 0}, - {"0", 0}, - {"0000-00-00", 0}, - {"00:00:00", 0}, - {"0000-00-00 00:00:00", 0}, + {1, "", 0}, + {2, "0", 0}, + {3, "0000-00-00", 0}, + {4, "00:00:00", 0}, + {5, "0000-00-00 00:00:00", 0}, - {"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}, + {1, "2020-01-01 13:14:15", 1577855655}, + {2, "2020-01-31 13:14:15", 1580447655}, + {3, "2020-02-01 13:14:15", 1580534055}, + {4, "2020-02-28 13:14:15", 1582866855}, + {5, "2020-02-29 13:14:15", 1582953255}, } for _, test := range tests { c := Parse(test.input) assert.Nil(c.Error) - assert.Equal(c.ToTimestamp(), test.output) + assert.Equal(c.ToTimestamp(), test.output, "Current test id is "+strconv.Itoa(test.id)) } } @@ -38,26 +40,27 @@ func TestCarbon_ToTimestampWithSecond(t *testing.T) { assert := assert.New(t) tests := []struct { + id int // 测试id input string // 输入值 output int64 // 期望输出值 }{ - {"", 0}, - {"0", 0}, - {"0000-00-00", 0}, - {"00:00:00", 0}, - {"0000-00-00 00:00:00", 0}, + {1, "", 0}, + {2, "0", 0}, + {3, "0000-00-00", 0}, + {4, "00:00:00", 0}, + {5, "0000-00-00 00:00:00", 0}, - {"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}, + {6, "2020-01-01 13:14:15", 1577855655}, + {7, "2020-01-31 13:14:15", 1580447655}, + {8, "2020-02-01 13:14:15", 1580534055}, + {9, "2020-02-28 13:14:15", 1582866855}, + {10, "2020-02-29 13:14:15", 1582953255}, } for _, test := range tests { c := Parse(test.input) assert.Nil(c.Error) - assert.Equal(c.ToTimestampWithSecond(), test.output) + assert.Equal(c.ToTimestampWithSecond(), test.output, "Current test id is "+strconv.Itoa(test.id)) } } @@ -65,26 +68,27 @@ func TestCarbon_ToTimestampWithMillisecond(t *testing.T) { assert := assert.New(t) tests := []struct { + id int // 测试id input string // 输入值 output int64 // 期望输出值 }{ - {"", 0}, - {"0", 0}, - {"0000-00-00", 0}, - {"00:00:00", 0}, - {"0000-00-00 00:00:00", 0}, + {1, "", 0}, + {2, "0", 0}, + {3, "0000-00-00", 0}, + {4, "00:00:00", 0}, + {5, "0000-00-00 00:00:00", 0}, - {"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}, + {6, "2020-01-01 13:14:15", 1577855655000}, + {7, "2020-01-31 13:14:15", 1580447655000}, + {8, "2020-02-01 13:14:15", 1580534055000}, + {9, "2020-02-28 13:14:15", 1582866855000}, + {10, "2020-02-29 13:14:15", 1582953255000}, } for _, test := range tests { c := Parse(test.input) assert.Nil(c.Error) - assert.Equal(c.ToTimestampWithMillisecond(), test.output) + assert.Equal(c.ToTimestampWithMillisecond(), test.output, "Current test id is "+strconv.Itoa(test.id)) } } @@ -92,26 +96,27 @@ func TestCarbon_ToTimestampWithMicrosecond(t *testing.T) { assert := assert.New(t) tests := []struct { + id int // 测试id input string // 输入值 output int64 // 期望输出值 }{ - {"", 0}, - {"0", 0}, - {"0000-00-00", 0}, - {"00:00:00", 0}, - {"0000-00-00 00:00:00", 0}, + {1, "", 0}, + {2, "0", 0}, + {3, "0000-00-00", 0}, + {4, "00:00:00", 0}, + {5, "0000-00-00 00:00:00", 0}, - {"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}, + {6, "2020-01-01 13:14:15", 1577855655000000}, + {7, "2020-01-31 13:14:15", 1580447655000000}, + {8, "2020-02-01 13:14:15", 1580534055000000}, + {9, "2020-02-28 13:14:15", 1582866855000000}, + {10, "2020-02-29 13:14:15", 1582953255000000}, } for _, test := range tests { c := Parse(test.input) assert.Nil(c.Error) - assert.Equal(c.ToTimestampWithMicrosecond(), test.output) + assert.Equal(c.ToTimestampWithMicrosecond(), test.output, "Current test id is "+strconv.Itoa(test.id)) } } @@ -119,26 +124,27 @@ func TestCarbon_ToTimestampWithNanosecond(t *testing.T) { assert := assert.New(t) tests := []struct { + id int // 测试id input string // 输入值 output int64 // 期望输出值 }{ - {"", 0}, - {"0", 0}, - {"0000-00-00", 0}, - {"00:00:00", 0}, - {"0000-00-00 00:00:00", 0}, + {1, "", 0}, + {2, "0", 0}, + {3, "0000-00-00", 0}, + {4, "00:00:00", 0}, + {5, "0000-00-00 00:00:00", 0}, - {"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}, + {6, "2020-01-01 13:14:15", 1577855655000000000}, + {7, "2020-01-31 13:14:15", 1580447655000000000}, + {8, "2020-02-01 13:14:15", 1580534055000000000}, + {9, "2020-02-28 13:14:15", 1582866855000000000}, + {10, "2020-02-29 13:14:15", 1582953255000000000}, } for _, test := range tests { c := Parse(test.input) assert.Nil(c.Error) - assert.Equal(c.ToTimestampWithNanosecond(), test.output) + assert.Equal(c.ToTimestampWithNanosecond(), test.output, "Current test id is "+strconv.Itoa(test.id)) } } @@ -146,44 +152,47 @@ func TestCarbon_String(t *testing.T) { assert := assert.New(t) tests := []struct { + id int // 测试id input string // 输入值 output string // 期望输出值 }{ - {"", ""}, - {"0", ""}, - {"0000-00-00", ""}, - {"00:00:00", ""}, - {"0000-00-00 00:00:00", ""}, + {1, "", ""}, + {2, "0", ""}, + {3, "0000-00-00", ""}, + {4, "00:00:00", ""}, + {5, "0000-00-00 00:00:00", ""}, - {"2020-08-05 13:14:15", "2020-08-05 13:14:15"}, + {6, "2020-08-05 13:14:15", "2020-08-05 13:14:15"}, } for _, test := range tests { c := Parse(test.input) assert.Nil(c.Error) - assert.Equal(fmt.Sprintf("%s", Parse(test.input)), test.output) + assert.Equal(fmt.Sprintf("%s", Parse(test.input)), test.output, "Current test id is "+strconv.Itoa(test.id)) } } func TestCarbon_ToString(t *testing.T) { assert := assert.New(t) + tests := []struct { + id int // 测试id input string // 输入值 output string // 期望输出值 }{ - {"", ""}, - {"0", ""}, - {"0000-00-00", ""}, - {"00:00:00", ""}, - {"0000-00-00 00:00:00", ""}, + {1, "", ""}, + {2, "0", ""}, + {3, "0000-00-00", ""}, + {4, "00:00:00", ""}, + {5, "0000-00-00 00:00:00", ""}, - {"2020-08-05 13:14:15", "2020-08-05 13:14:15 +0800 CST"}, + {6, "2020-08-05 13:14:15", "2020-08-05 13:14:15 +0800 CST"}, } for _, test := range tests { c := Parse(test.input) assert.Nil(c.Error) - assert.Equal(c.ToString(), test.output) + assert.Equal(c.ToString(), test.output, "Current test id is "+strconv.Itoa(test.id)) } } @@ -191,22 +200,23 @@ func TestCarbon_ToUtcString(t *testing.T) { assert := assert.New(t) tests := []struct { + id int // 测试id input string // 输入值 output string // 期望输出值 }{ - {"", ""}, - {"0", ""}, - {"0000-00-00", ""}, - {"00:00:00", ""}, - {"0000-00-00 00:00:00", ""}, + {1, "", ""}, + {2, "0", ""}, + {3, "0000-00-00", ""}, + {4, "00:00:00", ""}, + {5, "0000-00-00 00:00:00", ""}, - {"2020-08-05 13:14:15", "2020-08-05 05:14:15 +0000 UTC"}, + {6, "2020-08-05 13:14:15", "2020-08-05 05:14:15 +0000 UTC"}, } for _, test := range tests { c := Parse(test.input) assert.Nil(c.Error) - assert.Equal(c.ToUtcString(), test.output) + assert.Equal(c.ToUtcString(), test.output, "Current test id is "+strconv.Itoa(test.id)) } } @@ -214,33 +224,34 @@ func TestCarbon_ToMonthString1(t *testing.T) { assert := assert.New(t) tests := []struct { + id int // 测试id input string // 输入值 output 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"}, + {1, "", ""}, + {2, "0", ""}, + {3, "0000-00-00", ""}, + {4, "00:00:00", ""}, + {5, "0000-00-00 00:00:00", ""}, + + {6, "2020-01-05", "January"}, + {7, "2020-02-05", "February"}, + {8, "2020-03-05", "March"}, + {9, "2020-04-05", "April"}, + {10, "2020-05-05", "May"}, + {11, "2020-06-05", "June"}, + {12, "2020-07-05", "July"}, + {13, "2020-08-05", "August"}, + {14, "2020-09-05", "September"}, + {15, "2020-10-05", "October"}, + {16, "2020-11-05", "November"}, + {17, "2020-12-05", "December"}, } for _, test := range tests { c := Parse(test.input) assert.Nil(c.Error) - assert.Equal(c.ToMonthString(), test.output) + assert.Equal(c.ToMonthString(), test.output, "Current test id is "+strconv.Itoa(test.id)) } } @@ -248,28 +259,29 @@ func TestCarbon_ToMonthString2(t *testing.T) { assert := assert.New(t) tests := []struct { + id int // 测试id input string // 输入值 param string // 参数值 output string // 期望输出值 }{ - {"", "en", ""}, - {"0", "en", ""}, - {"0000-00-00", "en", ""}, - {"00:00:00", "en", ""}, - {"0000-00-00 00:00:00", "en", ""}, + {1, "", "en", ""}, + {2, "0", "en", ""}, + {3, "0000-00-00", "en", ""}, + {4, "00:00:00", "en", ""}, + {5, "0000-00-00 00:00:00", "en", ""}, - {"2020-08-05", "en", "August"}, - {"2020-08-05", "zh-CN", "八月"}, - {"2020-08-05", "zh-Tw", "八月"}, - {"2020-08-05", "jp", "はちがつ"}, - {"2020-08-05", "kr", "팔월"}, - {"2020-08-05", "xx", ""}, + {6, "2020-08-05", "en", "August"}, + {7, "2020-08-05", "zh-CN", "八月"}, + {8, "2020-08-05", "zh-Tw", "八月"}, + {9, "2020-08-05", "jp", "はちがつ"}, + {10, "2020-08-05", "kr", "팔월"}, + {11, "2020-08-05", "xx", ""}, } for _, test := range tests { c := Parse(test.input) assert.Nil(c.Error) - assert.Equal(c.SetLocale(test.param).ToMonthString(), test.output) + assert.Equal(c.SetLocale(test.param).ToMonthString(), test.output, "Current test id is "+strconv.Itoa(test.id)) } } @@ -277,33 +289,34 @@ func TestCarbon_ToShortMonthString1(t *testing.T) { assert := assert.New(t) tests := []struct { + id int // 测试id input string // 输入值 output 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"}, + {1, "", ""}, + {2, "0", ""}, + {3, "0000-00-00", ""}, + {4, "00:00:00", ""}, + {5, "0000-00-00 00:00:00", ""}, + + {6, "2020-01-05", "Jan"}, + {7, "2020-02-05", "Feb"}, + {8, "2020-03-05", "Mar"}, + {9, "2020-04-05", "Apr"}, + {10, "2020-05-05", "May"}, + {11, "2020-06-05", "Jun"}, + {12, "2020-07-05", "Jul"}, + {13, "2020-08-05", "Aug"}, + {14, "2020-09-05", "Sep"}, + {15, "2020-10-05", "Oct"}, + {16, "2020-11-05", "Nov"}, + {17, "2020-12-05", "Dec"}, } for _, test := range tests { c := Parse(test.input) assert.Nil(c.Error) - assert.Equal(c.ToShortMonthString(), test.output) + assert.Equal(c.ToShortMonthString(), test.output, "Current test id is "+strconv.Itoa(test.id)) } } @@ -311,28 +324,29 @@ func TestCarbon_ToShortMonthString2(t *testing.T) { assert := assert.New(t) tests := []struct { + id int // 测试id input string // 输入值 param string // 参数值 output string // 期望输出值 }{ - {"", "en", ""}, - {"0", "en", ""}, - {"0000-00-00", "en", ""}, - {"00:00:00", "en", ""}, - {"0000-00-00 00:00:00", "en", ""}, + {1, "", "en", ""}, + {2, "0", "en", ""}, + {3, "0000-00-00", "en", ""}, + {4, "00:00:00", "en", ""}, + {5, "0000-00-00 00:00:00", "en", ""}, - {"2020-08-05", "en", "Aug"}, - {"2020-08-05", "zh-CN", "8月"}, - {"2020-08-05", "zh-Tw", "8月"}, - {"2020-08-05", "jp", "8がつ"}, - {"2020-08-05", "kr", "8월"}, - {"2020-08-05", "xx", ""}, + {6, "2020-08-05", "en", "Aug"}, + {7, "2020-08-05", "zh-CN", "8月"}, + {8, "2020-08-05", "zh-Tw", "8月"}, + {9, "2020-08-05", "jp", "8がつ"}, + {10, "2020-08-05", "kr", "8월"}, + {11, "2020-08-05", "xx", ""}, } for _, test := range tests { c := Parse(test.input) assert.Nil(c.Error) - assert.Equal(c.SetLocale(test.param).ToShortMonthString(), test.output) + assert.Equal(c.SetLocale(test.param).ToShortMonthString(), test.output, "Current test id is "+strconv.Itoa(test.id)) } } @@ -340,28 +354,29 @@ func TestCarbon_ToWeekString1(t *testing.T) { assert := assert.New(t) tests := []struct { + id int // 测试id input string // 输入值 output string // 期望输出值 }{ - {"", ""}, - {"0", ""}, - {"0000-00-00", ""}, - {"00:00:00", ""}, - {"0000-00-00 00:00:00", ""}, + {1, "", ""}, + {2, "0", ""}, + {3, "0000-00-00", ""}, + {4, "00:00:00", ""}, + {5, "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"}, + {6, "2020-08-01", "Saturday"}, + {7, "2020-08-02", "Sunday"}, + {8, "2020-08-03", "Monday"}, + {9, "2020-08-04", "Tuesday"}, + {10, "2020-08-05", "Wednesday"}, + {11, "2020-08-06", "Thursday"}, + {12, "2020-08-07", "Friday"}, } for _, test := range tests { c := Parse(test.input) assert.Nil(c.Error) - assert.Equal(c.ToWeekString(), test.output) + assert.Equal(c.ToWeekString(), test.output, "Current test id is "+strconv.Itoa(test.id)) } } @@ -369,28 +384,29 @@ func TestCarbon_ToWeekString2(t *testing.T) { assert := assert.New(t) tests := []struct { + id int // 测试id input string // 输入值 param string // 参数值 output string // 期望输出值 }{ - {"", "en", ""}, - {"0", "en", ""}, - {"0000-00-00", "en", ""}, - {"00:00:00", "en", ""}, - {"0000-00-00 00:00:00", "en", ""}, + {1, "", "en", ""}, + {2, "0", "en", ""}, + {3, "0000-00-00", "en", ""}, + {4, "00:00:00", "en", ""}, + {5, "0000-00-00 00:00:00", "en", ""}, - {"2020-08-05", "en", "Wednesday"}, - {"2020-08-05", "zh-CN", "星期三"}, - {"2020-08-05", "zh-Tw", "星期三"}, - {"2020-08-05", "jp", "もくようび"}, - {"2020-08-05", "kr", "수요일"}, - {"2020-08-05", "xx", ""}, + {6, "2020-08-05", "en", "Wednesday"}, + {7, "2020-08-05", "zh-CN", "星期三"}, + {8, "2020-08-05", "zh-Tw", "星期三"}, + {9, "2020-08-05", "jp", "もくようび"}, + {10, "2020-08-05", "kr", "수요일"}, + {11, "2020-08-05", "xx", ""}, } for _, test := range tests { c := Parse(test.input) assert.Nil(c.Error) - assert.Equal(c.SetLocale(test.param).ToWeekString(), test.output) + assert.Equal(c.SetLocale(test.param).ToWeekString(), test.output, "Current test id is "+strconv.Itoa(test.id)) } } @@ -398,28 +414,29 @@ func TestCarbon_ToShortWeekString1(t *testing.T) { assert := assert.New(t) tests := []struct { + id int // 测试id input string // 输入值 output string // 期望输出值 }{ - {"", ""}, - {"0", ""}, - {"0000-00-00", ""}, - {"00:00:00", ""}, - {"0000-00-00 00:00:00", ""}, + {1, "", ""}, + {2, "0", ""}, + {3, "0000-00-00", ""}, + {4, "00:00:00", ""}, + {5, "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"}, + {6, "2020-08-01", "Sat"}, + {7, "2020-08-02", "Sun"}, + {8, "2020-08-03", "Mon"}, + {9, "2020-08-04", "Tue"}, + {10, "2020-08-05", "Wed"}, + {11, "2020-08-06", "Thu"}, + {12, "2020-08-07", "Fri"}, } for _, test := range tests { c := Parse(test.input) assert.Nil(c.Error) - assert.Equal(c.ToShortWeekString(), test.output) + assert.Equal(c.ToShortWeekString(), test.output, "Current test id is "+strconv.Itoa(test.id)) } } @@ -427,28 +444,29 @@ func TestCarbon_ToShortWeekString2(t *testing.T) { assert := assert.New(t) tests := []struct { + id int // 测试id input string // 输入值 param string // 参数值 output string // 期望输出值 }{ - {"", "en", ""}, - {"0", "en", ""}, - {"0000-00-00", "en", ""}, - {"00:00:00", "en", ""}, - {"0000-00-00 00:00:00", "en", ""}, + {1, "", "en", ""}, + {2, "0", "en", ""}, + {3, "0000-00-00", "en", ""}, + {4, "00:00:00", "en", ""}, + {5, "0000-00-00 00:00:00", "en", ""}, - {"2020-08-05", "en", "Wed"}, - {"2020-08-05", "zh-CN", "周三"}, - {"2020-08-05", "zh-Tw", "週三"}, - {"2020-08-05", "jp", "週三"}, - {"2020-08-05", "kr", "수요일"}, - {"2020-08-05", "xx", ""}, + {6, "2020-08-05", "en", "Wed"}, + {7, "2020-08-05", "zh-CN", "周三"}, + {8, "2020-08-05", "zh-Tw", "週三"}, + {9, "2020-08-05", "jp", "週三"}, + {10, "2020-08-05", "kr", "수요일"}, + {11, "2020-08-05", "xx", ""}, } for _, test := range tests { c := Parse(test.input) assert.Nil(c.Error) - assert.Equal(c.SetLocale(test.param).ToShortWeekString(), test.output) + assert.Equal(c.SetLocale(test.param).ToShortWeekString(), test.output, "Current test id is "+strconv.Itoa(test.id)) } } @@ -456,44 +474,45 @@ func TestCarbon_ToFormatString(t *testing.T) { assert := assert.New(t) tests := []struct { + id int // 测试id input string // 输入值 param string // 参数值 output 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", "Local"}, - {"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"}, + {1, "", "Y年m月d日", ""}, + {2, "0", "Y年m月d日", ""}, + {3, "0000-00-00", "Y年m月d日", ""}, + {4, "00:00:00", "Y年m月d日", ""}, + {5, "0000-00-00 00:00:00", "Y年m月d日", ""}, + + {6, "2020-08-05 13:14:15", "Y年m月d日", "2020年08月05日"}, + {7, "2020-08-05 01:14:15", "j", "5"}, + {8, "2020-08-05 01:14:15", "W", "32"}, + {9, "2020-08-05 01:14:15", "M", "Aug"}, + {10, "2020-08-05 01:14:15", "F", "August"}, + {11, "2020-08-05 01:14:15", "N", "3"}, + {12, "2020-08-05 01:14:15", "L", "1"}, + {13, "2020-08-05 01:14:15", "L", "1"}, + {14, "2021-08-05 01:14:15", "L", "0"}, + {15, "2020-08-05 01:14:15", "G", "1"}, + {16, "2020-08-05 13:14:15", "U", "1596604455"}, + {17, "2020-08-05 13:14:15.999", "u", "999"}, + {18, "2020-08-05 13:14:15", "w", "2"}, + {19, "2020-08-05 13:14:15", "t", "31"}, + {20, "2020-08-05 13:14:15", "z", "217"}, + {21, "2020-08-05 13:14:15", "e", "Local"}, + {22, "2020-08-05 13:14:15", "jS", "5th"}, + {23, "2020-08-22 13:14:15", "jS", "22nd"}, + {24, "2020-08-23 13:14:15", "jS", "23rd"}, + {25, "2020-08-31 13:14:15", "jS", "31st"}, + {26, "2020-08-31 13:14:15", "I\\t \\i\\s Y-m-d H:i:s", "It is 2020-08-31 13:14:15"}, + {27, "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 _, test := range tests { c := Parse(test.input) assert.Nil(c.Error) - assert.Equal(c.ToFormatString(test.param), test.output) + assert.Equal(c.ToFormatString(test.param), test.output, "Current test id is "+strconv.Itoa(test.id)) } } @@ -501,44 +520,45 @@ func TestCarbon_Format(t *testing.T) { assert := assert.New(t) tests := []struct { + id int // 测试id input string // 输入值 param string // 参数值 output 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", "Local"}, - {"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"}, + {1, "", "Y年m月d日", ""}, + {2, "0", "Y年m月d日", ""}, + {3, "0000-00-00", "Y年m月d日", ""}, + {4, "00:00:00", "Y年m月d日", ""}, + {5, "0000-00-00 00:00:00", "Y年m月d日", ""}, + + {6, "2020-08-05 13:14:15", "Y年m月d日", "2020年08月05日"}, + {7, "2020-08-05 01:14:15", "j", "5"}, + {8, "2020-08-05 01:14:15", "W", "32"}, + {9, "2020-08-05 01:14:15", "M", "Aug"}, + {10, "2020-08-05 01:14:15", "F", "August"}, + {11, "2020-08-05 01:14:15", "N", "3"}, + {12, "2020-08-05 01:14:15", "L", "1"}, + {13, "2020-08-05 01:14:15", "L", "1"}, + {14, "2021-08-05 01:14:15", "L", "0"}, + {15, "2020-08-05 01:14:15", "G", "1"}, + {16, "2020-08-05 13:14:15", "U", "1596604455"}, + {17, "2020-08-05 13:14:15.999", "u", "999"}, + {18, "2020-08-05 13:14:15", "w", "2"}, + {19, "2020-08-05 13:14:15", "t", "31"}, + {20, "2020-08-05 13:14:15", "z", "217"}, + {21, "2020-08-05 13:14:15", "e", "Local"}, + {22, "2020-08-05 13:14:15", "jS", "5th"}, + {23, "2020-08-22 13:14:15", "jS", "22nd"}, + {24, "2020-08-23 13:14:15", "jS", "23rd"}, + {25, "2020-08-31 13:14:15", "jS", "31st"}, + {26, "2020-08-31 13:14:15", "I\\t \\i\\s Y-m-d H:i:s", "It is 2020-08-31 13:14:15"}, + {27, "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 _, test := range tests { c := Parse(test.input) assert.Nil(c.Error) - assert.Equal(c.Format(test.param), test.output) + assert.Equal(c.Format(test.param), test.output, "Current test id is "+strconv.Itoa(test.id)) } } @@ -546,22 +566,23 @@ func TestCarbon_ToDayDateTimeString(t *testing.T) { assert := assert.New(t) tests := []struct { + id int // 测试id input string // 输入值 output string // 期望输出值 }{ - {"", ""}, - {"0", ""}, - {"0000-00-00", ""}, - {"00:00:00", ""}, - {"0000-00-00 00:00:00", ""}, + {1, "", ""}, + {2, "0", ""}, + {3, "0000-00-00", ""}, + {4, "00:00:00", ""}, + {5, "0000-00-00 00:00:00", ""}, - {"2020-08-05 13:14:15", "Wed, Aug 5, 2020 1:14 PM"}, + {6, "2020-08-05 13:14:15", "Wed, Aug 5, 2020 1:14 PM"}, } for _, test := range tests { c := Parse(test.input) assert.Nil(c.Error) - assert.Equal(c.ToDayDateTimeString(), test.output) + assert.Equal(c.ToDayDateTimeString(), test.output, "Current test id is "+strconv.Itoa(test.id)) } } @@ -569,22 +590,23 @@ func TestCarbon_ToDayDateTimeStringWithTimezone(t *testing.T) { assert := assert.New(t) tests := []struct { + id int // 测试id input string // 输入值 output string // 期望输出值 }{ - {"", ""}, - {"0", ""}, - {"0000-00-00", ""}, - {"00:00:00", ""}, - {"0000-00-00 00:00:00", ""}, + {1, "", ""}, + {2, "0", ""}, + {3, "0000-00-00", ""}, + {4, "00:00:00", ""}, + {5, "0000-00-00 00:00:00", ""}, - {"2020-08-05 13:14:15", "Wed, Aug 5, 2020 5:14 AM"}, + {6, "2020-08-05 13:14:15", "Wed, Aug 5, 2020 5:14 AM"}, } for _, test := range tests { c := Parse(test.input) assert.Nil(c.Error) - assert.Equal(c.ToDayDateTimeStringWithTimezone(UTC), test.output) + assert.Equal(c.ToDayDateTimeStringWithTimezone(UTC), test.output, "Current test id is "+strconv.Itoa(test.id)) } } @@ -592,23 +614,24 @@ func TestCarbon_ToDateTimeString(t *testing.T) { assert := assert.New(t) tests := []struct { + id int // 测试id input string // 输入值 output string // 期望输出值 }{ - {"", ""}, - {"0", ""}, - {"0000-00-00", ""}, - {"00:00:00", ""}, - {"0000-00-00 00:00:00", ""}, + {1, "", ""}, + {2, "0", ""}, + {3, "0000-00-00", ""}, + {4, "00:00:00", ""}, + {5, "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"}, + {6, "2020-08-05 13:14:15", "2020-08-05 13:14:15"}, + {7, "2020-08-05", "2020-08-05 00:00:00"}, } for _, test := range tests { c := Parse(test.input) assert.Nil(c.Error) - assert.Equal(c.ToDateTimeString(), test.output) + assert.Equal(c.ToDateTimeString(), test.output, "Current test id is "+strconv.Itoa(test.id)) } } @@ -616,23 +639,24 @@ func TestCarbon_ToDateTimeStringWithTimezone(t *testing.T) { assert := assert.New(t) tests := []struct { + id int // 测试id input string // 输入值 output string // 期望输出值 }{ - {"", ""}, - {"0", ""}, - {"0000-00-00", ""}, - {"00:00:00", ""}, - {"0000-00-00 00:00:00", ""}, + {1, "", ""}, + {2, "0", ""}, + {3, "0000-00-00", ""}, + {4, "00:00:00", ""}, + {5, "0000-00-00 00:00:00", ""}, - {"2020-08-05 13:14:15", "2020-08-05 05:14:15"}, - {"2020-08-05", "2020-08-04 16:00:00"}, + {6, "2020-08-05 13:14:15", "2020-08-05 05:14:15"}, + {7, "2020-08-05", "2020-08-04 16:00:00"}, } for _, test := range tests { c := Parse(test.input) assert.Nil(c.Error) - assert.Equal(c.ToDateTimeStringWithTimezone(UTC), test.output) + assert.Equal(c.ToDateTimeStringWithTimezone(UTC), test.output, "Current test id is "+strconv.Itoa(test.id)) } } @@ -640,23 +664,24 @@ func TestCarbon_ToDateString(t *testing.T) { assert := assert.New(t) tests := []struct { + id int // 测试id input string // 输入值 output string // 期望输出值 }{ - {"", ""}, - {"0", ""}, - {"0000-00-00", ""}, - {"00:00:00", ""}, - {"0000-00-00 00:00:00", ""}, + {1, "", ""}, + {2, "0", ""}, + {3, "0000-00-00", ""}, + {4, "00:00:00", ""}, + {5, "0000-00-00 00:00:00", ""}, - {"2020-08-05 13:14:15", "2020-08-05"}, - {"2020-08-05", "2020-08-05"}, + {6, "2020-08-05 13:14:15", "2020-08-05"}, + {7, "2020-08-05", "2020-08-05"}, } for _, test := range tests { c := Parse(test.input) assert.Nil(c.Error) - assert.Equal(c.ToDateString(), test.output) + assert.Equal(c.ToDateString(), test.output, "Current test id is "+strconv.Itoa(test.id)) } } @@ -664,23 +689,24 @@ func TestCarbon_ToDateStringWithTimezone(t *testing.T) { assert := assert.New(t) tests := []struct { + id int // 测试id input string // 输入值 output string // 期望输出值 }{ - {"", ""}, - {"0", ""}, - {"0000-00-00", ""}, - {"00:00:00", ""}, - {"0000-00-00 00:00:00", ""}, + {1, "", ""}, + {2, "0", ""}, + {3, "0000-00-00", ""}, + {4, "00:00:00", ""}, + {5, "0000-00-00 00:00:00", ""}, - {"2020-08-05 13:14:15", "2020-08-05"}, - {"2020-08-05", "2020-08-04"}, + {6, "2020-08-05 13:14:15", "2020-08-05"}, + {7, "2020-08-05", "2020-08-04"}, } for _, test := range tests { c := Parse(test.input) assert.Nil(c.Error) - assert.Equal(c.ToDateStringWithTimezone(UTC), test.output) + assert.Equal(c.ToDateStringWithTimezone(UTC), test.output, "Current test id is "+strconv.Itoa(test.id)) } } @@ -688,23 +714,24 @@ func TestCarbon_ToTimeString(t *testing.T) { assert := assert.New(t) tests := []struct { + id int // 测试id input string // 输入值 output string // 期望输出值 }{ - {"", ""}, - {"0", ""}, - {"0000-00-00", ""}, - {"00:00:00", ""}, - {"0000-00-00 00:00:00", ""}, + {1, "", ""}, + {2, "0", ""}, + {3, "0000-00-00", ""}, + {4, "00:00:00", ""}, + {5, "0000-00-00 00:00:00", ""}, - {"2020-08-05 13:14:15", "13:14:15"}, - {"2020-08-05", "00:00:00"}, + {6, "2020-08-05 13:14:15", "13:14:15"}, + {7, "2020-08-05", "00:00:00"}, } for _, test := range tests { c := Parse(test.input) assert.Nil(c.Error) - assert.Equal(c.ToTimeString(), test.output) + assert.Equal(c.ToTimeString(), test.output, "Current test id is "+strconv.Itoa(test.id)) } } @@ -712,23 +739,24 @@ func TestCarbon_ToTimeStringWithTimezone(t *testing.T) { assert := assert.New(t) tests := []struct { + id int // 测试id input string // 输入值 output string // 期望输出值 }{ - {"", ""}, - {"0", ""}, - {"0000-00-00", ""}, - {"00:00:00", ""}, - {"0000-00-00 00:00:00", ""}, + {1, "", ""}, + {2, "0", ""}, + {3, "0000-00-00", ""}, + {4, "00:00:00", ""}, + {5, "0000-00-00 00:00:00", ""}, - {"2020-08-05 13:14:15", "05:14:15"}, - {"2020-08-05", "16:00:00"}, + {6, "2020-08-05 13:14:15", "05:14:15"}, + {7, "2020-08-05", "16:00:00"}, } for _, test := range tests { c := Parse(test.input) assert.Nil(c.Error) - assert.Equal(c.ToTimeStringWithTimezone(UTC), test.output) + assert.Equal(c.ToTimeStringWithTimezone(UTC), test.output, "Current test id is "+strconv.Itoa(test.id)) } } @@ -736,23 +764,24 @@ func TestCarbon_ToAtomString(t *testing.T) { assert := assert.New(t) tests := []struct { + id int // 测试id input string // 输入值 output string // 期望输出值 }{ - {"", ""}, - {"0", ""}, - {"0000-00-00", ""}, - {"00:00:00", ""}, - {"0000-00-00 00:00:00", ""}, + {1, "", ""}, + {2, "0", ""}, + {3, "0000-00-00", ""}, + {4, "00:00:00", ""}, + {5, "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"}, + {6, "2020-08-05 13:14:15", "2020-08-05T13:14:15+08:00"}, + {7, "2020-08-05", "2020-08-05T00:00:00+08:00"}, } for _, test := range tests { c := Parse(test.input) assert.Nil(c.Error) - assert.Equal(c.ToAtomString(), test.output) + assert.Equal(c.ToAtomString(), test.output, "Current test id is "+strconv.Itoa(test.id)) } } @@ -760,23 +789,24 @@ func TestCarbon_ToAtomStringWithTimezone(t *testing.T) { assert := assert.New(t) tests := []struct { + id int // 测试id input string // 输入值 output string // 期望输出值 }{ - {"", ""}, - {"0", ""}, - {"0000-00-00", ""}, - {"00:00:00", ""}, - {"0000-00-00 00:00:00", ""}, + {1, "", ""}, + {2, "0", ""}, + {3, "0000-00-00", ""}, + {4, "00:00:00", ""}, + {5, "0000-00-00 00:00:00", ""}, - {"2020-08-05 13:14:15", "2020-08-05T05:14:15Z"}, - {"2020-08-05", "2020-08-04T16:00:00Z"}, + {6, "2020-08-05 13:14:15", "2020-08-05T05:14:15Z"}, + {7, "2020-08-05", "2020-08-04T16:00:00Z"}, } for _, test := range tests { c := Parse(test.input) assert.Nil(c.Error) - assert.Equal(c.ToAtomStringWithTimezone(UTC), test.output) + assert.Equal(c.ToAtomStringWithTimezone(UTC), test.output, "Current test id is "+strconv.Itoa(test.id)) } } @@ -784,23 +814,24 @@ func TestCarbon_ToAnsicString(t *testing.T) { assert := assert.New(t) tests := []struct { + id int // 测试id input string // 输入值 output string // 期望输出值 }{ - {"", ""}, - {"0", ""}, - {"0000-00-00", ""}, - {"00:00:00", ""}, - {"0000-00-00 00:00:00", ""}, + {1, "", ""}, + {2, "0", ""}, + {3, "0000-00-00", ""}, + {4, "00:00:00", ""}, + {5, "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"}, + {6, "2020-08-05 13:14:15", "Wed Aug 5 13:14:15 2020"}, + {7, "2020-08-05", "Wed Aug 5 00:00:00 2020"}, } for _, test := range tests { c := Parse(test.input) assert.Nil(c.Error) - assert.Equal(c.ToAnsicString(), test.output) + assert.Equal(c.ToAnsicString(), test.output, "Current test id is "+strconv.Itoa(test.id)) } } @@ -808,23 +839,24 @@ func TestCarbon_ToAnsicStringWithTimezone(t *testing.T) { assert := assert.New(t) tests := []struct { + id int // 测试id input string // 输入值 output string // 期望输出值 }{ - {"", ""}, - {"0", ""}, - {"0000-00-00", ""}, - {"00:00:00", ""}, - {"0000-00-00 00:00:00", ""}, + {1, "", ""}, + {2, "0", ""}, + {3, "0000-00-00", ""}, + {4, "00:00:00", ""}, + {5, "0000-00-00 00:00:00", ""}, - {"2020-08-05 13:14:15", "Wed Aug 5 05:14:15 2020"}, - {"2020-08-05", "Tue Aug 4 16:00:00 2020"}, + {6, "2020-08-05 13:14:15", "Wed Aug 5 05:14:15 2020"}, + {7, "2020-08-05", "Tue Aug 4 16:00:00 2020"}, } for _, test := range tests { c := Parse(test.input) assert.Nil(c.Error) - assert.Equal(c.ToAnsicStringWithTimezone(UTC), test.output) + assert.Equal(c.ToAnsicStringWithTimezone(UTC), test.output, "Current test id is "+strconv.Itoa(test.id)) } } @@ -832,23 +864,24 @@ func TestCarbon_ToCookieString(t *testing.T) { assert := assert.New(t) tests := []struct { + id int // 测试id input string // 输入值 output string // 期望输出值 }{ - {"", ""}, - {"0", ""}, - {"0000-00-00", ""}, - {"00:00:00", ""}, - {"0000-00-00 00:00:00", ""}, + {1, "", ""}, + {2, "0", ""}, + {3, "0000-00-00", ""}, + {4, "00:00:00", ""}, + {5, "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"}, + {6, "2020-08-05 13:14:15", "Wednesday, 05-Aug-2020 13:14:15 CST"}, + {7, "2020-08-05", "Wednesday, 05-Aug-2020 00:00:00 CST"}, } for _, test := range tests { c := Parse(test.input) assert.Nil(c.Error) - assert.Equal(c.ToCookieString(), test.output) + assert.Equal(c.ToCookieString(), test.output, "Current test id is "+strconv.Itoa(test.id)) } } @@ -856,23 +889,24 @@ func TestCarbon_ToCookieStringWithTimezone(t *testing.T) { assert := assert.New(t) tests := []struct { + id int // 测试id input string // 输入值 output string // 期望输出值 }{ - {"", ""}, - {"0", ""}, - {"0000-00-00", ""}, - {"00:00:00", ""}, - {"0000-00-00 00:00:00", ""}, + {1, "", ""}, + {2, "0", ""}, + {3, "0000-00-00", ""}, + {4, "00:00:00", ""}, + {5, "0000-00-00 00:00:00", ""}, - {"2020-08-05 13:14:15", "Wednesday, 05-Aug-2020 05:14:15 UTC"}, - {"2020-08-05", "Tuesday, 04-Aug-2020 16:00:00 UTC"}, + {6, "2020-08-05 13:14:15", "Wednesday, 05-Aug-2020 05:14:15 UTC"}, + {7, "2020-08-05", "Tuesday, 04-Aug-2020 16:00:00 UTC"}, } for _, test := range tests { c := Parse(test.input) assert.Nil(c.Error) - assert.Equal(c.ToCookieStringWithTimezone(UTC), test.output) + assert.Equal(c.ToCookieStringWithTimezone(UTC), test.output, "Current test id is "+strconv.Itoa(test.id)) } } @@ -880,23 +914,24 @@ func TestCarbon_ToRssString(t *testing.T) { assert := assert.New(t) tests := []struct { + id int // 测试id input string // 输入值 output string // 期望输出值 }{ - {"", ""}, - {"0", ""}, - {"0000-00-00", ""}, - {"00:00:00", ""}, - {"0000-00-00 00:00:00", ""}, + {1, "", ""}, + {2, "0", ""}, + {3, "0000-00-00", ""}, + {4, "00:00:00", ""}, + {5, "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"}, + {6, "2020-08-05 13:14:15", "Wed, 05 Aug 2020 13:14:15 +0800"}, + {7, "2020-08-05", "Wed, 05 Aug 2020 00:00:00 +0800"}, } for _, test := range tests { c := Parse(test.input) assert.Nil(c.Error) - assert.Equal(c.ToRssString(), test.output) + assert.Equal(c.ToRssString(), test.output, "Current test id is "+strconv.Itoa(test.id)) } } @@ -904,23 +939,24 @@ func TestCarbon_ToRssStringWithTimezone(t *testing.T) { assert := assert.New(t) tests := []struct { + id int // 测试id input string // 输入值 output string // 期望输出值 }{ - {"", ""}, - {"0", ""}, - {"0000-00-00", ""}, - {"00:00:00", ""}, - {"0000-00-00 00:00:00", ""}, + {1, "", ""}, + {2, "0", ""}, + {3, "0000-00-00", ""}, + {4, "00:00:00", ""}, + {5, "0000-00-00 00:00:00", ""}, - {"2020-08-05 13:14:15", "Wed, 05 Aug 2020 05:14:15 +0000"}, - {"2020-08-05", "Tue, 04 Aug 2020 16:00:00 +0000"}, + {6, "2020-08-05 13:14:15", "Wed, 05 Aug 2020 05:14:15 +0000"}, + {7, "2020-08-05", "Tue, 04 Aug 2020 16:00:00 +0000"}, } for _, test := range tests { c := Parse(test.input) assert.Nil(c.Error) - assert.Equal(c.ToRssStringWithTimezone(UTC), test.output) + assert.Equal(c.ToRssStringWithTimezone(UTC), test.output, "Current test id is "+strconv.Itoa(test.id)) } } @@ -928,23 +964,24 @@ func TestCarbon_ToW3cString(t *testing.T) { assert := assert.New(t) tests := []struct { + id int // 测试id input string // 输入值 output string // 期望输出值 }{ - {"", ""}, - {"0", ""}, - {"0000-00-00", ""}, - {"00:00:00", ""}, - {"0000-00-00 00:00:00", ""}, + {1, "", ""}, + {2, "0", ""}, + {3, "0000-00-00", ""}, + {4, "00:00:00", ""}, + {5, "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"}, + {6, "2020-08-05 13:14:15", "2020-08-05T13:14:15+08:00"}, + {7, "2020-08-05", "2020-08-05T00:00:00+08:00"}, } for _, test := range tests { c := Parse(test.input) assert.Nil(c.Error) - assert.Equal(c.ToW3cString(), test.output) + assert.Equal(c.ToW3cString(), test.output, "Current test id is "+strconv.Itoa(test.id)) } } @@ -952,23 +989,24 @@ func TestCarbon_ToW3cStringWithTimezone(t *testing.T) { assert := assert.New(t) tests := []struct { + id int // 测试id input string // 输入值 output string // 期望输出值 }{ - {"", ""}, - {"0", ""}, - {"0000-00-00", ""}, - {"00:00:00", ""}, - {"0000-00-00 00:00:00", ""}, + {1, "", ""}, + {2, "0", ""}, + {3, "0000-00-00", ""}, + {4, "00:00:00", ""}, + {5, "0000-00-00 00:00:00", ""}, - {"2020-08-05 13:14:15", "2020-08-05T05:14:15Z"}, - {"2020-08-05", "2020-08-04T16:00:00Z"}, + {6, "2020-08-05 13:14:15", "2020-08-05T05:14:15Z"}, + {7, "2020-08-05", "2020-08-04T16:00:00Z"}, } for _, test := range tests { c := Parse(test.input) assert.Nil(c.Error) - assert.Equal(c.ToW3cStringWithTimezone(UTC), test.output) + assert.Equal(c.ToW3cStringWithTimezone(UTC), test.output, "Current test id is "+strconv.Itoa(test.id)) } } @@ -976,23 +1014,24 @@ func TestCarbon_ToUnixDateString(t *testing.T) { assert := assert.New(t) tests := []struct { + id int // 测试id input string // 输入值 output string // 期望输出值 }{ - {"", ""}, - {"0", ""}, - {"0000-00-00", ""}, - {"00:00:00", ""}, - {"0000-00-00 00:00:00", ""}, + {1, "", ""}, + {2, "0", ""}, + {3, "0000-00-00", ""}, + {4, "00:00:00", ""}, + {5, "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"}, + {6, "2020-08-05 13:14:15", "Wed Aug 5 13:14:15 CST 2020"}, + {7, "2020-08-05", "Wed Aug 5 00:00:00 CST 2020"}, } for _, test := range tests { c := Parse(test.input) assert.Nil(c.Error) - assert.Equal(c.ToUnixDateString(), test.output) + assert.Equal(c.ToUnixDateString(), test.output, "Current test id is "+strconv.Itoa(test.id)) } } @@ -1000,23 +1039,24 @@ func TestCarbon_ToUnixDateStringWithTimezone(t *testing.T) { assert := assert.New(t) tests := []struct { + id int // 测试id input string // 输入值 output string // 期望输出值 }{ - {"", ""}, - {"0", ""}, - {"0000-00-00", ""}, - {"00:00:00", ""}, - {"0000-00-00 00:00:00", ""}, + {1, "", ""}, + {2, "0", ""}, + {3, "0000-00-00", ""}, + {4, "00:00:00", ""}, + {5, "0000-00-00 00:00:00", ""}, - {"2020-08-05 13:14:15", "Wed Aug 5 05:14:15 UTC 2020"}, - {"2020-08-05", "Tue Aug 4 16:00:00 UTC 2020"}, + {6, "2020-08-05 13:14:15", "Wed Aug 5 05:14:15 UTC 2020"}, + {7, "2020-08-05", "Tue Aug 4 16:00:00 UTC 2020"}, } for _, test := range tests { c := Parse(test.input) assert.Nil(c.Error) - assert.Equal(c.ToUnixDateStringWithTimezone(UTC), test.output) + assert.Equal(c.ToUnixDateStringWithTimezone(UTC), test.output, "Current test id is "+strconv.Itoa(test.id)) } } @@ -1024,23 +1064,24 @@ func TestCarbon_ToRubyDateString(t *testing.T) { assert := assert.New(t) tests := []struct { + id int // 测试id input string // 输入值 output string // 期望输出值 }{ - {"", ""}, - {"0", ""}, - {"0000-00-00", ""}, - {"00:00:00", ""}, - {"0000-00-00 00:00:00", ""}, + {1, "", ""}, + {2, "0", ""}, + {3, "0000-00-00", ""}, + {4, "00:00:00", ""}, + {5, "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"}, + {6, "2020-08-05 13:14:15", "Wed Aug 05 13:14:15 +0800 2020"}, + {7, "2020-08-05", "Wed Aug 05 00:00:00 +0800 2020"}, } for _, test := range tests { c := Parse(test.input) assert.Nil(c.Error) - assert.Equal(c.ToRubyDateString(), test.output) + assert.Equal(c.ToRubyDateString(), test.output, "Current test id is "+strconv.Itoa(test.id)) } } @@ -1048,23 +1089,24 @@ func TestCarbon_ToRubyDateStringWithTimezone(t *testing.T) { assert := assert.New(t) tests := []struct { + id int // 测试id input string // 输入值 output string // 期望输出值 }{ - {"", ""}, - {"0", ""}, - {"0000-00-00", ""}, - {"00:00:00", ""}, - {"0000-00-00 00:00:00", ""}, + {1, "", ""}, + {2, "0", ""}, + {3, "0000-00-00", ""}, + {4, "00:00:00", ""}, + {5, "0000-00-00 00:00:00", ""}, - {"2020-08-05 13:14:15", "Wed Aug 05 05:14:15 +0000 2020"}, - {"2020-08-05", "Tue Aug 04 16:00:00 +0000 2020"}, + {6, "2020-08-05 13:14:15", "Wed Aug 05 05:14:15 +0000 2020"}, + {7, "2020-08-05", "Tue Aug 04 16:00:00 +0000 2020"}, } for _, test := range tests { c := Parse(test.input) assert.Nil(c.Error) - assert.Equal(c.ToRubyDateStringWithTimezone(UTC), test.output) + assert.Equal(c.ToRubyDateStringWithTimezone(UTC), test.output, "Current test id is "+strconv.Itoa(test.id)) } } @@ -1072,23 +1114,24 @@ func TestCarbon_ToKitchenString(t *testing.T) { assert := assert.New(t) tests := []struct { + id int // 测试id input string // 输入值 output string // 期望输出值 }{ - {"", ""}, - {"0", ""}, - {"0000-00-00", ""}, - {"00:00:00", ""}, - {"0000-00-00 00:00:00", ""}, + {1, "", ""}, + {2, "0", ""}, + {3, "0000-00-00", ""}, + {4, "00:00:00", ""}, + {5, "0000-00-00 00:00:00", ""}, - {"2020-08-05 13:14:15", "1:14PM"}, - {"2020-08-05", "12:00AM"}, + {6, "2020-08-05 13:14:15", "1:14PM"}, + {7, "2020-08-05", "12:00AM"}, } for _, test := range tests { c := Parse(test.input) assert.Nil(c.Error) - assert.Equal(c.ToKitchenString(), test.output) + assert.Equal(c.ToKitchenString(), test.output, "Current test id is "+strconv.Itoa(test.id)) } } @@ -1096,23 +1139,24 @@ func TestCarbon_ToKitchenStringWithTimezone(t *testing.T) { assert := assert.New(t) tests := []struct { + id int // 测试id input string // 输入值 output string // 期望输出值 }{ - {"", ""}, - {"0", ""}, - {"0000-00-00", ""}, - {"00:00:00", ""}, - {"0000-00-00 00:00:00", ""}, + {1, "", ""}, + {2, "0", ""}, + {3, "0000-00-00", ""}, + {4, "00:00:00", ""}, + {5, "0000-00-00 00:00:00", ""}, - {"2020-08-05 13:14:15", "5:14AM"}, - {"2020-08-05", "4:00PM"}, + {6, "2020-08-05 13:14:15", "5:14AM"}, + {7, "2020-08-05", "4:00PM"}, } for _, test := range tests { c := Parse(test.input) assert.Nil(c.Error) - assert.Equal(c.ToKitchenStringWithTimezone(UTC), test.output) + assert.Equal(c.ToKitchenStringWithTimezone(UTC), test.output, "Current test id is "+strconv.Itoa(test.id)) } } @@ -1120,23 +1164,24 @@ func TestCarbon_ToRfc822String(t *testing.T) { assert := assert.New(t) tests := []struct { + id int // 测试id input string // 输入值 output string // 期望输出值 }{ - {"", ""}, - {"0", ""}, - {"0000-00-00", ""}, - {"00:00:00", ""}, - {"0000-00-00 00:00:00", ""}, + {1, "", ""}, + {2, "0", ""}, + {3, "0000-00-00", ""}, + {4, "00:00:00", ""}, + {5, "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"}, + {6, "2020-08-05 13:14:15", "05 Aug 20 13:14 CST"}, + {7, "2020-08-05", "05 Aug 20 00:00 CST"}, } for _, test := range tests { c := Parse(test.input) assert.Nil(c.Error) - assert.Equal(c.ToRfc822String(), test.output) + assert.Equal(c.ToRfc822String(), test.output, "Current test id is "+strconv.Itoa(test.id)) } } @@ -1144,23 +1189,24 @@ func TestCarbon_ToRfc822StringWithTimezone(t *testing.T) { assert := assert.New(t) tests := []struct { + id int // 测试id input string // 输入值 output string // 期望输出值 }{ - {"", ""}, - {"0", ""}, - {"0000-00-00", ""}, - {"00:00:00", ""}, - {"0000-00-00 00:00:00", ""}, + {1, "", ""}, + {2, "0", ""}, + {3, "0000-00-00", ""}, + {4, "00:00:00", ""}, + {5, "0000-00-00 00:00:00", ""}, - {"2020-08-05 13:14:15", "05 Aug 20 05:14 UTC"}, - {"2020-08-05", "04 Aug 20 16:00 UTC"}, + {6, "2020-08-05 13:14:15", "05 Aug 20 05:14 UTC"}, + {7, "2020-08-05", "04 Aug 20 16:00 UTC"}, } for _, test := range tests { c := Parse(test.input) assert.Nil(c.Error) - assert.Equal(c.ToRfc822StringWithTimezone(UTC), test.output) + assert.Equal(c.ToRfc822StringWithTimezone(UTC), test.output, "Current test id is "+strconv.Itoa(test.id)) } } @@ -1168,23 +1214,24 @@ func TestCarbon_ToRfc822zString(t *testing.T) { assert := assert.New(t) tests := []struct { + id int // 测试id input string // 输入值 output string // 期望输出值 }{ - {"", ""}, - {"0", ""}, - {"0000-00-00", ""}, - {"00:00:00", ""}, - {"0000-00-00 00:00:00", ""}, + {1, "", ""}, + {2, "0", ""}, + {3, "0000-00-00", ""}, + {4, "00:00:00", ""}, + {5, "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"}, + {6, "2020-08-05 13:14:15", "05 Aug 20 13:14 +0800"}, + {7, "2020-08-05", "05 Aug 20 00:00 +0800"}, } for _, test := range tests { c := Parse(test.input) assert.Nil(c.Error) - assert.Equal(c.ToRfc822zString(), test.output) + assert.Equal(c.ToRfc822zString(), test.output, "Current test id is "+strconv.Itoa(test.id)) } } @@ -1192,23 +1239,24 @@ func TestCarbon_ToRfc822zStringWithTimezone(t *testing.T) { assert := assert.New(t) tests := []struct { + id int // 测试id input string // 输入值 output string // 期望输出值 }{ - {"", ""}, - {"0", ""}, - {"0000-00-00", ""}, - {"00:00:00", ""}, - {"0000-00-00 00:00:00", ""}, + {1, "", ""}, + {2, "0", ""}, + {3, "0000-00-00", ""}, + {4, "00:00:00", ""}, + {5, "0000-00-00 00:00:00", ""}, - {"2020-08-05 13:14:15", "05 Aug 20 05:14 +0000"}, - {"2020-08-05", "04 Aug 20 16:00 +0000"}, + {6, "2020-08-05 13:14:15", "05 Aug 20 05:14 +0000"}, + {7, "2020-08-05", "04 Aug 20 16:00 +0000"}, } for _, test := range tests { c := Parse(test.input) assert.Nil(c.Error) - assert.Equal(c.ToRfc822zStringWithTimezone(UTC), test.output) + assert.Equal(c.ToRfc822zStringWithTimezone(UTC), test.output, "Current test id is "+strconv.Itoa(test.id)) } } @@ -1216,23 +1264,24 @@ func TestCarbon_ToRfc850String(t *testing.T) { assert := assert.New(t) tests := []struct { + id int // 测试id input string // 输入值 output string // 期望输出值 }{ - {"", ""}, - {"0", ""}, - {"0000-00-00", ""}, - {"00:00:00", ""}, - {"0000-00-00 00:00:00", ""}, + {1, "", ""}, + {2, "0", ""}, + {3, "0000-00-00", ""}, + {4, "00:00:00", ""}, + {5, "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"}, + {6, "2020-08-05 13:14:15", "Wednesday, 05-Aug-20 13:14:15 CST"}, + {7, "2020-08-05", "Wednesday, 05-Aug-20 00:00:00 CST"}, } for _, test := range tests { c := Parse(test.input) assert.Nil(c.Error) - assert.Equal(c.ToRfc850String(), test.output) + assert.Equal(c.ToRfc850String(), test.output, "Current test id is "+strconv.Itoa(test.id)) } } @@ -1240,23 +1289,24 @@ func TestCarbon_ToRfc850StringWithTimezone(t *testing.T) { assert := assert.New(t) tests := []struct { + id int // 测试id input string // 输入值 output string // 期望输出值 }{ - {"", ""}, - {"0", ""}, - {"0000-00-00", ""}, - {"00:00:00", ""}, - {"0000-00-00 00:00:00", ""}, + {1, "", ""}, + {2, "0", ""}, + {3, "0000-00-00", ""}, + {4, "00:00:00", ""}, + {5, "0000-00-00 00:00:00", ""}, - {"2020-08-05 13:14:15", "Wednesday, 05-Aug-20 05:14:15 UTC"}, - {"2020-08-05", "Tuesday, 04-Aug-20 16:00:00 UTC"}, + {6, "2020-08-05 13:14:15", "Wednesday, 05-Aug-20 05:14:15 UTC"}, + {7, "2020-08-05", "Tuesday, 04-Aug-20 16:00:00 UTC"}, } for _, test := range tests { c := Parse(test.input) assert.Nil(c.Error) - assert.Equal(c.ToRfc850StringWithTimezone(UTC), test.output) + assert.Equal(c.ToRfc850StringWithTimezone(UTC), test.output, "Current test id is "+strconv.Itoa(test.id)) } } @@ -1264,23 +1314,24 @@ func TestCarbon_ToRfc1036String(t *testing.T) { assert := assert.New(t) tests := []struct { + id int // 测试id input string // 输入值 output string // 期望输出值 }{ - {"", ""}, - {"0", ""}, - {"0000-00-00", ""}, - {"00:00:00", ""}, - {"0000-00-00 00:00:00", ""}, + {1, "", ""}, + {2, "0", ""}, + {3, "0000-00-00", ""}, + {4, "00:00:00", ""}, + {5, "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"}, + {6, "2020-08-05 13:14:15", "Wed, 05 Aug 20 13:14:15 +0800"}, + {7, "2020-08-05", "Wed, 05 Aug 20 00:00:00 +0800"}, } for _, test := range tests { c := Parse(test.input) assert.Nil(c.Error) - assert.Equal(c.ToRfc1036String(), test.output) + assert.Equal(c.ToRfc1036String(), test.output, "Current test id is "+strconv.Itoa(test.id)) } } @@ -1288,23 +1339,24 @@ func TestCarbon_ToRfc1036StringWithTimezone(t *testing.T) { assert := assert.New(t) tests := []struct { + id int // 测试id input string // 输入值 output string // 期望输出值 }{ - {"", ""}, - {"0", ""}, - {"0000-00-00", ""}, - {"00:00:00", ""}, - {"0000-00-00 00:00:00", ""}, + {1, "", ""}, + {2, "0", ""}, + {3, "0000-00-00", ""}, + {4, "00:00:00", ""}, + {5, "0000-00-00 00:00:00", ""}, - {"2020-08-05 13:14:15", "Wed, 05 Aug 20 05:14:15 +0000"}, - {"2020-08-05", "Tue, 04 Aug 20 16:00:00 +0000"}, + {6, "2020-08-05 13:14:15", "Wed, 05 Aug 20 05:14:15 +0000"}, + {7, "2020-08-05", "Tue, 04 Aug 20 16:00:00 +0000"}, } for _, test := range tests { c := Parse(test.input) assert.Nil(c.Error) - assert.Equal(c.ToRfc1036StringWithTimezone(UTC), test.output) + assert.Equal(c.ToRfc1036StringWithTimezone(UTC), test.output, "Current test id is "+strconv.Itoa(test.id)) } } @@ -1312,23 +1364,24 @@ func TestCarbon_ToRfc1123String(t *testing.T) { assert := assert.New(t) tests := []struct { + id int // 测试id input string // 输入值 output string // 期望输出值 }{ - {"", ""}, - {"0", ""}, - {"0000-00-00", ""}, - {"00:00:00", ""}, - {"0000-00-00 00:00:00", ""}, + {1, "", ""}, + {2, "0", ""}, + {3, "0000-00-00", ""}, + {4, "00:00:00", ""}, + {5, "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"}, + {6, "2020-08-05 13:14:15", "Wed, 05 Aug 2020 13:14:15 CST"}, + {7, "2020-08-05", "Wed, 05 Aug 2020 00:00:00 CST"}, } for _, test := range tests { c := Parse(test.input) assert.Nil(c.Error) - assert.Equal(c.ToRfc1123String(), test.output) + assert.Equal(c.ToRfc1123String(), test.output, "Current test id is "+strconv.Itoa(test.id)) } } @@ -1336,23 +1389,24 @@ func TestCarbon_ToRfc1123StringWithTimezone(t *testing.T) { assert := assert.New(t) tests := []struct { + id int // 测试id input string // 输入值 output string // 期望输出值 }{ - {"", ""}, - {"0", ""}, - {"0000-00-00", ""}, - {"00:00:00", ""}, - {"0000-00-00 00:00:00", ""}, + {1, "", ""}, + {2, "0", ""}, + {3, "0000-00-00", ""}, + {4, "00:00:00", ""}, + {5, "0000-00-00 00:00:00", ""}, - {"2020-08-05 13:14:15", "Wed, 05 Aug 2020 05:14:15 UTC"}, - {"2020-08-05", "Tue, 04 Aug 2020 16:00:00 UTC"}, + {6, "2020-08-05 13:14:15", "Wed, 05 Aug 2020 05:14:15 UTC"}, + {7, "2020-08-05", "Tue, 04 Aug 2020 16:00:00 UTC"}, } for _, test := range tests { c := Parse(test.input) assert.Nil(c.Error) - assert.Equal(c.ToRfc1123StringWithTimezone(UTC), test.output) + assert.Equal(c.ToRfc1123StringWithTimezone(UTC), test.output, "Current test id is "+strconv.Itoa(test.id)) } } @@ -1360,23 +1414,24 @@ func TestCarbon_ToRfc1123ZString(t *testing.T) { assert := assert.New(t) tests := []struct { + id int // 测试id input string // 输入值 output string // 期望输出值 }{ - {"", ""}, - {"0", ""}, - {"0000-00-00", ""}, - {"00:00:00", ""}, - {"0000-00-00 00:00:00", ""}, + {1, "", ""}, + {2, "0", ""}, + {3, "0000-00-00", ""}, + {4, "00:00:00", ""}, + {5, "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"}, + {6, "2020-08-05 13:14:15", "Wed, 05 Aug 2020 13:14:15 +0800"}, + {7, "2020-08-05", "Wed, 05 Aug 2020 00:00:00 +0800"}, } for _, test := range tests { c := Parse(test.input) assert.Nil(c.Error) - assert.Equal(c.ToRfc1123ZString(), test.output) + assert.Equal(c.ToRfc1123ZString(), test.output, "Current test id is "+strconv.Itoa(test.id)) } } @@ -1384,23 +1439,24 @@ func TestCarbon_ToRfc1123ZStringWithTimezone(t *testing.T) { assert := assert.New(t) tests := []struct { + id int // 测试id input string // 输入值 output string // 期望输出值 }{ - {"", ""}, - {"0", ""}, - {"0000-00-00", ""}, - {"00:00:00", ""}, - {"0000-00-00 00:00:00", ""}, + {1, "", ""}, + {2, "0", ""}, + {3, "0000-00-00", ""}, + {4, "00:00:00", ""}, + {5, "0000-00-00 00:00:00", ""}, - {"2020-08-05 13:14:15", "Wed, 05 Aug 2020 05:14:15 +0000"}, - {"2020-08-05", "Tue, 04 Aug 2020 16:00:00 +0000"}, + {6, "2020-08-05 13:14:15", "Wed, 05 Aug 2020 05:14:15 +0000"}, + {7, "2020-08-05", "Tue, 04 Aug 2020 16:00:00 +0000"}, } for _, test := range tests { c := Parse(test.input) assert.Nil(c.Error) - assert.Equal(c.ToRfc1123ZStringWithTimezone(UTC), test.output) + assert.Equal(c.ToRfc1123ZStringWithTimezone(UTC), test.output, "Current test id is "+strconv.Itoa(test.id)) } } @@ -1408,23 +1464,24 @@ func TestCarbon_ToRfc2822String(t *testing.T) { assert := assert.New(t) tests := []struct { + id int // 测试id input string // 输入值 output string // 期望输出值 }{ - {"", ""}, - {"0", ""}, - {"0000-00-00", ""}, - {"00:00:00", ""}, - {"0000-00-00 00:00:00", ""}, + {1, "", ""}, + {2, "0", ""}, + {3, "0000-00-00", ""}, + {4, "00:00:00", ""}, + {5, "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"}, + {6, "2020-08-05 13:14:15", "Wed, 05 Aug 2020 13:14:15 +0800"}, + {7, "2020-08-05", "Wed, 05 Aug 2020 00:00:00 +0800"}, } for _, test := range tests { c := Parse(test.input) assert.Nil(c.Error) - assert.Equal(c.ToRfc2822String(), test.output) + assert.Equal(c.ToRfc2822String(), test.output, "Current test id is "+strconv.Itoa(test.id)) } } @@ -1432,23 +1489,24 @@ func TestCarbon_ToRfc2822StringWithTimezone(t *testing.T) { assert := assert.New(t) tests := []struct { + id int // 测试id input string // 输入值 output string // 期望输出值 }{ - {"", ""}, - {"0", ""}, - {"0000-00-00", ""}, - {"00:00:00", ""}, - {"0000-00-00 00:00:00", ""}, + {1, "", ""}, + {2, "0", ""}, + {3, "0000-00-00", ""}, + {4, "00:00:00", ""}, + {5, "0000-00-00 00:00:00", ""}, - {"2020-08-05 13:14:15", "Wed, 05 Aug 2020 05:14:15 +0000"}, - {"2020-08-05", "Tue, 04 Aug 2020 16:00:00 +0000"}, + {6, "2020-08-05 13:14:15", "Wed, 05 Aug 2020 05:14:15 +0000"}, + {7, "2020-08-05", "Tue, 04 Aug 2020 16:00:00 +0000"}, } for _, test := range tests { c := Parse(test.input) assert.Nil(c.Error) - assert.Equal(c.ToRfc2822StringWithTimezone(UTC), test.output) + assert.Equal(c.ToRfc2822StringWithTimezone(UTC), test.output, "Current test id is "+strconv.Itoa(test.id)) } } @@ -1456,23 +1514,24 @@ func TestCarbon_ToRfc3339String(t *testing.T) { assert := assert.New(t) tests := []struct { + id int // 测试id input string // 输入值 output string // 期望输出值 }{ - {"", ""}, - {"0", ""}, - {"0000-00-00", ""}, - {"00:00:00", ""}, - {"0000-00-00 00:00:00", ""}, + {1, "", ""}, + {2, "0", ""}, + {3, "0000-00-00", ""}, + {4, "00:00:00", ""}, + {5, "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"}, + {6, "2020-08-05 13:14:15", "2020-08-05T13:14:15+08:00"}, + {7, "2020-08-05", "2020-08-05T00:00:00+08:00"}, } for _, test := range tests { c := Parse(test.input) assert.Nil(c.Error) - assert.Equal(c.ToRfc3339String(), test.output) + assert.Equal(c.ToRfc3339String(), test.output, "Current test id is "+strconv.Itoa(test.id)) } } @@ -1480,23 +1539,24 @@ func TestCarbon_ToRfc3339StringWithTimezone(t *testing.T) { assert := assert.New(t) tests := []struct { + id int // 测试id input string // 输入值 output string // 期望输出值 }{ - {"", ""}, - {"0", ""}, - {"0000-00-00", ""}, - {"00:00:00", ""}, - {"0000-00-00 00:00:00", ""}, + {1, "", ""}, + {2, "0", ""}, + {3, "0000-00-00", ""}, + {4, "00:00:00", ""}, + {5, "0000-00-00 00:00:00", ""}, - {"2020-08-05 13:14:15", "2020-08-05T05:14:15Z"}, - {"2020-08-05", "2020-08-04T16:00:00Z"}, + {6, "2020-08-05 13:14:15", "2020-08-05T05:14:15Z"}, + {7, "2020-08-05", "2020-08-04T16:00:00Z"}, } for _, test := range tests { c := Parse(test.input) assert.Nil(c.Error) - assert.Equal(c.ToRfc3339StringWithTimezone(UTC), test.output) + assert.Equal(c.ToRfc3339StringWithTimezone(UTC), test.output, "Current test id is "+strconv.Itoa(test.id)) } } @@ -1504,23 +1564,24 @@ func TestCarbon_ToRfc7231String(t *testing.T) { assert := assert.New(t) tests := []struct { + id int // 测试id input string // 输入值 output string // 期望输出值 }{ - {"", ""}, - {"0", ""}, - {"0000-00-00", ""}, - {"00:00:00", ""}, - {"0000-00-00 00:00:00", ""}, + {1, "", ""}, + {2, "0", ""}, + {3, "0000-00-00", ""}, + {4, "00:00:00", ""}, + {5, "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"}, + {6, "2020-08-05 13:14:15", "Wed, 05 Aug 2020 13:14:15 GMT"}, + {7, "2020-08-05", "Wed, 05 Aug 2020 00:00:00 GMT"}, } for _, test := range tests { c := Parse(test.input) assert.Nil(c.Error) - assert.Equal(c.ToRfc7231String(), test.output) + assert.Equal(c.ToRfc7231String(), test.output, "Current test id is "+strconv.Itoa(test.id)) } } @@ -1528,22 +1589,23 @@ func TestCarbon_ToRfc7231StringWithTimezone(t *testing.T) { assert := assert.New(t) tests := []struct { + id int // 测试id input string // 输入值 output string // 期望输出值 }{ - {"", ""}, - {"0", ""}, - {"0000-00-00", ""}, - {"00:00:00", ""}, - {"0000-00-00 00:00:00", ""}, + {1, "", ""}, + {2, "0", ""}, + {3, "0000-00-00", ""}, + {4, "00:00:00", ""}, + {5, "0000-00-00 00:00:00", ""}, - {"2020-08-05 13:14:15", "Wed, 05 Aug 2020 05:14:15 GMT"}, - {"2020-08-05", "Tue, 04 Aug 2020 16:00:00 GMT"}, + {6, "2020-08-05 13:14:15", "Wed, 05 Aug 2020 05:14:15 GMT"}, + {7, "2020-08-05", "Tue, 04 Aug 2020 16:00:00 GMT"}, } for _, test := range tests { c := Parse(test.input) assert.Nil(c.Error) - assert.Equal(c.ToRfc7231StringWithTimezone(UTC), test.output) + assert.Equal(c.ToRfc7231StringWithTimezone(UTC), test.output, "Current test id is "+strconv.Itoa(test.id)) } } diff --git a/language_test.go b/language_test.go index 2d8f9a42..8077bccbf 100755 --- a/language_test.go +++ b/language_test.go @@ -1,6 +1,7 @@ package carbon import ( + "strconv" "testing" "github.com/stretchr/testify/assert" @@ -10,15 +11,16 @@ func TestLanguage_SetLocale(t *testing.T) { assert := assert.New(t) tests := []struct { + id int // 测试id input string // 输入值 output error // 期望输出值 }{ - {"en", nil}, - {"zh-CN", nil}, + {1, "en", nil}, + {2, "zh-CN", nil}, } for _, test := range tests { - assert.ErrorIs(NewLanguage().SetLocale(test.input), test.output) + assert.ErrorIs(NewLanguage().SetLocale(test.input), test.output, "Current test id is "+strconv.Itoa(test.id)) } } @@ -26,14 +28,15 @@ func TestLanguage_SetDir(t *testing.T) { assert := assert.New(t) tests := []struct { + id int // 测试id input string // 输入值 output error // 期望输出值 }{ - {"lang", nil}, + {1, "lang", nil}, } for _, test := range tests { - assert.ErrorIs(NewLanguage().SetDir(test.input), test.output) + assert.ErrorIs(NewLanguage().SetDir(test.input), test.output, "Current test id is "+strconv.Itoa(test.id)) } } @@ -59,30 +62,31 @@ func TestLanguage_SetResources1(t *testing.T) { lang.SetResources(resources) tests := []struct { + id int // 测试id input Carbon // 输入值 output string // 期望输出值 }{ - {Now(), "just now"}, - {Now().AddYears(1), "in 1 yr"}, - {Now().SubYears(1), "1 yr ago"}, - {Now().AddYears(10), "in 10 yrs"}, - {Now().SubYears(10), "10 yrs ago"}, + {1, Now(), "just now"}, + {2, Now().AddYears(1), "in 1 yr"}, + {3, Now().SubYears(1), "1 yr ago"}, + {4, Now().AddYears(10), "in 10 yrs"}, + {5, Now().SubYears(10), "10 yrs ago"}, - {Now().AddMonths(1), "in 1 mo"}, - {Now().SubMonths(1), "1 mo ago"}, - {Now().AddMonths(10), "in 10 mos"}, - {Now().SubMonths(10), "10 mos ago"}, + {6, Now().AddMonths(1), "in 1 mo"}, + {7, Now().SubMonths(1), "1 mo ago"}, + {8, Now().AddMonths(10), "in 10 mos"}, + {9, Now().SubMonths(10), "10 mos ago"}, - {Now().AddDays(1), "in 1d"}, - {Now().SubDays(1), "1d ago"}, - {Now().AddDays(10), "in 1w"}, - {Now().SubDays(10), "1w ago"}, + {10, Now().AddDays(1), "in 1d"}, + {11, Now().SubDays(1), "1d ago"}, + {12, Now().AddDays(10), "in 1w"}, + {13, Now().SubDays(10), "1w ago"}, } for _, test := range tests { c := test.input.SetLanguage(lang) assert.Nil(c.Error) - assert.Equal(c.DiffForHumans(), test.output) + assert.Equal(c.DiffForHumans(), test.output, "Current test id is "+strconv.Itoa(test.id)) } } @@ -96,43 +100,44 @@ func TestLanguage_SetResources2(t *testing.T) { lang.SetResources(resources) tests := []struct { + id int // 测试id input string // 输入值 output string // 期望输出值 }{ - {"", ""}, - {"0", ""}, - {"0000-00-00", ""}, - {"00:00:00", ""}, + {1, "", ""}, + {2, "0", ""}, + {3, "0000-00-00", ""}, + {4, "00:00:00", ""}, - {"0000-00-00 00:00:00", ""}, - {"2021-08-05 13:14:15", ""}, + {5, "0000-00-00 00:00:00", ""}, + {6, "2021-08-05 13:14:15", ""}, } for _, test := range tests { - assert.Equal(Parse(test.input).SetLanguage(lang).DiffForHumans(), test.output) + assert.Equal(Parse(test.input).SetLanguage(lang).DiffForHumans(), test.output, "Current test id is "+strconv.Itoa(test.id)) } for _, test := range tests { - assert.Equal(Parse(test.input).SetLanguage(lang).Constellation(), test.output) + assert.Equal(Parse(test.input).SetLanguage(lang).Constellation(), test.output, "Current test id is "+strconv.Itoa(test.id)) } for _, test := range tests { - assert.Equal(Parse(test.input).SetLanguage(lang).Season(), test.output) + assert.Equal(Parse(test.input).SetLanguage(lang).Season(), test.output, "Current test id is "+strconv.Itoa(test.id)) } for _, test := range tests { - assert.Equal(Parse(test.input).SetLanguage(lang).ToWeekString(), test.output) + assert.Equal(Parse(test.input).SetLanguage(lang).ToWeekString(), test.output, "Current test id is "+strconv.Itoa(test.id)) } for _, test := range tests { - assert.Equal(Parse(test.input).SetLanguage(lang).ToShortWeekString(), test.output) + assert.Equal(Parse(test.input).SetLanguage(lang).ToShortWeekString(), test.output, "Current test id is "+strconv.Itoa(test.id)) } for _, test := range tests { - assert.Equal(Parse(test.input).SetLanguage(lang).ToMonthString(), test.output) + assert.Equal(Parse(test.input).SetLanguage(lang).ToMonthString(), test.output, "Current test id is "+strconv.Itoa(test.id)) } for _, test := range tests { - assert.Equal(Parse(test.input).SetLanguage(lang).ToShortMonthString(), test.output) + assert.Equal(Parse(test.input).SetLanguage(lang).ToShortMonthString(), test.output, "Current test id is "+strconv.Itoa(test.id)) } } diff --git a/modifier_test.go b/modifier_test.go index 16dcbf0b..8b5a3d26 100755 --- a/modifier_test.go +++ b/modifier_test.go @@ -1,6 +1,7 @@ package carbon import ( + "strconv" "testing" "time" @@ -11,26 +12,27 @@ func TestCarbon_StartOfCentury(t *testing.T) { assert := assert.New(t) tests := []struct { + id int // 测试id input string // 输入值 output string // 期望输出值 }{ - {"", ""}, - {"0", ""}, - {"0000-00-00", ""}, - {"00:00:00", ""}, - {"0000-00-00 00:00:00", ""}, + {1, "", ""}, + {2, "0", ""}, + {3, "0000-00-00", ""}, + {4, "00:00:00", ""}, + {5, "0000-00-00 00:00:00", ""}, - {"2020-01-01 00:00:00", "2000-01-01 00:00:00"}, - {"2020-01-31 23:59:59", "2000-01-01 00:00:00"}, - {"2020-02-01 13:14:15", "2000-01-01 00:00:00"}, - {"2020-02-28", "2000-01-01 00:00:00"}, - {"2020-02-29", "2000-01-01 00:00:00"}, + {6, "2020-01-01 00:00:00", "2000-01-01 00:00:00"}, + {7, "2020-01-31 23:59:59", "2000-01-01 00:00:00"}, + {8, "2020-02-01 13:14:15", "2000-01-01 00:00:00"}, + {9, "2020-02-28", "2000-01-01 00:00:00"}, + {10, "2020-02-29", "2000-01-01 00:00:00"}, } for _, test := range tests { c := Parse(test.input).StartOfCentury() assert.Nil(c.Error) - assert.Equal(c.ToDateTimeString(), test.output) + assert.Equal(c.ToDateTimeString(), test.output, "Current test id is "+strconv.Itoa(test.id)) } } @@ -38,26 +40,27 @@ func TestCarbon_EndOfCentury(t *testing.T) { assert := assert.New(t) tests := []struct { + id int // 测试id input string // 输入值 output string // 期望输出值 }{ - {"", ""}, - {"0", ""}, - {"0000-00-00", ""}, - {"00:00:00", ""}, - {"0000-00-00 00:00:00", ""}, + {1, "", ""}, + {2, "0", ""}, + {3, "0000-00-00", ""}, + {4, "00:00:00", ""}, + {5, "0000-00-00 00:00:00", ""}, - {"2020-01-01 00:00:00", "2999-12-31 23:59:59"}, - {"2020-01-31 23:59:59", "2999-12-31 23:59:59"}, - {"2020-02-01 13:14:15", "2999-12-31 23:59:59"}, - {"2020-02-28", "2999-12-31 23:59:59"}, - {"2020-02-29", "2999-12-31 23:59:59"}, + {6, "2020-01-01 00:00:00", "2999-12-31 23:59:59"}, + {7, "2020-01-31 23:59:59", "2999-12-31 23:59:59"}, + {8, "2020-02-01 13:14:15", "2999-12-31 23:59:59"}, + {9, "2020-02-28", "2999-12-31 23:59:59"}, + {10, "2020-02-29", "2999-12-31 23:59:59"}, } for _, test := range tests { c := Parse(test.input).EndOfCentury() assert.Nil(c.Error) - assert.Equal(c.ToDateTimeString(), test.output) + assert.Equal(c.ToDateTimeString(), test.output, "Current test id is "+strconv.Itoa(test.id)) } } @@ -65,27 +68,28 @@ func TestCarbon_StartOfDecade(t *testing.T) { assert := assert.New(t) tests := []struct { + id int // 测试id input string // 输入值 output string // 期望输出值 }{ - {"", ""}, - {"0", ""}, - {"0000-00-00", ""}, - {"00:00:00", ""}, - {"0000-00-00 00:00:00", ""}, + {1, "", ""}, + {2, "0", ""}, + {3, "0000-00-00", ""}, + {4, "00:00:00", ""}, + {5, "0000-00-00 00:00:00", ""}, - {"2020-01-31 23:59:59", "2020-01-01 00:00:00"}, - {"2021-01-01 00:00:00", "2020-01-01 00:00:00"}, - {"2029-01-31 23:59:59", "2020-01-01 00:00:00"}, - {"2020-02-01 13:14:15", "2020-01-01 00:00:00"}, - {"2020-02-28", "2020-01-01 00:00:00"}, - {"2020-02-29", "2020-01-01 00:00:00"}, + {6, "2020-01-31 23:59:59", "2020-01-01 00:00:00"}, + {7, "2021-01-01 00:00:00", "2020-01-01 00:00:00"}, + {8, "2029-01-31 23:59:59", "2020-01-01 00:00:00"}, + {9, "2020-02-01 13:14:15", "2020-01-01 00:00:00"}, + {10, "2020-02-28", "2020-01-01 00:00:00"}, + {11, "2020-02-29", "2020-01-01 00:00:00"}, } for _, test := range tests { c := Parse(test.input).StartOfDecade() assert.Nil(c.Error) - assert.Equal(c.ToDateTimeString(), test.output) + assert.Equal(c.ToDateTimeString(), test.output, "Current test id is "+strconv.Itoa(test.id)) } } @@ -93,27 +97,28 @@ func TestCarbon_EndOfDecade(t *testing.T) { assert := assert.New(t) tests := []struct { + id int // 测试id input string // 输入值 output string // 期望输出值 }{ - {"", ""}, - {"0", ""}, - {"0000-00-00", ""}, - {"00:00:00", ""}, - {"0000-00-00 00:00:00", ""}, + {1, "", ""}, + {2, "0", ""}, + {3, "0000-00-00", ""}, + {4, "00:00:00", ""}, + {5, "0000-00-00 00:00:00", ""}, - {"2020-01-31 23:59:59", "2029-12-31 23:59:59"}, - {"2021-01-01 00:00:00", "2029-12-31 23:59:59"}, - {"2029-01-31 23:59:59", "2029-12-31 23:59:59"}, - {"2020-02-01 13:14:15", "2029-12-31 23:59:59"}, - {"2020-02-28", "2029-12-31 23:59:59"}, - {"2020-02-29", "2029-12-31 23:59:59"}, + {6, "2020-01-31 23:59:59", "2029-12-31 23:59:59"}, + {7, "2021-01-01 00:00:00", "2029-12-31 23:59:59"}, + {8, "2029-01-31 23:59:59", "2029-12-31 23:59:59"}, + {9, "2020-02-01 13:14:15", "2029-12-31 23:59:59"}, + {10, "2020-02-28", "2029-12-31 23:59:59"}, + {11, "2020-02-29", "2029-12-31 23:59:59"}, } for _, test := range tests { c := Parse(test.input).EndOfDecade() assert.Nil(c.Error) - assert.Equal(c.ToDateTimeString(), test.output) + assert.Equal(c.ToDateTimeString(), test.output, "Current test id is "+strconv.Itoa(test.id)) } } @@ -121,26 +126,27 @@ func TestCarbon_StartOfYear(t *testing.T) { assert := assert.New(t) tests := []struct { + id int // 测试id input string // 输入值 output string // 期望输出值 }{ - {"", ""}, - {"0", ""}, - {"0000-00-00", ""}, - {"00:00:00", ""}, - {"0000-00-00 00:00:00", ""}, + {1, "", ""}, + {2, "0", ""}, + {3, "0000-00-00", ""}, + {4, "00:00:00", ""}, + {5, "0000-00-00 00:00:00", ""}, - {"2020-01-01 00:00:00", "2020-01-01 00:00:00"}, - {"2020-01-31 23:59:59", "2020-01-01 00:00:00"}, - {"2020-02-01 13:14:15", "2020-01-01 00:00:00"}, - {"2020-02-28", "2020-01-01 00:00:00"}, - {"2020-02-29", "2020-01-01 00:00:00"}, + {6, "2020-01-01 00:00:00", "2020-01-01 00:00:00"}, + {7, "2020-01-31 23:59:59", "2020-01-01 00:00:00"}, + {8, "2020-02-01 13:14:15", "2020-01-01 00:00:00"}, + {9, "2020-02-28", "2020-01-01 00:00:00"}, + {10, "2020-02-29", "2020-01-01 00:00:00"}, } for _, test := range tests { c := Parse(test.input).StartOfYear() assert.Nil(c.Error) - assert.Equal(c.ToDateTimeString(), test.output) + assert.Equal(c.ToDateTimeString(), test.output, "Current test id is "+strconv.Itoa(test.id)) } } @@ -148,26 +154,27 @@ func TestCarbon_EndOfYear(t *testing.T) { assert := assert.New(t) tests := []struct { + id int // 测试id input string // 输入值 output string // 期望输出值 }{ - {"", ""}, - {"0", ""}, - {"0000-00-00", ""}, - {"00:00:00", ""}, - {"0000-00-00 00:00:00", ""}, + {1, "", ""}, + {2, "0", ""}, + {3, "0000-00-00", ""}, + {4, "00:00:00", ""}, + {5, "0000-00-00 00:00:00", ""}, - {"2020-01-01 00:00:00", "2020-12-31 23:59:59"}, - {"2020-01-31 23:59:59", "2020-12-31 23:59:59"}, - {"2020-02-01 13:14:15", "2020-12-31 23:59:59"}, - {"2020-02-28", "2020-12-31 23:59:59"}, - {"2020-02-29", "2020-12-31 23:59:59"}, + {6, "2020-01-01 00:00:00", "2020-12-31 23:59:59"}, + {7, "2020-01-31 23:59:59", "2020-12-31 23:59:59"}, + {8, "2020-02-01 13:14:15", "2020-12-31 23:59:59"}, + {9, "2020-02-28", "2020-12-31 23:59:59"}, + {10, "2020-02-29", "2020-12-31 23:59:59"}, } for _, test := range tests { c := Parse(test.input).EndOfYear() assert.Nil(c.Error) - assert.Equal(c.ToDateTimeString(), test.output) + assert.Equal(c.ToDateTimeString(), test.output, "Current test id is "+strconv.Itoa(test.id)) } } @@ -175,33 +182,34 @@ func TestCarbon_StartOfQuarter(t *testing.T) { assert := assert.New(t) tests := []struct { + id int // 测试id input string // 输入值 output string // 期望输出值 }{ - {"", ""}, - {"0", ""}, - {"0000-00-00", ""}, - {"00:00:00", ""}, - {"0000-00-00 00:00:00", ""}, - - {"2020-01-15 00:00:00", "2020-01-01 00:00:00"}, - {"2020-02-15 00:00:00", "2020-01-01 00:00:00"}, - {"2020-03-15 00:00:00", "2020-01-01 00:00:00"}, - {"2020-04-15 23:59:59", "2020-04-01 00:00:00"}, - {"2020-05-15 23:59:59", "2020-04-01 00:00:00"}, - {"2020-06-15 23:59:59", "2020-04-01 00:00:00"}, - {"2020-07-15 23:59:59", "2020-07-01 00:00:00"}, - {"2020-08-15 13:14:15", "2020-07-01 00:00:00"}, - {"2020-09-15 13:14:15", "2020-07-01 00:00:00"}, - {"2020-10-15", "2020-10-01 00:00:00"}, - {"2020-11-15", "2020-10-01 00:00:00"}, - {"2020-12-15", "2020-10-01 00:00:00"}, + {1, "", ""}, + {2, "0", ""}, + {3, "0000-00-00", ""}, + {4, "00:00:00", ""}, + {5, "0000-00-00 00:00:00", ""}, + + {6, "2020-01-15 00:00:00", "2020-01-01 00:00:00"}, + {7, "2020-02-15 00:00:00", "2020-01-01 00:00:00"}, + {8, "2020-03-15 00:00:00", "2020-01-01 00:00:00"}, + {9, "2020-04-15 23:59:59", "2020-04-01 00:00:00"}, + {10, "2020-05-15 23:59:59", "2020-04-01 00:00:00"}, + {11, "2020-06-15 23:59:59", "2020-04-01 00:00:00"}, + {12, "2020-07-15 23:59:59", "2020-07-01 00:00:00"}, + {13, "2020-08-15 13:14:15", "2020-07-01 00:00:00"}, + {14, "2020-09-15 13:14:15", "2020-07-01 00:00:00"}, + {15, "2020-10-15", "2020-10-01 00:00:00"}, + {16, "2020-11-15", "2020-10-01 00:00:00"}, + {17, "2020-12-15", "2020-10-01 00:00:00"}, } for _, test := range tests { c := Parse(test.input).StartOfQuarter() assert.Nil(c.Error) - assert.Equal(c.ToDateTimeString(), test.output) + assert.Equal(c.ToDateTimeString(), test.output, "Current test id is "+strconv.Itoa(test.id)) } } @@ -209,33 +217,34 @@ func TestCarbon_EndOfQuarter(t *testing.T) { assert := assert.New(t) tests := []struct { + id int // 测试id input string // 输入值 output string // 期望输出值 }{ - {"", ""}, - {"0", ""}, - {"0000-00-00", ""}, - {"00:00:00", ""}, - {"0000-00-00 00:00:00", ""}, - - {"2020-01-15 00:00:00", "2020-03-31 23:59:59"}, - {"2020-02-15 00:00:00", "2020-03-31 23:59:59"}, - {"2020-03-15 00:00:00", "2020-03-31 23:59:59"}, - {"2020-04-15 23:59:59", "2020-06-30 23:59:59"}, - {"2020-05-15 23:59:59", "2020-06-30 23:59:59"}, - {"2020-06-15 23:59:59", "2020-06-30 23:59:59"}, - {"2020-07-15 23:59:59", "2020-09-30 23:59:59"}, - {"2020-08-15 13:14:15", "2020-09-30 23:59:59"}, - {"2020-09-15 13:14:15", "2020-09-30 23:59:59"}, - {"2020-10-15", "2020-12-31 23:59:59"}, - {"2020-11-15", "2020-12-31 23:59:59"}, - {"2020-12-15", "2020-12-31 23:59:59"}, + {1, "", ""}, + {2, "0", ""}, + {3, "0000-00-00", ""}, + {4, "00:00:00", ""}, + {5, "0000-00-00 00:00:00", ""}, + + {6, "2020-01-15 00:00:00", "2020-03-31 23:59:59"}, + {7, "2020-02-15 00:00:00", "2020-03-31 23:59:59"}, + {8, "2020-03-15 00:00:00", "2020-03-31 23:59:59"}, + {9, "2020-04-15 23:59:59", "2020-06-30 23:59:59"}, + {10, "2020-05-15 23:59:59", "2020-06-30 23:59:59"}, + {11, "2020-06-15 23:59:59", "2020-06-30 23:59:59"}, + {12, "2020-07-15 23:59:59", "2020-09-30 23:59:59"}, + {13, "2020-08-15 13:14:15", "2020-09-30 23:59:59"}, + {14, "2020-09-15 13:14:15", "2020-09-30 23:59:59"}, + {15, "2020-10-15", "2020-12-31 23:59:59"}, + {16, "2020-11-15", "2020-12-31 23:59:59"}, + {17, "2020-12-15", "2020-12-31 23:59:59"}, } for _, test := range tests { c := Parse(test.input).EndOfQuarter() assert.Nil(c.Error) - assert.Equal(c.ToDateTimeString(), test.output) + assert.Equal(c.ToDateTimeString(), test.output, "Current test id is "+strconv.Itoa(test.id)) } } @@ -243,33 +252,34 @@ func TestCarbon_StartOfMonth(t *testing.T) { assert := assert.New(t) tests := []struct { + id int // 测试id input string // 输入值 output string // 期望输出值 }{ - {"", ""}, - {"0", ""}, - {"0000-00-00", ""}, - {"00:00:00", ""}, - {"0000-00-00 00:00:00", ""}, - - {"2020-01-15 00:00:00", "2020-01-01 00:00:00"}, - {"2020-02-15 00:00:00", "2020-02-01 00:00:00"}, - {"2020-03-15 00:00:00", "2020-03-01 00:00:00"}, - {"2020-04-15 23:59:59", "2020-04-01 00:00:00"}, - {"2020-05-15 23:59:59", "2020-05-01 00:00:00"}, - {"2020-06-15 23:59:59", "2020-06-01 00:00:00"}, - {"2020-07-15 23:59:59", "2020-07-01 00:00:00"}, - {"2020-08-15 13:14:15", "2020-08-01 00:00:00"}, - {"2020-09-15 13:14:15", "2020-09-01 00:00:00"}, - {"2020-10-15", "2020-10-01 00:00:00"}, - {"2020-11-15", "2020-11-01 00:00:00"}, - {"2020-12-15", "2020-12-01 00:00:00"}, + {1, "", ""}, + {2, "0", ""}, + {3, "0000-00-00", ""}, + {4, "00:00:00", ""}, + {5, "0000-00-00 00:00:00", ""}, + + {6, "2020-01-15 00:00:00", "2020-01-01 00:00:00"}, + {7, "2020-02-15 00:00:00", "2020-02-01 00:00:00"}, + {8, "2020-03-15 00:00:00", "2020-03-01 00:00:00"}, + {9, "2020-04-15 23:59:59", "2020-04-01 00:00:00"}, + {10, "2020-05-15 23:59:59", "2020-05-01 00:00:00"}, + {11, "2020-06-15 23:59:59", "2020-06-01 00:00:00"}, + {12, "2020-07-15 23:59:59", "2020-07-01 00:00:00"}, + {13, "2020-08-15 13:14:15", "2020-08-01 00:00:00"}, + {14, "2020-09-15 13:14:15", "2020-09-01 00:00:00"}, + {15, "2020-10-15", "2020-10-01 00:00:00"}, + {16, "2020-11-15", "2020-11-01 00:00:00"}, + {17, "2020-12-15", "2020-12-01 00:00:00"}, } for _, test := range tests { c := Parse(test.input).StartOfMonth() assert.Nil(c.Error) - assert.Equal(c.ToDateTimeString(), test.output) + assert.Equal(c.ToDateTimeString(), test.output, "Current test id is "+strconv.Itoa(test.id)) } } @@ -277,33 +287,34 @@ func TestCarbon_EndOfMonth(t *testing.T) { assert := assert.New(t) tests := []struct { + id int // 测试id input string // 输入值 output string // 期望输出值 }{ - {"", ""}, - {"0", ""}, - {"0000-00-00", ""}, - {"00:00:00", ""}, - {"0000-00-00 00:00:00", ""}, - - {"2020-01-15 00:00:00", "2020-01-31 23:59:59"}, - {"2020-02-15 00:00:00", "2020-02-29 23:59:59"}, - {"2020-03-15 00:00:00", "2020-03-31 23:59:59"}, - {"2020-04-15 23:59:59", "2020-04-30 23:59:59"}, - {"2020-05-15 23:59:59", "2020-05-31 23:59:59"}, - {"2020-06-15 23:59:59", "2020-06-30 23:59:59"}, - {"2020-07-15 23:59:59", "2020-07-31 23:59:59"}, - {"2020-08-15 13:14:15", "2020-08-31 23:59:59"}, - {"2020-09-15 13:14:15", "2020-09-30 23:59:59"}, - {"2020-10-15", "2020-10-31 23:59:59"}, - {"2020-11-15", "2020-11-30 23:59:59"}, - {"2020-12-15", "2020-12-31 23:59:59"}, + {1, "", ""}, + {2, "0", ""}, + {3, "0000-00-00", ""}, + {4, "00:00:00", ""}, + {5, "0000-00-00 00:00:00", ""}, + + {6, "2020-01-15 00:00:00", "2020-01-31 23:59:59"}, + {7, "2020-02-15 00:00:00", "2020-02-29 23:59:59"}, + {8, "2020-03-15 00:00:00", "2020-03-31 23:59:59"}, + {9, "2020-04-15 23:59:59", "2020-04-30 23:59:59"}, + {10, "2020-05-15 23:59:59", "2020-05-31 23:59:59"}, + {11, "2020-06-15 23:59:59", "2020-06-30 23:59:59"}, + {12, "2020-07-15 23:59:59", "2020-07-31 23:59:59"}, + {13, "2020-08-15 13:14:15", "2020-08-31 23:59:59"}, + {14, "2020-09-15 13:14:15", "2020-09-30 23:59:59"}, + {15, "2020-10-15", "2020-10-31 23:59:59"}, + {16, "2020-11-15", "2020-11-30 23:59:59"}, + {17, "2020-12-15", "2020-12-31 23:59:59"}, } for _, test := range tests { c := Parse(test.input).EndOfMonth() assert.Nil(c.Error) - assert.Equal(c.ToDateTimeString(), test.output) + assert.Equal(c.ToDateTimeString(), test.output, "Current test id is "+strconv.Itoa(test.id)) } } @@ -311,29 +322,30 @@ func TestCarbon_StartOfWeek(t *testing.T) { assert := assert.New(t) tests := []struct { + id int // 测试id input string // 输入值 week time.Weekday // 输入参数 output string // 期望输出值 }{ - {"", time.Sunday, ""}, - {"0000-00-00 00:00:00", time.Sunday, ""}, - {"", time.Monday, ""}, - {"0000-00-00 00:00:00", time.Monday, ""}, + {1, "", time.Sunday, ""}, + {2, "0000-00-00 00:00:00", time.Sunday, ""}, + {3, "", time.Monday, ""}, + {4, "0000-00-00 00:00:00", time.Monday, ""}, - {"2021-06-13", time.Sunday, "2021-06-13 00:00:00"}, - {"2021-06-14", time.Sunday, "2021-06-13 00:00:00"}, - {"2021-06-18", time.Sunday, "2021-06-13 00:00:00"}, - {"2021-06-13", time.Monday, "2021-06-07 00:00:00"}, - {"2021-06-14", time.Monday, "2021-06-14 00:00:00"}, - {"2021-06-18", time.Monday, "2021-06-14 00:00:00"}, - {"2021-06-19", time.Monday, "2021-06-14 00:00:00"}, - {"2021-06-20", time.Monday, "2021-06-14 00:00:00"}, + {5, "2021-06-13", time.Sunday, "2021-06-13 00:00:00"}, + {6, "2021-06-14", time.Sunday, "2021-06-13 00:00:00"}, + {7, "2021-06-18", time.Sunday, "2021-06-13 00:00:00"}, + {8, "2021-06-13", time.Monday, "2021-06-07 00:00:00"}, + {9, "2021-06-14", time.Monday, "2021-06-14 00:00:00"}, + {10, "2021-06-18", time.Monday, "2021-06-14 00:00:00"}, + {11, "2021-06-19", time.Monday, "2021-06-14 00:00:00"}, + {12, "2021-06-20", time.Monday, "2021-06-14 00:00:00"}, } for _, test := range tests { c := Parse(test.input).StartOfWeek(test.week) assert.Nil(c.Error) - assert.Equal(c.ToDateTimeString(), test.output) + assert.Equal(c.ToDateTimeString(), test.output, "Current test id is "+strconv.Itoa(test.id)) } } @@ -341,32 +353,33 @@ func TestCarbon_EndOfWeek(t *testing.T) { assert := assert.New(t) tests := []struct { + id int // 测试id input string // 输入值 week time.Weekday // 输入参数 output string // 期望输出值 }{ - {"", time.Sunday, ""}, - {"0000-00-00 00:00:00", time.Sunday, ""}, - {"", time.Monday, ""}, - {"0000-00-00 00:00:00", time.Monday, ""}, - - {"2021-06-13", time.Sunday, "2021-06-19 23:59:59"}, - {"2021-06-14", time.Sunday, "2021-06-19 23:59:59"}, - {"2021-06-18", time.Sunday, "2021-06-19 23:59:59"}, - {"2021-07-17", time.Sunday, "2021-07-17 23:59:59"}, - {"2021-07-18", time.Sunday, "2021-07-24 23:59:59"}, - {"2021-06-13", time.Monday, "2021-06-13 23:59:59"}, - {"2021-06-14", time.Monday, "2021-06-20 23:59:59"}, - {"2021-06-18", time.Monday, "2021-06-20 23:59:59"}, - {"2021-06-19", time.Monday, "2021-06-20 23:59:59"}, - {"2021-07-17", time.Monday, "2021-07-18 23:59:59"}, - {"2021-07-18", time.Monday, "2021-07-18 23:59:59"}, + {1, "", time.Sunday, ""}, + {2, "0000-00-00 00:00:00", time.Sunday, ""}, + {3, "", time.Monday, ""}, + {4, "0000-00-00 00:00:00", time.Monday, ""}, + + {5, "2021-06-13", time.Sunday, "2021-06-19 23:59:59"}, + {6, "2021-06-14", time.Sunday, "2021-06-19 23:59:59"}, + {7, "2021-06-18", time.Sunday, "2021-06-19 23:59:59"}, + {8, "2021-07-17", time.Sunday, "2021-07-17 23:59:59"}, + {9, "2021-07-18", time.Sunday, "2021-07-24 23:59:59"}, + {10, "2021-06-13", time.Monday, "2021-06-13 23:59:59"}, + {11, "2021-06-14", time.Monday, "2021-06-20 23:59:59"}, + {12, "2021-06-18", time.Monday, "2021-06-20 23:59:59"}, + {13, "2021-06-19", time.Monday, "2021-06-20 23:59:59"}, + {14, "2021-07-17", time.Monday, "2021-07-18 23:59:59"}, + {15, "2021-07-18", time.Monday, "2021-07-18 23:59:59"}, } for _, test := range tests { c := Parse(test.input).EndOfWeek(test.week) assert.Nil(c.Error) - assert.Equal(c.ToDateTimeString(), test.output) + assert.Equal(c.ToDateTimeString(), test.output, "Current test id is "+strconv.Itoa(test.id)) } } @@ -374,33 +387,34 @@ func TestCarbon_StartOfDay(t *testing.T) { assert := assert.New(t) tests := []struct { + id int // 测试id input string // 输入值 output string // 期望输出值 }{ - {"", ""}, - {"0", ""}, - {"0000-00-00", ""}, - {"00:00:00", ""}, - {"0000-00-00 00:00:00", ""}, - - {"2020-01-15 00:00:00", "2020-01-15 00:00:00"}, - {"2020-02-15 00:00:00", "2020-02-15 00:00:00"}, - {"2020-03-15 00:00:00", "2020-03-15 00:00:00"}, - {"2020-04-15 23:59:59", "2020-04-15 00:00:00"}, - {"2020-05-15 23:59:59", "2020-05-15 00:00:00"}, - {"2020-06-15 23:59:59", "2020-06-15 00:00:00"}, - {"2020-07-15 23:59:59", "2020-07-15 00:00:00"}, - {"2020-08-15 13:14:15", "2020-08-15 00:00:00"}, - {"2020-09-15 13:14:15", "2020-09-15 00:00:00"}, - {"2020-10-15", "2020-10-15 00:00:00"}, - {"2020-11-15", "2020-11-15 00:00:00"}, - {"2020-12-15", "2020-12-15 00:00:00"}, + {1, "", ""}, + {2, "0", ""}, + {3, "0000-00-00", ""}, + {4, "00:00:00", ""}, + {5, "0000-00-00 00:00:00", ""}, + + {6, "2020-01-15 00:00:00", "2020-01-15 00:00:00"}, + {7, "2020-02-15 00:00:00", "2020-02-15 00:00:00"}, + {8, "2020-03-15 00:00:00", "2020-03-15 00:00:00"}, + {9, "2020-04-15 23:59:59", "2020-04-15 00:00:00"}, + {10, "2020-05-15 23:59:59", "2020-05-15 00:00:00"}, + {11, "2020-06-15 23:59:59", "2020-06-15 00:00:00"}, + {12, "2020-07-15 23:59:59", "2020-07-15 00:00:00"}, + {13, "2020-08-15 13:14:15", "2020-08-15 00:00:00"}, + {14, "2020-09-15 13:14:15", "2020-09-15 00:00:00"}, + {15, "2020-10-15", "2020-10-15 00:00:00"}, + {16, "2020-11-15", "2020-11-15 00:00:00"}, + {17, "2020-12-15", "2020-12-15 00:00:00"}, } for _, test := range tests { c := Parse(test.input).StartOfDay() assert.Nil(c.Error) - assert.Equal(c.ToDateTimeString(), test.output) + assert.Equal(c.ToDateTimeString(), test.output, "Current test id is "+strconv.Itoa(test.id)) } } @@ -408,33 +422,34 @@ func TestCarbon_EndOfDay(t *testing.T) { assert := assert.New(t) tests := []struct { + id int // 测试id input string // 输入值 output string // 期望输出值 }{ - {"", ""}, - {"0", ""}, - {"0000-00-00", ""}, - {"00:00:00", ""}, - {"0000-00-00 00:00:00", ""}, - - {"2020-01-15 00:00:00", "2020-01-15 23:59:59"}, - {"2020-02-15 00:00:00", "2020-02-15 23:59:59"}, - {"2020-03-15 00:00:00", "2020-03-15 23:59:59"}, - {"2020-04-15 23:59:59", "2020-04-15 23:59:59"}, - {"2020-05-15 23:59:59", "2020-05-15 23:59:59"}, - {"2020-06-15 23:59:59", "2020-06-15 23:59:59"}, - {"2020-07-15 23:59:59", "2020-07-15 23:59:59"}, - {"2020-08-15 13:14:15", "2020-08-15 23:59:59"}, - {"2020-09-15 13:14:15", "2020-09-15 23:59:59"}, - {"2020-10-15", "2020-10-15 23:59:59"}, - {"2020-11-15", "2020-11-15 23:59:59"}, - {"2020-12-15", "2020-12-15 23:59:59"}, + {1, "", ""}, + {2, "0", ""}, + {3, "0000-00-00", ""}, + {4, "00:00:00", ""}, + {5, "0000-00-00 00:00:00", ""}, + + {6, "2020-01-15 00:00:00", "2020-01-15 23:59:59"}, + {7, "2020-02-15 00:00:00", "2020-02-15 23:59:59"}, + {8, "2020-03-15 00:00:00", "2020-03-15 23:59:59"}, + {9, "2020-04-15 23:59:59", "2020-04-15 23:59:59"}, + {10, "2020-05-15 23:59:59", "2020-05-15 23:59:59"}, + {11, "2020-06-15 23:59:59", "2020-06-15 23:59:59"}, + {12, "2020-07-15 23:59:59", "2020-07-15 23:59:59"}, + {13, "2020-08-15 13:14:15", "2020-08-15 23:59:59"}, + {14, "2020-09-15 13:14:15", "2020-09-15 23:59:59"}, + {15, "2020-10-15", "2020-10-15 23:59:59"}, + {16, "2020-11-15", "2020-11-15 23:59:59"}, + {17, "2020-12-15", "2020-12-15 23:59:59"}, } for _, test := range tests { c := Parse(test.input).EndOfDay() assert.Nil(c.Error) - assert.Equal(c.ToDateTimeString(), test.output) + assert.Equal(c.ToDateTimeString(), test.output, "Current test id is "+strconv.Itoa(test.id)) } } @@ -442,33 +457,34 @@ func TestCarbon_StartOfHour(t *testing.T) { assert := assert.New(t) tests := []struct { + id int // 测试id input string // 输入值 output string // 期望输出值 }{ - {"", ""}, - {"0", ""}, - {"0000-00-00", ""}, - {"00:00:00", ""}, - {"0000-00-00 00:00:00", ""}, - - {"2020-01-15 00:00:00", "2020-01-15 00:00:00"}, - {"2020-02-15 00:00:00", "2020-02-15 00:00:00"}, - {"2020-03-15 00:00:00", "2020-03-15 00:00:00"}, - {"2020-04-15 23:59:59", "2020-04-15 23:00:00"}, - {"2020-05-15 23:59:59", "2020-05-15 23:00:00"}, - {"2020-06-15 23:59:59", "2020-06-15 23:00:00"}, - {"2020-07-15 23:59:59", "2020-07-15 23:00:00"}, - {"2020-08-15 13:14:15", "2020-08-15 13:00:00"}, - {"2020-09-15 13:14:15", "2020-09-15 13:00:00"}, - {"2020-10-15", "2020-10-15 00:00:00"}, - {"2020-11-15", "2020-11-15 00:00:00"}, - {"2020-12-15", "2020-12-15 00:00:00"}, + {1, "", ""}, + {2, "0", ""}, + {3, "0000-00-00", ""}, + {4, "00:00:00", ""}, + {5, "0000-00-00 00:00:00", ""}, + + {6, "2020-01-15 00:00:00", "2020-01-15 00:00:00"}, + {7, "2020-02-15 00:00:00", "2020-02-15 00:00:00"}, + {8, "2020-03-15 00:00:00", "2020-03-15 00:00:00"}, + {9, "2020-04-15 23:59:59", "2020-04-15 23:00:00"}, + {10, "2020-05-15 23:59:59", "2020-05-15 23:00:00"}, + {11, "2020-06-15 23:59:59", "2020-06-15 23:00:00"}, + {12, "2020-07-15 23:59:59", "2020-07-15 23:00:00"}, + {13, "2020-08-15 13:14:15", "2020-08-15 13:00:00"}, + {14, "2020-09-15 13:14:15", "2020-09-15 13:00:00"}, + {15, "2020-10-15", "2020-10-15 00:00:00"}, + {16, "2020-11-15", "2020-11-15 00:00:00"}, + {17, "2020-12-15", "2020-12-15 00:00:00"}, } for _, test := range tests { c := Parse(test.input).StartOfHour() assert.Nil(c.Error) - assert.Equal(c.ToDateTimeString(), test.output) + assert.Equal(c.ToDateTimeString(), test.output, "Current test id is "+strconv.Itoa(test.id)) } } @@ -476,33 +492,34 @@ func TestCarbon_EndOfHour(t *testing.T) { assert := assert.New(t) tests := []struct { + id int // 测试id input string // 输入值 output string // 期望输出值 }{ - {"", ""}, - {"0", ""}, - {"0000-00-00", ""}, - {"00:00:00", ""}, - {"0000-00-00 00:00:00", ""}, - - {"2020-01-15 00:00:00", "2020-01-15 00:59:59"}, - {"2020-02-15 00:00:00", "2020-02-15 00:59:59"}, - {"2020-03-15 00:00:00", "2020-03-15 00:59:59"}, - {"2020-04-15 23:59:59", "2020-04-15 23:59:59"}, - {"2020-05-15 23:59:59", "2020-05-15 23:59:59"}, - {"2020-06-15 23:59:59", "2020-06-15 23:59:59"}, - {"2020-07-15 23:59:59", "2020-07-15 23:59:59"}, - {"2020-08-15 13:14:15", "2020-08-15 13:59:59"}, - {"2020-09-15 13:14:15", "2020-09-15 13:59:59"}, - {"2020-10-15", "2020-10-15 00:59:59"}, - {"2020-11-15", "2020-11-15 00:59:59"}, - {"2020-12-15", "2020-12-15 00:59:59"}, + {1, "", ""}, + {2, "0", ""}, + {3, "0000-00-00", ""}, + {4, "00:00:00", ""}, + {5, "0000-00-00 00:00:00", ""}, + + {6, "2020-01-15 00:00:00", "2020-01-15 00:59:59"}, + {7, "2020-02-15 00:00:00", "2020-02-15 00:59:59"}, + {8, "2020-03-15 00:00:00", "2020-03-15 00:59:59"}, + {9, "2020-04-15 23:59:59", "2020-04-15 23:59:59"}, + {10, "2020-05-15 23:59:59", "2020-05-15 23:59:59"}, + {11, "2020-06-15 23:59:59", "2020-06-15 23:59:59"}, + {12, "2020-07-15 23:59:59", "2020-07-15 23:59:59"}, + {13, "2020-08-15 13:14:15", "2020-08-15 13:59:59"}, + {14, "2020-09-15 13:14:15", "2020-09-15 13:59:59"}, + {15, "2020-10-15", "2020-10-15 00:59:59"}, + {16, "2020-11-15", "2020-11-15 00:59:59"}, + {17, "2020-12-15", "2020-12-15 00:59:59"}, } for _, test := range tests { c := Parse(test.input).EndOfHour() assert.Nil(c.Error) - assert.Equal(c.ToDateTimeString(), test.output) + assert.Equal(c.ToDateTimeString(), test.output, "Current test id is "+strconv.Itoa(test.id)) } } @@ -510,33 +527,34 @@ func TestCarbon_StartOfMinute(t *testing.T) { assert := assert.New(t) tests := []struct { + id int // 测试id input string // 输入值 output string // 期望输出值 }{ - {"", ""}, - {"0", ""}, - {"0000-00-00", ""}, - {"00:00:00", ""}, - {"0000-00-00 00:00:00", ""}, - - {"2020-01-15 00:00:00", "2020-01-15 00:00:00"}, - {"2020-02-15 00:00:00", "2020-02-15 00:00:00"}, - {"2020-03-15 00:00:00", "2020-03-15 00:00:00"}, - {"2020-04-15 23:59:59", "2020-04-15 23:59:00"}, - {"2020-05-15 23:59:59", "2020-05-15 23:59:00"}, - {"2020-06-15 23:59:59", "2020-06-15 23:59:00"}, - {"2020-07-15 23:59:59", "2020-07-15 23:59:00"}, - {"2020-08-15 13:14:15", "2020-08-15 13:14:00"}, - {"2020-09-15 13:14:15", "2020-09-15 13:14:00"}, - {"2020-10-15", "2020-10-15 00:00:00"}, - {"2020-11-15", "2020-11-15 00:00:00"}, - {"2020-12-15", "2020-12-15 00:00:00"}, + {1, "", ""}, + {2, "0", ""}, + {3, "0000-00-00", ""}, + {4, "00:00:00", ""}, + {5, "0000-00-00 00:00:00", ""}, + + {6, "2020-01-15 00:00:00", "2020-01-15 00:00:00"}, + {7, "2020-02-15 00:00:00", "2020-02-15 00:00:00"}, + {8, "2020-03-15 00:00:00", "2020-03-15 00:00:00"}, + {9, "2020-04-15 23:59:59", "2020-04-15 23:59:00"}, + {10, "2020-05-15 23:59:59", "2020-05-15 23:59:00"}, + {11, "2020-06-15 23:59:59", "2020-06-15 23:59:00"}, + {12, "2020-07-15 23:59:59", "2020-07-15 23:59:00"}, + {13, "2020-08-15 13:14:15", "2020-08-15 13:14:00"}, + {14, "2020-09-15 13:14:15", "2020-09-15 13:14:00"}, + {15, "2020-10-15", "2020-10-15 00:00:00"}, + {16, "2020-11-15", "2020-11-15 00:00:00"}, + {17, "2020-12-15", "2020-12-15 00:00:00"}, } for _, test := range tests { c := Parse(test.input).StartOfMinute() assert.Nil(c.Error) - assert.Equal(c.ToDateTimeString(), test.output) + assert.Equal(c.ToDateTimeString(), test.output, "Current test id is "+strconv.Itoa(test.id)) } } @@ -544,33 +562,34 @@ func TestCarbon_EndOfMinute(t *testing.T) { assert := assert.New(t) tests := []struct { + id int // 测试id input string // 输入值 output string // 期望输出值 }{ - {"", ""}, - {"0", ""}, - {"0000-00-00", ""}, - {"00:00:00", ""}, - {"0000-00-00 00:00:00", ""}, - - {"2020-01-15 00:00:00", "2020-01-15 00:00:59"}, - {"2020-02-15 00:00:00", "2020-02-15 00:00:59"}, - {"2020-03-15 00:00:00", "2020-03-15 00:00:59"}, - {"2020-04-15 23:59:59", "2020-04-15 23:59:59"}, - {"2020-05-15 23:59:59", "2020-05-15 23:59:59"}, - {"2020-06-15 23:59:59", "2020-06-15 23:59:59"}, - {"2020-07-15 23:59:59", "2020-07-15 23:59:59"}, - {"2020-08-15 13:14:15", "2020-08-15 13:14:59"}, - {"2020-09-15 13:14:15", "2020-09-15 13:14:59"}, - {"2020-10-15", "2020-10-15 00:00:59"}, - {"2020-11-15", "2020-11-15 00:00:59"}, - {"2020-12-15", "2020-12-15 00:00:59"}, + {1, "", ""}, + {2, "0", ""}, + {3, "0000-00-00", ""}, + {4, "00:00:00", ""}, + {5, "0000-00-00 00:00:00", ""}, + + {6, "2020-01-15 00:00:00", "2020-01-15 00:00:59"}, + {7, "2020-02-15 00:00:00", "2020-02-15 00:00:59"}, + {8, "2020-03-15 00:00:00", "2020-03-15 00:00:59"}, + {9, "2020-04-15 23:59:59", "2020-04-15 23:59:59"}, + {10, "2020-05-15 23:59:59", "2020-05-15 23:59:59"}, + {11, "2020-06-15 23:59:59", "2020-06-15 23:59:59"}, + {12, "2020-07-15 23:59:59", "2020-07-15 23:59:59"}, + {13, "2020-08-15 13:14:15", "2020-08-15 13:14:59"}, + {14, "2020-09-15 13:14:15", "2020-09-15 13:14:59"}, + {15, "2020-10-15", "2020-10-15 00:00:59"}, + {16, "2020-11-15", "2020-11-15 00:00:59"}, + {17, "2020-12-15", "2020-12-15 00:00:59"}, } for _, test := range tests { c := Parse(test.input).EndOfMinute() assert.Nil(c.Error) - assert.Equal(c.ToDateTimeString(), test.output) + assert.Equal(c.ToDateTimeString(), test.output, "Current test id is "+strconv.Itoa(test.id)) } } @@ -578,33 +597,34 @@ func TestCarbon_StartOfSecond(t *testing.T) { assert := assert.New(t) tests := []struct { + id int // 测试id input string // 输入值 output string // 期望输出值 }{ - {"", ""}, - {"0", ""}, - {"0000-00-00", ""}, - {"00:00:00", ""}, - {"0000-00-00 00:00:00", ""}, - - {"2020-01-15 00:00:00.123", "2020-01-15 00:00:00.0"}, - {"2020-02-15 00:00:00.123", "2020-02-15 00:00:00.0"}, - {"2020-03-15 00:00:00.123", "2020-03-15 00:00:00.0"}, - {"2020-04-15 23:59:59.123", "2020-04-15 23:59:59.0"}, - {"2020-05-15 23:59:59.123", "2020-05-15 23:59:59.0"}, - {"2020-06-15 23:59:59.123", "2020-06-15 23:59:59.0"}, - {"2020-07-15 23:59:59.123", "2020-07-15 23:59:59.0"}, - {"2020-08-15 13:14:15.123", "2020-08-15 13:14:15.0"}, - {"2020-09-15 13:14:15.123", "2020-09-15 13:14:15.0"}, - {"2020-10-15", "2020-10-15 00:00:00.0"}, - {"2020-11-15", "2020-11-15 00:00:00.0"}, - {"2020-12-15", "2020-12-15 00:00:00.0"}, + {1, "", ""}, + {2, "0", ""}, + {3, "0000-00-00", ""}, + {4, "00:00:00", ""}, + {5, "0000-00-00 00:00:00", ""}, + + {6, "2020-01-15 00:00:00.123", "2020-01-15 00:00:00.0"}, + {7, "2020-02-15 00:00:00.123", "2020-02-15 00:00:00.0"}, + {8, "2020-03-15 00:00:00.123", "2020-03-15 00:00:00.0"}, + {9, "2020-04-15 23:59:59.123", "2020-04-15 23:59:59.0"}, + {10, "2020-05-15 23:59:59.123", "2020-05-15 23:59:59.0"}, + {11, "2020-06-15 23:59:59.123", "2020-06-15 23:59:59.0"}, + {12, "2020-07-15 23:59:59.123", "2020-07-15 23:59:59.0"}, + {13, "2020-08-15 13:14:15.123", "2020-08-15 13:14:15.0"}, + {14, "2020-09-15 13:14:15.123", "2020-09-15 13:14:15.0"}, + {15, "2020-10-15", "2020-10-15 00:00:00.0"}, + {16, "2020-11-15", "2020-11-15 00:00:00.0"}, + {17, "2020-12-15", "2020-12-15 00:00:00.0"}, } for _, test := range tests { c := Parse(test.input).StartOfSecond() assert.Nil(c.Error) - assert.Equal(c.Format("Y-m-d H:i:s.u"), test.output) + assert.Equal(c.Format("Y-m-d H:i:s.u"), test.output, "Current test id is "+strconv.Itoa(test.id)) } } @@ -612,32 +632,33 @@ func TestCarbon_EndOfSecond(t *testing.T) { assert := assert.New(t) tests := []struct { + id int // 测试id input string // 输入值 output string // 期望输出值 }{ - {"", ""}, - {"0", ""}, - {"0000-00-00", ""}, - {"00:00:00", ""}, - {"0000-00-00 00:00:00", ""}, - - {"2020-01-15 00:00:00.123", "2020-01-15 00:00:00.999"}, - {"2020-02-15 00:00:00.123", "2020-02-15 00:00:00.999"}, - {"2020-03-15 00:00:00.123", "2020-03-15 00:00:00.999"}, - {"2020-04-15 23:59:59.123", "2020-04-15 23:59:59.999"}, - {"2020-05-15 23:59:59.123", "2020-05-15 23:59:59.999"}, - {"2020-06-15 23:59:59.123", "2020-06-15 23:59:59.999"}, - {"2020-07-15 23:59:59.123", "2020-07-15 23:59:59.999"}, - {"2020-08-15 13:14:15.123", "2020-08-15 13:14:15.999"}, - {"2020-09-15 13:14:15.123", "2020-09-15 13:14:15.999"}, - {"2020-10-15", "2020-10-15 00:00:00.999"}, - {"2020-11-15", "2020-11-15 00:00:00.999"}, - {"2020-12-15", "2020-12-15 00:00:00.999"}, + {1, "", ""}, + {2, "0", ""}, + {3, "0000-00-00", ""}, + {4, "00:00:00", ""}, + {5, "0000-00-00 00:00:00", ""}, + + {6, "2020-01-15 00:00:00.123", "2020-01-15 00:00:00.999"}, + {7, "2020-02-15 00:00:00.123", "2020-02-15 00:00:00.999"}, + {8, "2020-03-15 00:00:00.123", "2020-03-15 00:00:00.999"}, + {9, "2020-04-15 23:59:59.123", "2020-04-15 23:59:59.999"}, + {10, "2020-05-15 23:59:59.123", "2020-05-15 23:59:59.999"}, + {11, "2020-06-15 23:59:59.123", "2020-06-15 23:59:59.999"}, + {12, "2020-07-15 23:59:59.123", "2020-07-15 23:59:59.999"}, + {13, "2020-08-15 13:14:15.123", "2020-08-15 13:14:15.999"}, + {14, "2020-09-15 13:14:15.123", "2020-09-15 13:14:15.999"}, + {15, "2020-10-15", "2020-10-15 00:00:00.999"}, + {16, "2020-11-15", "2020-11-15 00:00:00.999"}, + {17, "2020-12-15", "2020-12-15 00:00:00.999"}, } for _, test := range tests { c := Parse(test.input).EndOfSecond() assert.Nil(c.Error) - assert.Equal(c.Format("Y-m-d H:i:s.u"), test.output) + assert.Equal(c.Format("Y-m-d H:i:s.u"), test.output, "Current test id is "+strconv.Itoa(test.id)) } }