1 Star 0 Fork 70

vdebug/carbon

forked from dromara/carbon 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
display_test.go 39.33 KB
一键复制 编辑 原始数据 按行查看 历史
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611
package carbon
import (
"fmt"
"strconv"
"testing"
"github.com/stretchr/testify/assert"
)
func TestCarbon_ToTimestamp(t *testing.T) {
assert := assert.New(t)
tests := []struct {
id int // 测试id
input string // 输入值
output int64 // 期望输出值
}{
{1, "", 0},
{2, "0", 0},
{3, "0000-00-00", 0},
{4, "00:00:00", 0},
{5, "0000-00-00 00:00:00", 0},
{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, "Current test id is "+strconv.Itoa(test.id))
}
}
func TestCarbon_ToTimestampWithSecond(t *testing.T) {
assert := assert.New(t)
tests := []struct {
id int // 测试id
input string // 输入值
output int64 // 期望输出值
}{
{1, "", 0},
{2, "0", 0},
{3, "0000-00-00", 0},
{4, "00:00:00", 0},
{5, "0000-00-00 00:00:00", 0},
{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, "Current test id is "+strconv.Itoa(test.id))
}
}
func TestCarbon_ToTimestampWithMillisecond(t *testing.T) {
assert := assert.New(t)
tests := []struct {
id int // 测试id
input string // 输入值
output int64 // 期望输出值
}{
{1, "", 0},
{2, "0", 0},
{3, "0000-00-00", 0},
{4, "00:00:00", 0},
{5, "0000-00-00 00:00:00", 0},
{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, "Current test id is "+strconv.Itoa(test.id))
}
}
func TestCarbon_ToTimestampWithMicrosecond(t *testing.T) {
assert := assert.New(t)
tests := []struct {
id int // 测试id
input string // 输入值
output int64 // 期望输出值
}{
{1, "", 0},
{2, "0", 0},
{3, "0000-00-00", 0},
{4, "00:00:00", 0},
{5, "0000-00-00 00:00:00", 0},
{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, "Current test id is "+strconv.Itoa(test.id))
}
}
func TestCarbon_ToTimestampWithNanosecond(t *testing.T) {
assert := assert.New(t)
tests := []struct {
id int // 测试id
input string // 输入值
output int64 // 期望输出值
}{
{1, "", 0},
{2, "0", 0},
{3, "0000-00-00", 0},
{4, "00:00:00", 0},
{5, "0000-00-00 00:00:00", 0},
{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, "Current test id is "+strconv.Itoa(test.id))
}
}
func TestCarbon_String(t *testing.T) {
assert := assert.New(t)
tests := []struct {
id int // 测试id
input string // 输入值
output string // 期望输出值
}{
{1, "", ""},
{2, "0", ""},
{3, "0000-00-00", ""},
{4, "00:00:00", ""},
{5, "0000-00-00 00:00:00", ""},
{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, "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 // 期望输出值
}{
{1, "", ""},
{2, "0", ""},
{3, "0000-00-00", ""},
{4, "00:00:00", ""},
{5, "0000-00-00 00:00:00", ""},
{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, "Current test id is "+strconv.Itoa(test.id))
}
}
func TestCarbon_ToUtcString(t *testing.T) {
assert := assert.New(t)
tests := []struct {
id int // 测试id
input string // 输入值
output string // 期望输出值
}{
{1, "", ""},
{2, "0", ""},
{3, "0000-00-00", ""},
{4, "00:00:00", ""},
{5, "0000-00-00 00:00:00", ""},
{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, "Current test id is "+strconv.Itoa(test.id))
}
}
func TestCarbon_ToMonthString1(t *testing.T) {
assert := assert.New(t)
tests := []struct {
id int // 测试id
input string // 输入值
output string // 期望输出值
}{
{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, "Current test id is "+strconv.Itoa(test.id))
}
}
func TestCarbon_ToMonthString2(t *testing.T) {
assert := assert.New(t)
tests := []struct {
id int // 测试id
input string // 输入值
param string // 参数值
output string // 期望输出值
}{
{1, "", "en", ""},
{2, "0", "en", ""},
{3, "0000-00-00", "en", ""},
{4, "00:00:00", "en", ""},
{5, "0000-00-00 00:00:00", "en", ""},
{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, "Current test id is "+strconv.Itoa(test.id))
}
}
func TestCarbon_ToShortMonthString1(t *testing.T) {
assert := assert.New(t)
tests := []struct {
id int // 测试id
input string // 输入值
output string // 期望输出值
}{
{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, "Current test id is "+strconv.Itoa(test.id))
}
}
func TestCarbon_ToShortMonthString2(t *testing.T) {
assert := assert.New(t)
tests := []struct {
id int // 测试id
input string // 输入值
param string // 参数值
output string // 期望输出值
}{
{1, "", "en", ""},
{2, "0", "en", ""},
{3, "0000-00-00", "en", ""},
{4, "00:00:00", "en", ""},
{5, "0000-00-00 00:00:00", "en", ""},
{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, "Current test id is "+strconv.Itoa(test.id))
}
}
func TestCarbon_ToWeekString1(t *testing.T) {
assert := assert.New(t)
tests := []struct {
id int // 测试id
input string // 输入值
output string // 期望输出值
}{
{1, "", ""},
{2, "0", ""},
{3, "0000-00-00", ""},
{4, "00:00:00", ""},
{5, "0000-00-00 00:00:00", ""},
{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, "Current test id is "+strconv.Itoa(test.id))
}
}
func TestCarbon_ToWeekString2(t *testing.T) {
assert := assert.New(t)
tests := []struct {
id int // 测试id
input string // 输入值
param string // 参数值
output string // 期望输出值
}{
{1, "", "en", ""},
{2, "0", "en", ""},
{3, "0000-00-00", "en", ""},
{4, "00:00:00", "en", ""},
{5, "0000-00-00 00:00:00", "en", ""},
{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, "Current test id is "+strconv.Itoa(test.id))
}
}
func TestCarbon_ToShortWeekString1(t *testing.T) {
assert := assert.New(t)
tests := []struct {
id int // 测试id
input string // 输入值
output string // 期望输出值
}{
{1, "", ""},
{2, "0", ""},
{3, "0000-00-00", ""},
{4, "00:00:00", ""},
{5, "0000-00-00 00:00:00", ""},
{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, "Current test id is "+strconv.Itoa(test.id))
}
}
func TestCarbon_ToShortWeekString2(t *testing.T) {
assert := assert.New(t)
tests := []struct {
id int // 测试id
input string // 输入值
param string // 参数值
output string // 期望输出值
}{
{1, "", "en", ""},
{2, "0", "en", ""},
{3, "0000-00-00", "en", ""},
{4, "00:00:00", "en", ""},
{5, "0000-00-00 00:00:00", "en", ""},
{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, "Current test id is "+strconv.Itoa(test.id))
}
}
func TestCarbon_ToFormatString(t *testing.T) {
assert := assert.New(t)
tests := []struct {
id int // 测试id
input string // 输入值
param string // 参数值
output string // 期望输出值
}{
{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, "Current test id is "+strconv.Itoa(test.id))
}
}
func TestCarbon_Format(t *testing.T) {
assert := assert.New(t)
tests := []struct {
id int // 测试id
input string // 输入值
param string // 参数值
output string // 期望输出值
}{
{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, "Current test id is "+strconv.Itoa(test.id))
}
}
func TestCarbon_ToDayDateTimeString(t *testing.T) {
assert := assert.New(t)
tests := []struct {
id int // 测试id
input string // 输入值
output string // 期望输出值
}{
{1, "", ""},
{2, "0", ""},
{3, "0000-00-00", ""},
{4, "00:00:00", ""},
{5, "0000-00-00 00:00:00", ""},
{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, "Current test id is "+strconv.Itoa(test.id))
}
}
func TestCarbon_ToDayDateTimeStringWithTimezone(t *testing.T) {
assert := assert.New(t)
tests := []struct {
id int // 测试id
input string // 输入值
output string // 期望输出值
}{
{1, "", ""},
{2, "0", ""},
{3, "0000-00-00", ""},
{4, "00:00:00", ""},
{5, "0000-00-00 00:00:00", ""},
{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, "Current test id is "+strconv.Itoa(test.id))
}
}
func TestCarbon_ToDateTimeString(t *testing.T) {
assert := assert.New(t)
tests := []struct {
id int // 测试id
input string // 输入值
output string // 期望输出值
}{
{1, "", ""},
{2, "0", ""},
{3, "0000-00-00", ""},
{4, "00:00:00", ""},
{5, "0000-00-00 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, "Current test id is "+strconv.Itoa(test.id))
}
}
func TestCarbon_ToDateTimeStringWithTimezone(t *testing.T) {
assert := assert.New(t)
tests := []struct {
id int // 测试id
input string // 输入值
output string // 期望输出值
}{
{1, "", ""},
{2, "0", ""},
{3, "0000-00-00", ""},
{4, "00:00:00", ""},
{5, "0000-00-00 00: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, "Current test id is "+strconv.Itoa(test.id))
}
}
func TestCarbon_ToDateString(t *testing.T) {
assert := assert.New(t)
tests := []struct {
id int // 测试id
input string // 输入值
output string // 期望输出值
}{
{1, "", ""},
{2, "0", ""},
{3, "0000-00-00", ""},
{4, "00:00:00", ""},
{5, "0000-00-00 00:00:00", ""},
{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, "Current test id is "+strconv.Itoa(test.id))
}
}
func TestCarbon_ToDateStringWithTimezone(t *testing.T) {
assert := assert.New(t)
tests := []struct {
id int // 测试id
input string // 输入值
output string // 期望输出值
}{
{1, "", ""},
{2, "0", ""},
{3, "0000-00-00", ""},
{4, "00:00:00", ""},
{5, "0000-00-00 00:00:00", ""},
{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, "Current test id is "+strconv.Itoa(test.id))
}
}
func TestCarbon_ToTimeString(t *testing.T) {
assert := assert.New(t)
tests := []struct {
id int // 测试id
input string // 输入值
output string // 期望输出值
}{
{1, "", ""},
{2, "0", ""},
{3, "0000-00-00", ""},
{4, "00:00:00", ""},
{5, "0000-00-00 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, "Current test id is "+strconv.Itoa(test.id))
}
}
func TestCarbon_ToTimeStringWithTimezone(t *testing.T) {
assert := assert.New(t)
tests := []struct {
id int // 测试id
input string // 输入值
output string // 期望输出值
}{
{1, "", ""},
{2, "0", ""},
{3, "0000-00-00", ""},
{4, "00:00:00", ""},
{5, "0000-00-00 00: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, "Current test id is "+strconv.Itoa(test.id))
}
}
func TestCarbon_ToAtomString(t *testing.T) {
assert := assert.New(t)
tests := []struct {
id int // 测试id
input string // 输入值
output string // 期望输出值
}{
{1, "", ""},
{2, "0", ""},
{3, "0000-00-00", ""},
{4, "00:00:00", ""},
{5, "0000-00-00 00:00: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, "Current test id is "+strconv.Itoa(test.id))
}
}
func TestCarbon_ToAtomStringWithTimezone(t *testing.T) {
assert := assert.New(t)
tests := []struct {
id int // 测试id
input string // 输入值
output string // 期望输出值
}{
{1, "", ""},
{2, "0", ""},
{3, "0000-00-00", ""},
{4, "00:00:00", ""},
{5, "0000-00-00 00:00:00", ""},
{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, "Current test id is "+strconv.Itoa(test.id))
}
}
func TestCarbon_ToAnsicString(t *testing.T) {
assert := assert.New(t)
tests := []struct {
id int // 测试id
input string // 输入值
output string // 期望输出值
}{
{1, "", ""},
{2, "0", ""},
{3, "0000-00-00", ""},
{4, "00:00:00", ""},
{5, "0000-00-00 00:00:00", ""},
{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, "Current test id is "+strconv.Itoa(test.id))
}
}
func TestCarbon_ToAnsicStringWithTimezone(t *testing.T) {
assert := assert.New(t)
tests := []struct {
id int // 测试id
input string // 输入值
output string // 期望输出值
}{
{1, "", ""},
{2, "0", ""},
{3, "0000-00-00", ""},
{4, "00:00:00", ""},
{5, "0000-00-00 00:00:00", ""},
{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, "Current test id is "+strconv.Itoa(test.id))
}
}
func TestCarbon_ToCookieString(t *testing.T) {
assert := assert.New(t)
tests := []struct {
id int // 测试id
input string // 输入值
output string // 期望输出值
}{
{1, "", ""},
{2, "0", ""},
{3, "0000-00-00", ""},
{4, "00:00:00", ""},
{5, "0000-00-00 00:00:00", ""},
{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, "Current test id is "+strconv.Itoa(test.id))
}
}
func TestCarbon_ToCookieStringWithTimezone(t *testing.T) {
assert := assert.New(t)
tests := []struct {
id int // 测试id
input string // 输入值
output string // 期望输出值
}{
{1, "", ""},
{2, "0", ""},
{3, "0000-00-00", ""},
{4, "00:00:00", ""},
{5, "0000-00-00 00:00:00", ""},
{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, "Current test id is "+strconv.Itoa(test.id))
}
}
func TestCarbon_ToRssString(t *testing.T) {
assert := assert.New(t)
tests := []struct {
id int // 测试id
input string // 输入值
output string // 期望输出值
}{
{1, "", ""},
{2, "0", ""},
{3, "0000-00-00", ""},
{4, "00:00:00", ""},
{5, "0000-00-00 00:00:00", ""},
{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, "Current test id is "+strconv.Itoa(test.id))
}
}
func TestCarbon_ToRssStringWithTimezone(t *testing.T) {
assert := assert.New(t)
tests := []struct {
id int // 测试id
input string // 输入值
output string // 期望输出值
}{
{1, "", ""},
{2, "0", ""},
{3, "0000-00-00", ""},
{4, "00:00:00", ""},
{5, "0000-00-00 00:00:00", ""},
{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, "Current test id is "+strconv.Itoa(test.id))
}
}
func TestCarbon_ToW3cString(t *testing.T) {
assert := assert.New(t)
tests := []struct {
id int // 测试id
input string // 输入值
output string // 期望输出值
}{
{1, "", ""},
{2, "0", ""},
{3, "0000-00-00", ""},
{4, "00:00:00", ""},
{5, "0000-00-00 00:00: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, "Current test id is "+strconv.Itoa(test.id))
}
}
func TestCarbon_ToW3cStringWithTimezone(t *testing.T) {
assert := assert.New(t)
tests := []struct {
id int // 测试id
input string // 输入值
output string // 期望输出值
}{
{1, "", ""},
{2, "0", ""},
{3, "0000-00-00", ""},
{4, "00:00:00", ""},
{5, "0000-00-00 00:00:00", ""},
{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, "Current test id is "+strconv.Itoa(test.id))
}
}
func TestCarbon_ToUnixDateString(t *testing.T) {
assert := assert.New(t)
tests := []struct {
id int // 测试id
input string // 输入值
output string // 期望输出值
}{
{1, "", ""},
{2, "0", ""},
{3, "0000-00-00", ""},
{4, "00:00:00", ""},
{5, "0000-00-00 00:00:00", ""},
{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, "Current test id is "+strconv.Itoa(test.id))
}
}
func TestCarbon_ToUnixDateStringWithTimezone(t *testing.T) {
assert := assert.New(t)
tests := []struct {
id int // 测试id
input string // 输入值
output string // 期望输出值
}{
{1, "", ""},
{2, "0", ""},
{3, "0000-00-00", ""},
{4, "00:00:00", ""},
{5, "0000-00-00 00:00:00", ""},
{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, "Current test id is "+strconv.Itoa(test.id))
}
}
func TestCarbon_ToRubyDateString(t *testing.T) {
assert := assert.New(t)
tests := []struct {
id int // 测试id
input string // 输入值
output string // 期望输出值
}{
{1, "", ""},
{2, "0", ""},
{3, "0000-00-00", ""},
{4, "00:00:00", ""},
{5, "0000-00-00 00:00:00", ""},
{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, "Current test id is "+strconv.Itoa(test.id))
}
}
func TestCarbon_ToRubyDateStringWithTimezone(t *testing.T) {
assert := assert.New(t)
tests := []struct {
id int // 测试id
input string // 输入值
output string // 期望输出值
}{
{1, "", ""},
{2, "0", ""},
{3, "0000-00-00", ""},
{4, "00:00:00", ""},
{5, "0000-00-00 00:00:00", ""},
{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, "Current test id is "+strconv.Itoa(test.id))
}
}
func TestCarbon_ToKitchenString(t *testing.T) {
assert := assert.New(t)
tests := []struct {
id int // 测试id
input string // 输入值
output string // 期望输出值
}{
{1, "", ""},
{2, "0", ""},
{3, "0000-00-00", ""},
{4, "00:00:00", ""},
{5, "0000-00-00 00:00:00", ""},
{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, "Current test id is "+strconv.Itoa(test.id))
}
}
func TestCarbon_ToKitchenStringWithTimezone(t *testing.T) {
assert := assert.New(t)
tests := []struct {
id int // 测试id
input string // 输入值
output string // 期望输出值
}{
{1, "", ""},
{2, "0", ""},
{3, "0000-00-00", ""},
{4, "00:00:00", ""},
{5, "0000-00-00 00:00:00", ""},
{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, "Current test id is "+strconv.Itoa(test.id))
}
}
func TestCarbon_ToRfc822String(t *testing.T) {
assert := assert.New(t)
tests := []struct {
id int // 测试id
input string // 输入值
output string // 期望输出值
}{
{1, "", ""},
{2, "0", ""},
{3, "0000-00-00", ""},
{4, "00:00:00", ""},
{5, "0000-00-00 00:00:00", ""},
{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, "Current test id is "+strconv.Itoa(test.id))
}
}
func TestCarbon_ToRfc822StringWithTimezone(t *testing.T) {
assert := assert.New(t)
tests := []struct {
id int // 测试id
input string // 输入值
output string // 期望输出值
}{
{1, "", ""},
{2, "0", ""},
{3, "0000-00-00", ""},
{4, "00:00:00", ""},
{5, "0000-00-00 00:00:00", ""},
{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, "Current test id is "+strconv.Itoa(test.id))
}
}
func TestCarbon_ToRfc822zString(t *testing.T) {
assert := assert.New(t)
tests := []struct {
id int // 测试id
input string // 输入值
output string // 期望输出值
}{
{1, "", ""},
{2, "0", ""},
{3, "0000-00-00", ""},
{4, "00:00:00", ""},
{5, "0000-00-00 00:00:00", ""},
{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, "Current test id is "+strconv.Itoa(test.id))
}
}
func TestCarbon_ToRfc822zStringWithTimezone(t *testing.T) {
assert := assert.New(t)
tests := []struct {
id int // 测试id
input string // 输入值
output string // 期望输出值
}{
{1, "", ""},
{2, "0", ""},
{3, "0000-00-00", ""},
{4, "00:00:00", ""},
{5, "0000-00-00 00:00:00", ""},
{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, "Current test id is "+strconv.Itoa(test.id))
}
}
func TestCarbon_ToRfc850String(t *testing.T) {
assert := assert.New(t)
tests := []struct {
id int // 测试id
input string // 输入值
output string // 期望输出值
}{
{1, "", ""},
{2, "0", ""},
{3, "0000-00-00", ""},
{4, "00:00:00", ""},
{5, "0000-00-00 00:00:00", ""},
{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, "Current test id is "+strconv.Itoa(test.id))
}
}
func TestCarbon_ToRfc850StringWithTimezone(t *testing.T) {
assert := assert.New(t)
tests := []struct {
id int // 测试id
input string // 输入值
output string // 期望输出值
}{
{1, "", ""},
{2, "0", ""},
{3, "0000-00-00", ""},
{4, "00:00:00", ""},
{5, "0000-00-00 00:00:00", ""},
{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, "Current test id is "+strconv.Itoa(test.id))
}
}
func TestCarbon_ToRfc1036String(t *testing.T) {
assert := assert.New(t)
tests := []struct {
id int // 测试id
input string // 输入值
output string // 期望输出值
}{
{1, "", ""},
{2, "0", ""},
{3, "0000-00-00", ""},
{4, "00:00:00", ""},
{5, "0000-00-00 00:00:00", ""},
{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, "Current test id is "+strconv.Itoa(test.id))
}
}
func TestCarbon_ToRfc1036StringWithTimezone(t *testing.T) {
assert := assert.New(t)
tests := []struct {
id int // 测试id
input string // 输入值
output string // 期望输出值
}{
{1, "", ""},
{2, "0", ""},
{3, "0000-00-00", ""},
{4, "00:00:00", ""},
{5, "0000-00-00 00:00:00", ""},
{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, "Current test id is "+strconv.Itoa(test.id))
}
}
func TestCarbon_ToRfc1123String(t *testing.T) {
assert := assert.New(t)
tests := []struct {
id int // 测试id
input string // 输入值
output string // 期望输出值
}{
{1, "", ""},
{2, "0", ""},
{3, "0000-00-00", ""},
{4, "00:00:00", ""},
{5, "0000-00-00 00:00:00", ""},
{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, "Current test id is "+strconv.Itoa(test.id))
}
}
func TestCarbon_ToRfc1123StringWithTimezone(t *testing.T) {
assert := assert.New(t)
tests := []struct {
id int // 测试id
input string // 输入值
output string // 期望输出值
}{
{1, "", ""},
{2, "0", ""},
{3, "0000-00-00", ""},
{4, "00:00:00", ""},
{5, "0000-00-00 00:00:00", ""},
{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, "Current test id is "+strconv.Itoa(test.id))
}
}
func TestCarbon_ToRfc1123ZString(t *testing.T) {
assert := assert.New(t)
tests := []struct {
id int // 测试id
input string // 输入值
output string // 期望输出值
}{
{1, "", ""},
{2, "0", ""},
{3, "0000-00-00", ""},
{4, "00:00:00", ""},
{5, "0000-00-00 00:00:00", ""},
{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, "Current test id is "+strconv.Itoa(test.id))
}
}
func TestCarbon_ToRfc1123ZStringWithTimezone(t *testing.T) {
assert := assert.New(t)
tests := []struct {
id int // 测试id
input string // 输入值
output string // 期望输出值
}{
{1, "", ""},
{2, "0", ""},
{3, "0000-00-00", ""},
{4, "00:00:00", ""},
{5, "0000-00-00 00:00:00", ""},
{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, "Current test id is "+strconv.Itoa(test.id))
}
}
func TestCarbon_ToRfc2822String(t *testing.T) {
assert := assert.New(t)
tests := []struct {
id int // 测试id
input string // 输入值
output string // 期望输出值
}{
{1, "", ""},
{2, "0", ""},
{3, "0000-00-00", ""},
{4, "00:00:00", ""},
{5, "0000-00-00 00:00:00", ""},
{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, "Current test id is "+strconv.Itoa(test.id))
}
}
func TestCarbon_ToRfc2822StringWithTimezone(t *testing.T) {
assert := assert.New(t)
tests := []struct {
id int // 测试id
input string // 输入值
output string // 期望输出值
}{
{1, "", ""},
{2, "0", ""},
{3, "0000-00-00", ""},
{4, "00:00:00", ""},
{5, "0000-00-00 00:00:00", ""},
{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, "Current test id is "+strconv.Itoa(test.id))
}
}
func TestCarbon_ToRfc3339String(t *testing.T) {
assert := assert.New(t)
tests := []struct {
id int // 测试id
input string // 输入值
output string // 期望输出值
}{
{1, "", ""},
{2, "0", ""},
{3, "0000-00-00", ""},
{4, "00:00:00", ""},
{5, "0000-00-00 00:00: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, "Current test id is "+strconv.Itoa(test.id))
}
}
func TestCarbon_ToRfc3339StringWithTimezone(t *testing.T) {
assert := assert.New(t)
tests := []struct {
id int // 测试id
input string // 输入值
output string // 期望输出值
}{
{1, "", ""},
{2, "0", ""},
{3, "0000-00-00", ""},
{4, "00:00:00", ""},
{5, "0000-00-00 00:00:00", ""},
{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, "Current test id is "+strconv.Itoa(test.id))
}
}
func TestCarbon_ToRfc7231String(t *testing.T) {
assert := assert.New(t)
tests := []struct {
id int // 测试id
input string // 输入值
output string // 期望输出值
}{
{1, "", ""},
{2, "0", ""},
{3, "0000-00-00", ""},
{4, "00:00:00", ""},
{5, "0000-00-00 00:00:00", ""},
{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, "Current test id is "+strconv.Itoa(test.id))
}
}
func TestCarbon_ToRfc7231StringWithTimezone(t *testing.T) {
assert := assert.New(t)
tests := []struct {
id int // 测试id
input string // 输入值
output string // 期望输出值
}{
{1, "", ""},
{2, "0", ""},
{3, "0000-00-00", ""},
{4, "00:00:00", ""},
{5, "0000-00-00 00:00:00", ""},
{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, "Current test id is "+strconv.Itoa(test.id))
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/vdebug/carbon.git
git@gitee.com:vdebug/carbon.git
vdebug
carbon
carbon
master

搜索帮助