提升单元测试覆盖率

This commit is contained in:
Peleus 2024-01-07 20:03:45 +08:00
parent ff94772f00
commit 21747c4289
11 changed files with 700 additions and 423 deletions

View File

@ -7,6 +7,9 @@ func BenchmarkCarbon_IsDST(b *testing.B) {
for n := 0; n < b.N; n++ {
now.IsDST()
}
for n := 0; n < b.N; n++ {
NewCarbon().IsDST()
}
}
func BenchmarkCarbon_IsZero(b *testing.B) {
@ -14,6 +17,9 @@ func BenchmarkCarbon_IsZero(b *testing.B) {
for n := 0; n < b.N; n++ {
now.IsZero()
}
for n := 0; n < b.N; n++ {
NewCarbon().IsZero()
}
}
func BenchmarkCarbon_IsValid(b *testing.B) {
@ -21,6 +27,9 @@ func BenchmarkCarbon_IsValid(b *testing.B) {
for n := 0; n < b.N; n++ {
now.IsZero()
}
for n := 0; n < b.N; n++ {
NewCarbon().IsZero()
}
}
func BenchmarkCarbon_IsInvalid(b *testing.B) {
@ -28,6 +37,9 @@ func BenchmarkCarbon_IsInvalid(b *testing.B) {
for n := 0; n < b.N; n++ {
now.IsInvalid()
}
for n := 0; n < b.N; n++ {
NewCarbon().IsInvalid()
}
}
func BenchmarkCarbon_IsNow(b *testing.B) {
@ -35,6 +47,9 @@ func BenchmarkCarbon_IsNow(b *testing.B) {
for n := 0; n < b.N; n++ {
now.IsNow()
}
for n := 0; n < b.N; n++ {
NewCarbon().IsNow()
}
}
func BenchmarkCarbon_IsFuture(b *testing.B) {
@ -42,6 +57,9 @@ func BenchmarkCarbon_IsFuture(b *testing.B) {
for n := 0; n < b.N; n++ {
now.IsFuture()
}
for n := 0; n < b.N; n++ {
NewCarbon().IsFuture()
}
}
func BenchmarkCarbon_IsPast(b *testing.B) {
@ -49,6 +67,9 @@ func BenchmarkCarbon_IsPast(b *testing.B) {
for n := 0; n < b.N; n++ {
now.IsPast()
}
for n := 0; n < b.N; n++ {
NewCarbon().IsPast()
}
}
func BenchmarkCarbon_IsLeapYear(b *testing.B) {
@ -56,6 +77,9 @@ func BenchmarkCarbon_IsLeapYear(b *testing.B) {
for n := 0; n < b.N; n++ {
now.IsLeapYear()
}
for n := 0; n < b.N; n++ {
NewCarbon().IsLeapYear()
}
}
func BenchmarkCarbon_IsLongYear(b *testing.B) {
@ -63,6 +87,9 @@ func BenchmarkCarbon_IsLongYear(b *testing.B) {
for n := 0; n < b.N; n++ {
now.IsLongYear()
}
for n := 0; n < b.N; n++ {
NewCarbon().IsLongYear()
}
}
func BenchmarkCarbon_IsJanuary(b *testing.B) {
@ -70,6 +97,9 @@ func BenchmarkCarbon_IsJanuary(b *testing.B) {
for n := 0; n < b.N; n++ {
now.IsJanuary()
}
for n := 0; n < b.N; n++ {
NewCarbon().IsJanuary()
}
}
func BenchmarkCarbon_IsFebruary(b *testing.B) {
@ -77,6 +107,9 @@ func BenchmarkCarbon_IsFebruary(b *testing.B) {
for n := 0; n < b.N; n++ {
now.IsFebruary()
}
for n := 0; n < b.N; n++ {
NewCarbon().IsFebruary()
}
}
func BenchmarkCarbon_IsMarch(b *testing.B) {
@ -84,6 +117,9 @@ func BenchmarkCarbon_IsMarch(b *testing.B) {
for n := 0; n < b.N; n++ {
now.IsMarch()
}
for n := 0; n < b.N; n++ {
NewCarbon().IsMarch()
}
}
func BenchmarkCarbon_IsApril(b *testing.B) {
@ -91,6 +127,9 @@ func BenchmarkCarbon_IsApril(b *testing.B) {
for n := 0; n < b.N; n++ {
now.IsApril()
}
for n := 0; n < b.N; n++ {
NewCarbon().IsApril()
}
}
func BenchmarkCarbon_IsMay(b *testing.B) {
@ -98,6 +137,9 @@ func BenchmarkCarbon_IsMay(b *testing.B) {
for n := 0; n < b.N; n++ {
now.IsMay()
}
for n := 0; n < b.N; n++ {
NewCarbon().IsMay()
}
}
func BenchmarkCarbon_IsJune(b *testing.B) {
@ -105,6 +147,9 @@ func BenchmarkCarbon_IsJune(b *testing.B) {
for n := 0; n < b.N; n++ {
now.IsJune()
}
for n := 0; n < b.N; n++ {
NewCarbon().IsJune()
}
}
func BenchmarkCarbon_IsJuly(b *testing.B) {
@ -112,6 +157,9 @@ func BenchmarkCarbon_IsJuly(b *testing.B) {
for n := 0; n < b.N; n++ {
now.IsJuly()
}
for n := 0; n < b.N; n++ {
NewCarbon().IsJuly()
}
}
func BenchmarkCarbon_IsAugust(b *testing.B) {
@ -119,6 +167,9 @@ func BenchmarkCarbon_IsAugust(b *testing.B) {
for n := 0; n < b.N; n++ {
now.IsAugust()
}
for n := 0; n < b.N; n++ {
NewCarbon().IsAugust()
}
}
func BenchmarkCarbon_IsSeptember(b *testing.B) {
@ -126,6 +177,9 @@ func BenchmarkCarbon_IsSeptember(b *testing.B) {
for n := 0; n < b.N; n++ {
now.IsSeptember()
}
for n := 0; n < b.N; n++ {
NewCarbon().IsSeptember()
}
}
func BenchmarkCarbon_IsOctober(b *testing.B) {
@ -133,6 +187,9 @@ func BenchmarkCarbon_IsOctober(b *testing.B) {
for n := 0; n < b.N; n++ {
now.IsOctober()
}
for n := 0; n < b.N; n++ {
NewCarbon().IsOctober()
}
}
func BenchmarkCarbon_IsNovember(b *testing.B) {
@ -140,6 +197,9 @@ func BenchmarkCarbon_IsNovember(b *testing.B) {
for n := 0; n < b.N; n++ {
now.IsNovember()
}
for n := 0; n < b.N; n++ {
NewCarbon().IsNovember()
}
}
func BenchmarkCarbon_IsDecember(b *testing.B) {
@ -147,6 +207,9 @@ func BenchmarkCarbon_IsDecember(b *testing.B) {
for n := 0; n < b.N; n++ {
now.IsDecember()
}
for n := 0; n < b.N; n++ {
NewCarbon().IsDecember()
}
}
func BenchmarkCarbon_IsMonday(b *testing.B) {
@ -154,6 +217,9 @@ func BenchmarkCarbon_IsMonday(b *testing.B) {
for n := 0; n < b.N; n++ {
now.IsMonday()
}
for n := 0; n < b.N; n++ {
NewCarbon().IsMonday()
}
}
func BenchmarkCarbon_IsTuesday(b *testing.B) {
@ -161,6 +227,9 @@ func BenchmarkCarbon_IsTuesday(b *testing.B) {
for n := 0; n < b.N; n++ {
now.IsTuesday()
}
for n := 0; n < b.N; n++ {
NewCarbon().IsTuesday()
}
}
func BenchmarkCarbon_IsWednesday(b *testing.B) {
@ -168,6 +237,9 @@ func BenchmarkCarbon_IsWednesday(b *testing.B) {
for n := 0; n < b.N; n++ {
now.IsWednesday()
}
for n := 0; n < b.N; n++ {
NewCarbon().IsWednesday()
}
}
func BenchmarkCarbon_IsThursday(b *testing.B) {
@ -175,6 +247,9 @@ func BenchmarkCarbon_IsThursday(b *testing.B) {
for n := 0; n < b.N; n++ {
now.IsThursday()
}
for n := 0; n < b.N; n++ {
NewCarbon().IsThursday()
}
}
func BenchmarkCarbon_IsFriday(b *testing.B) {
@ -182,6 +257,9 @@ func BenchmarkCarbon_IsFriday(b *testing.B) {
for n := 0; n < b.N; n++ {
now.IsFriday()
}
for n := 0; n < b.N; n++ {
NewCarbon().IsFriday()
}
}
func BenchmarkCarbon_IsSaturday(b *testing.B) {
@ -189,6 +267,9 @@ func BenchmarkCarbon_IsSaturday(b *testing.B) {
for n := 0; n < b.N; n++ {
now.IsSaturday()
}
for n := 0; n < b.N; n++ {
NewCarbon().IsSaturday()
}
}
func BenchmarkCarbon_IsSunday(b *testing.B) {
@ -196,6 +277,9 @@ func BenchmarkCarbon_IsSunday(b *testing.B) {
for n := 0; n < b.N; n++ {
now.IsSunday()
}
for n := 0; n < b.N; n++ {
NewCarbon().IsSunday()
}
}
func BenchmarkCarbon_IsWeekday(b *testing.B) {
@ -203,6 +287,9 @@ func BenchmarkCarbon_IsWeekday(b *testing.B) {
for n := 0; n < b.N; n++ {
now.IsWeekday()
}
for n := 0; n < b.N; n++ {
NewCarbon().IsWeekday()
}
}
func BenchmarkCarbon_IsWeekend(b *testing.B) {
@ -210,6 +297,9 @@ func BenchmarkCarbon_IsWeekend(b *testing.B) {
for n := 0; n < b.N; n++ {
now.IsWeekend()
}
for n := 0; n < b.N; n++ {
NewCarbon().IsWeekend()
}
}
func BenchmarkCarbon_IsYesterday(b *testing.B) {
@ -217,6 +307,9 @@ func BenchmarkCarbon_IsYesterday(b *testing.B) {
for n := 0; n < b.N; n++ {
now.IsYesterday()
}
for n := 0; n < b.N; n++ {
NewCarbon().IsYesterday()
}
}
func BenchmarkCarbon_IsToday(b *testing.B) {
@ -224,6 +317,9 @@ func BenchmarkCarbon_IsToday(b *testing.B) {
for n := 0; n < b.N; n++ {
now.IsToday()
}
for n := 0; n < b.N; n++ {
NewCarbon().IsToday()
}
}
func BenchmarkCarbon_IsTomorrow(b *testing.B) {
@ -231,6 +327,9 @@ func BenchmarkCarbon_IsTomorrow(b *testing.B) {
for n := 0; n < b.N; n++ {
now.IsTomorrow()
}
for n := 0; n < b.N; n++ {
NewCarbon().IsTomorrow()
}
}
func BenchmarkCarbon_IsSameCentury(b *testing.B) {
@ -238,6 +337,9 @@ func BenchmarkCarbon_IsSameCentury(b *testing.B) {
for n := 0; n < b.N; n++ {
now.IsSameCentury(Yesterday())
}
for n := 0; n < b.N; n++ {
NewCarbon().IsSameCentury(Yesterday())
}
}
func BenchmarkCarbon_IsSameDecade(b *testing.B) {
@ -245,6 +347,9 @@ func BenchmarkCarbon_IsSameDecade(b *testing.B) {
for n := 0; n < b.N; n++ {
now.IsSameDecade(Yesterday())
}
for n := 0; n < b.N; n++ {
NewCarbon().IsSameDecade(Yesterday())
}
}
func BenchmarkCarbon_IsSameYear(b *testing.B) {
@ -252,6 +357,9 @@ func BenchmarkCarbon_IsSameYear(b *testing.B) {
for n := 0; n < b.N; n++ {
now.IsSameYear(Yesterday())
}
for n := 0; n < b.N; n++ {
NewCarbon().IsSameYear(Yesterday())
}
}
func BenchmarkCarbon_IsSameQuarter(b *testing.B) {
@ -259,6 +367,9 @@ func BenchmarkCarbon_IsSameQuarter(b *testing.B) {
for n := 0; n < b.N; n++ {
now.IsSameQuarter(Yesterday())
}
for n := 0; n < b.N; n++ {
NewCarbon().IsSameQuarter(Yesterday())
}
}
func BenchmarkCarbon_IsSameMonth(b *testing.B) {
@ -266,6 +377,9 @@ func BenchmarkCarbon_IsSameMonth(b *testing.B) {
for n := 0; n < b.N; n++ {
now.IsSameMonth(Yesterday())
}
for n := 0; n < b.N; n++ {
NewCarbon().IsSameMonth(Yesterday())
}
}
func BenchmarkCarbon_IsSameDay(b *testing.B) {
@ -273,6 +387,9 @@ func BenchmarkCarbon_IsSameDay(b *testing.B) {
for n := 0; n < b.N; n++ {
now.IsSameDay(Yesterday())
}
for n := 0; n < b.N; n++ {
NewCarbon().IsSameDay(Yesterday())
}
}
func BenchmarkCarbon_IsSameHour(b *testing.B) {
@ -280,6 +397,9 @@ func BenchmarkCarbon_IsSameHour(b *testing.B) {
for n := 0; n < b.N; n++ {
now.IsSameHour(Yesterday())
}
for n := 0; n < b.N; n++ {
NewCarbon().IsSameHour(Yesterday())
}
}
func BenchmarkCarbon_IsSameMinute(b *testing.B) {
@ -287,6 +407,9 @@ func BenchmarkCarbon_IsSameMinute(b *testing.B) {
for n := 0; n < b.N; n++ {
now.IsSameMinute(Yesterday())
}
for n := 0; n < b.N; n++ {
NewCarbon().IsSameMinute(Yesterday())
}
}
func BenchmarkCarbon_IsSameSecond(b *testing.B) {
@ -294,6 +417,9 @@ func BenchmarkCarbon_IsSameSecond(b *testing.B) {
for n := 0; n < b.N; n++ {
now.IsSameSecond(Yesterday())
}
for n := 0; n < b.N; n++ {
NewCarbon().IsSameSecond(Yesterday())
}
}
func BenchmarkCarbon_Compare(b *testing.B) {
@ -301,6 +427,9 @@ func BenchmarkCarbon_Compare(b *testing.B) {
for n := 0; n < b.N; n++ {
now.Compare(">", Yesterday())
}
for n := 0; n < b.N; n++ {
NewCarbon().Compare(">", Yesterday())
}
}
func BenchmarkCarbon_Gt(b *testing.B) {
@ -308,6 +437,9 @@ func BenchmarkCarbon_Gt(b *testing.B) {
for n := 0; n < b.N; n++ {
now.Gt(Yesterday())
}
for n := 0; n < b.N; n++ {
NewCarbon().Gt(Yesterday())
}
}
func BenchmarkCarbon_Lt(b *testing.B) {
@ -315,6 +447,9 @@ func BenchmarkCarbon_Lt(b *testing.B) {
for n := 0; n < b.N; n++ {
now.Lt(Yesterday())
}
for n := 0; n < b.N; n++ {
NewCarbon().Lt(Yesterday())
}
}
func BenchmarkCarbon_Eq(b *testing.B) {
@ -322,6 +457,9 @@ func BenchmarkCarbon_Eq(b *testing.B) {
for n := 0; n < b.N; n++ {
now.Eq(Yesterday())
}
for n := 0; n < b.N; n++ {
NewCarbon().Eq(Yesterday())
}
}
func BenchmarkCarbon_Ne(b *testing.B) {
@ -329,6 +467,9 @@ func BenchmarkCarbon_Ne(b *testing.B) {
for n := 0; n < b.N; n++ {
now.Ne(Yesterday())
}
for n := 0; n < b.N; n++ {
NewCarbon().Ne(Yesterday())
}
}
func BenchmarkCarbon_Gte(b *testing.B) {
@ -336,6 +477,9 @@ func BenchmarkCarbon_Gte(b *testing.B) {
for n := 0; n < b.N; n++ {
now.Gte(Yesterday())
}
for n := 0; n < b.N; n++ {
NewCarbon().Gte(Yesterday())
}
}
func BenchmarkCarbon_Lte(b *testing.B) {
@ -343,6 +487,9 @@ func BenchmarkCarbon_Lte(b *testing.B) {
for n := 0; n < b.N; n++ {
now.Lte(Yesterday())
}
for n := 0; n < b.N; n++ {
NewCarbon().Lte(Yesterday())
}
}
func BenchmarkCarbon_Between(b *testing.B) {
@ -350,6 +497,9 @@ func BenchmarkCarbon_Between(b *testing.B) {
for n := 0; n < b.N; n++ {
now.Between(Tomorrow(), Yesterday())
}
for n := 0; n < b.N; n++ {
NewCarbon().Between(Tomorrow(), Yesterday())
}
}
func BenchmarkCarbon_BetweenIncludedStart(b *testing.B) {
@ -357,6 +507,9 @@ func BenchmarkCarbon_BetweenIncludedStart(b *testing.B) {
for n := 0; n < b.N; n++ {
now.BetweenIncludedStart(Tomorrow(), Yesterday())
}
for n := 0; n < b.N; n++ {
NewCarbon().BetweenIncludedStart(Tomorrow(), Yesterday())
}
}
func BenchmarkCarbon_BetweenIncludedEnd(b *testing.B) {
@ -364,6 +517,9 @@ func BenchmarkCarbon_BetweenIncludedEnd(b *testing.B) {
for n := 0; n < b.N; n++ {
now.BetweenIncludedEnd(Tomorrow(), Yesterday())
}
for n := 0; n < b.N; n++ {
NewCarbon().BetweenIncludedEnd(Tomorrow(), Yesterday())
}
}
func BenchmarkCarbon_BetweenIncludedBoth(b *testing.B) {
@ -371,4 +527,7 @@ func BenchmarkCarbon_BetweenIncludedBoth(b *testing.B) {
for n := 0; n < b.N; n++ {
now.BetweenIncludedBoth(Tomorrow(), Yesterday())
}
for n := 0; n < b.N; n++ {
NewCarbon().BetweenIncludedBoth(Tomorrow(), Yesterday())
}
}

View File

@ -9,100 +9,151 @@ func BenchmarkCarbon_CreateFromStdTime(b *testing.B) {
for n := 0; n < b.N; n++ {
CreateFromStdTime(time.Now())
}
for n := 0; n < b.N; n++ {
CreateFromStdTime(time.Now(), PRC)
}
}
func BenchmarkCarbon_CreateFromTimestamp(b *testing.B) {
for n := 0; n < b.N; n++ {
CreateFromTimestamp(1649735755)
}
for n := 0; n < b.N; n++ {
CreateFromTimestamp(1649735755, PRC)
}
}
func BenchmarkCarbon_CreateFromTimestampMilli(b *testing.B) {
for n := 0; n < b.N; n++ {
CreateFromTimestampMilli(1649735755981)
}
for n := 0; n < b.N; n++ {
CreateFromTimestampMilli(1649735755981, PRC)
}
}
func BenchmarkCarbon_CreateFromTimestampMicro(b *testing.B) {
for n := 0; n < b.N; n++ {
CreateFromTimestampMicro(1649735755981566)
}
for n := 0; n < b.N; n++ {
CreateFromTimestampMicro(1649735755981566, PRC)
}
}
func BenchmarkCarbon_CreateFromTimestampNano(b *testing.B) {
for n := 0; n < b.N; n++ {
CreateFromTimestampNano(1649735755981566000)
}
for n := 0; n < b.N; n++ {
CreateFromTimestampNano(1649735755981566000, PRC)
}
}
func BenchmarkCarbon_CreateFromDateTime(b *testing.B) {
for n := 0; n < b.N; n++ {
CreateFromDateTime(2020, 8, 5, 13, 14, 15)
}
for n := 0; n < b.N; n++ {
CreateFromDateTime(2020, 8, 5, 13, 14, 15, PRC)
}
}
func BenchmarkCarbon_CreateFromDateTimeMilli(b *testing.B) {
for n := 0; n < b.N; n++ {
CreateFromDateTimeMilli(2020, 8, 5, 13, 14, 15, 0)
}
for n := 0; n < b.N; n++ {
CreateFromDateTimeMilli(2020, 8, 5, 13, 14, 15, 0, PRC)
}
}
func BenchmarkCarbon_CreateFromDateTimeMicro(b *testing.B) {
for n := 0; n < b.N; n++ {
CreateFromDateTimeMicro(2020, 8, 5, 13, 14, 15, 0)
}
for n := 0; n < b.N; n++ {
CreateFromDateTimeMicro(2020, 8, 5, 13, 14, 15, 0, PRC)
}
}
func BenchmarkCarbon_CreateFromDateTimeNano(b *testing.B) {
for n := 0; n < b.N; n++ {
CreateFromDateTimeNano(2020, 8, 5, 13, 14, 15, 0)
}
for n := 0; n < b.N; n++ {
CreateFromDateTimeNano(2020, 8, 5, 13, 14, 15, 0, PRC)
}
}
func BenchmarkCarbon_CreateFromDate(b *testing.B) {
for n := 0; n < b.N; n++ {
CreateFromDate(2020, 8, 5)
}
for n := 0; n < b.N; n++ {
CreateFromDate(2020, 8, 5, PRC)
}
}
func BenchmarkCarbon_CreateFromDateMilli(b *testing.B) {
for n := 0; n < b.N; n++ {
CreateFromDateMilli(2020, 8, 5, 0)
}
for n := 0; n < b.N; n++ {
CreateFromDateMilli(2020, 8, 5, 0, PRC)
}
}
func BenchmarkCarbon_CreateFromDateMicro(b *testing.B) {
for n := 0; n < b.N; n++ {
CreateFromDateMicro(2020, 8, 5, 0)
}
for n := 0; n < b.N; n++ {
CreateFromDateMicro(2020, 8, 5, 0, PRC)
}
}
func BenchmarkCarbon_CreateFromDateNano(b *testing.B) {
for n := 0; n < b.N; n++ {
CreateFromDateNano(2020, 8, 5, 0)
}
for n := 0; n < b.N; n++ {
CreateFromDateNano(2020, 8, 5, 0, PRC)
}
}
func BenchmarkCarbon_CreateFromTime(b *testing.B) {
for n := 0; n < b.N; n++ {
CreateFromTime(13, 14, 15)
}
for n := 0; n < b.N; n++ {
CreateFromTime(13, 14, 15, PRC)
}
}
func BenchmarkCarbon_CreateFromTimeMilli(b *testing.B) {
for n := 0; n < b.N; n++ {
CreateFromTimeMilli(13, 14, 15, 0)
}
for n := 0; n < b.N; n++ {
CreateFromTimeMilli(13, 14, 15, 0, PRC)
}
}
func BenchmarkCarbon_CreateFromTimeMicro(b *testing.B) {
for n := 0; n < b.N; n++ {
CreateFromTimeMicro(13, 14, 15, 0)
}
for n := 0; n < b.N; n++ {
CreateFromTimeMicro(13, 14, 15, 0, PRC)
}
}
func BenchmarkCarbon_CreateFromTimeNano(b *testing.B) {
for n := 0; n < b.N; n++ {
CreateFromTimeNano(13, 14, 15, 0)
}
for n := 0; n < b.N; n++ {
CreateFromTimeNano(13, 14, 15, 0, PRC)
}
}

View File

@ -410,7 +410,7 @@ func TestCarbon_DiffInString(t *testing.T) {
func TestLangError_DiffInString(t *testing.T) {
lang := NewLanguage()
lang.SetLocale("xxx")
c := Now().SetLanguage(lang).AddMonths(1)
c := SetLanguage(lang).Now().AddMonths(1)
assert.NotNil(t, c.Error, "It should catch an exception in DiffInString()")
assert.Equal(t, "", c.DiffInString())
}
@ -471,7 +471,7 @@ func TestCarbon_DiffAbsInString(t *testing.T) {
func TestLangError_DiffAbsInString(t *testing.T) {
lang := NewLanguage()
lang.SetLocale("xxx")
c := Now().SetLanguage(lang).AddMonths(1)
c := SetLanguage(lang).Now().AddMonths(1)
assert.NotNil(t, c.Error, "It should catch an exception in DiffInStringWithAbs()")
assert.Equal(t, "", c.DiffAbsInString())
}
@ -526,7 +526,7 @@ func TestCarbon_DiffForHumans(t *testing.T) {
func TestLangError_DiffForHumans(t *testing.T) {
lang := NewLanguage()
lang.SetLocale("xxx")
c := Now().SetLanguage(lang).AddMonths(1)
c := SetLanguage(lang).Now().AddMonths(1)
assert.NotNil(t, c.Error, "It should catch an exception in DiffForHumans()")
assert.Equal(t, "", c.DiffForHumans())
}

View File

@ -12,381 +12,239 @@ type Person struct {
Name string `json:"name"`
Age int `json:"age"`
Birthday01 Carbon `json:"birthday01"`
Birthday02 Carbon `json:"birthday02" carbon:"type:dateTime"`
Birthday03 Carbon `json:"birthday03" tz:"PRC"`
Birthday04 Carbon `json:"birthday04" carbon:"" tz:""`
Birthday1 Carbon `json:"birthday1"`
Birthday2 Carbon `json:"birthday2" carbon:"type:dateTime"`
Birthday3 Carbon `json:"birthday3" tz:"PRC"`
Birthday4 Carbon `json:"birthday4" carbon:"" tz:""`
Birthday1 Carbon `json:"birthday1" carbon:"layout:2006-01-02"`
Birthday2 Carbon `json:"birthday2" carbon:"layout:15:04:05"`
Birthday3 Carbon `json:"birthday3" carbon:"layout:2006-01-02 15:04:05"`
Birthday4 Carbon `json:"birthday4" carbon:"layout:2006-01-02" tz:"PRC"`
Birthday5 Carbon `json:"birthday5" carbon:"layout:15:04:05" tz:"PRC"`
Birthday6 Carbon `json:"birthday6" carbon:"layout:2006-01-02 15:04:05" tz:"PRC"`
Birthday5 Carbon `json:"birthday5" carbon:"layout:2006-01-02" tz:"PRC"`
Birthday6 Carbon `json:"birthday6" carbon:"layout:15:04:05" tz:"PRC"`
Birthday7 Carbon `json:"birthday7" carbon:"layout:2006-01-02 15:04:05" tz:"PRC"`
Birthday7 Carbon `json:"birthday7" carbon:"format:Y-m-d"`
Birthday8 Carbon `json:"birthday8" carbon:"format:H:i:s"`
Birthday9 Carbon `json:"birthday9" carbon:"format:Y-m-d H:i:s"`
Birthday10 Carbon `json:"birthday10" carbon:"format:Y-m-d" tz:"PRC"`
Birthday11 Carbon `json:"birthday11" carbon:"format:H:i:s" tz:"PRC"`
Birthday12 Carbon `json:"birthday12" carbon:"format:Y-m-d H:i:s" tz:"PRC"`
Birthday8 Carbon `json:"birthday8" carbon:"format:Y-m-d" tz:"PRC"`
Birthday9 Carbon `json:"birthday9" carbon:"format:H:i:s" tz:"PRC"`
Birthday10 Carbon `json:"birthday10" carbon:"format:Y-m-d H:i:s" tz:"PRC"`
Birthday13 Carbon `json:"birthday13" carbon:"type:dateTime"`
Birthday14 Carbon `json:"birthday14" carbon:"type:dateTimeMilli"`
Birthday15 Carbon `json:"birthday15" carbon:"type:dateTimeMicro"`
Birthday16 Carbon `json:"birthday16" carbon:"type:dateTimeNano"`
Birthday17 Carbon `json:"birthday17" carbon:"type:shortDateTime"`
Birthday18 Carbon `json:"birthday18" carbon:"type:shortDateTimeMilli"`
Birthday19 Carbon `json:"birthday19" carbon:"type:shortDateTimeMicro"`
Birthday20 Carbon `json:"birthday20" carbon:"type:shortDateTimeNano"`
Birthday21 Carbon `json:"birthday21" carbon:"type:dayDateTime"`
Birthday22 Carbon `json:"birthday22" carbon:"type:date"`
Birthday23 Carbon `json:"birthday23" carbon:"type:dateMilli"`
Birthday24 Carbon `json:"birthday24" carbon:"type:dateMicro"`
Birthday25 Carbon `json:"birthday25" carbon:"type:dateNano"`
Birthday26 Carbon `json:"birthday26" carbon:"type:shortDate"`
Birthday27 Carbon `json:"birthday27" carbon:"type:shortDateMilli"`
Birthday28 Carbon `json:"birthday28" carbon:"type:shortDateMicro"`
Birthday29 Carbon `json:"birthday29" carbon:"type:shortDateNano"`
Birthday30 Carbon `json:"birthday30" carbon:"type:time"`
Birthday31 Carbon `json:"birthday31" carbon:"type:timeMilli"`
Birthday32 Carbon `json:"birthday32" carbon:"type:timeMicro"`
Birthday33 Carbon `json:"birthday33" carbon:"type:timeNano"`
Birthday34 Carbon `json:"birthday34" carbon:"type:shortTime"`
Birthday35 Carbon `json:"birthday35" carbon:"type:shortTimeMilli"`
Birthday36 Carbon `json:"birthday36" carbon:"type:shortTimeMicro"`
Birthday37 Carbon `json:"birthday37" carbon:"type:shortTimeNano"`
Birthday38 Carbon `json:"birthday38" carbon:"type:atom"`
Birthday39 Carbon `json:"birthday39" carbon:"type:ansic"`
Birthday40 Carbon `json:"birthday40" carbon:"type:cookie"`
Birthday41 Carbon `json:"birthday41" carbon:"type:kitchen"`
Birthday42 Carbon `json:"birthday42" carbon:"type:rss"`
Birthday43 Carbon `json:"birthday43" carbon:"type:rubyDate"`
Birthday44 Carbon `json:"birthday44" carbon:"type:unixDate"`
Birthday45 Carbon `json:"birthday45" carbon:"type:rfc1036"`
Birthday46 Carbon `json:"birthday46" carbon:"type:rfc1123"`
Birthday47 Carbon `json:"birthday47" carbon:"type:rfc1123Z"`
Birthday48 Carbon `json:"birthday48" carbon:"type:rfc2822"`
Birthday49 Carbon `json:"birthday49" carbon:"type:rfc3339"`
Birthday50 Carbon `json:"birthday50" carbon:"type:rfc3339Milli"`
Birthday51 Carbon `json:"birthday51" carbon:"type:rfc3339Micro"`
Birthday52 Carbon `json:"birthday52" carbon:"type:rfc3339Nano"`
Birthday53 Carbon `json:"birthday53" carbon:"type:rfc7231"`
Birthday54 Carbon `json:"birthday54" carbon:"type:rfc822"`
Birthday55 Carbon `json:"birthday55" carbon:"type:rfc822Z"`
Birthday56 Carbon `json:"birthday56" carbon:"type:rfc850"`
Birthday57 Carbon `json:"birthday57" carbon:"type:iso8601"`
Birthday58 Carbon `json:"birthday58" carbon:"type:iso8601Milli"`
Birthday59 Carbon `json:"birthday59" carbon:"type:iso8601Micro"`
Birthday60 Carbon `json:"birthday60" carbon:"type:iso8601Nano"`
Birthday11 Carbon `json:"birthday11" carbon:"type:date" tz:"PRC"`
Birthday12 Carbon `json:"birthday12" carbon:"type:time" tz:"PRC"`
Birthday13 Carbon `json:"birthday13" carbon:"type:dateTime" tz:"PRC"`
Birthday61 Carbon `json:"birthday61" carbon:"type:timestamp"`
Birthday62 Carbon `json:"birthday62" carbon:"type:timestampMilli"`
Birthday63 Carbon `json:"birthday63" carbon:"type:timestampMicro"`
Birthday64 Carbon `json:"birthday64" carbon:"type:timestampNano"`
}
var c = Parse("2020-08-05 13:14:15.999999999", PRC)
var person = Person{
Name: "gouguoyin",
Age: 18,
Birthday01: c,
Birthday02: c,
Birthday03: c,
Birthday04: c,
Birthday1: c,
Birthday2: c,
Birthday3: c,
Birthday4: c,
Birthday5: c,
Birthday6: c,
Birthday7: c,
Birthday8: c,
Birthday9: c,
Birthday10: c,
Birthday11: c,
Birthday12: c,
Birthday13: c,
Birthday14: c,
Birthday15: c,
Birthday16: c,
Birthday17: c,
Birthday18: c,
Birthday19: c,
Birthday20: c,
Birthday21: c,
Birthday22: c,
Birthday23: c,
Birthday24: c,
Birthday25: c,
Birthday26: c,
Birthday27: c,
Birthday28: c,
Birthday29: c,
Birthday30: c,
Birthday31: c,
Birthday32: c,
Birthday33: c,
Birthday34: c,
Birthday35: c,
Birthday36: c,
Birthday37: c,
Birthday38: c,
Birthday39: c,
Birthday40: c,
Birthday41: c,
Birthday42: c,
Birthday43: c,
Birthday44: c,
Birthday45: c,
Birthday46: c,
Birthday47: c,
Birthday48: c,
Birthday49: c,
Birthday50: c,
Birthday51: c,
Birthday52: c,
Birthday53: c,
Birthday54: c,
Birthday55: c,
Birthday56: c,
Birthday57: c,
Birthday58: c,
Birthday59: c,
Birthday60: c,
Birthday61: c,
Birthday62: c,
Birthday63: c,
Birthday64: c,
Birthday14 Carbon `json:"birthday14" carbon:"type:timestamp" tz:"PRC"`
Birthday15 Carbon `json:"birthday15" carbon:"type:timestampMilli" tz:"PRC"`
Birthday16 Carbon `json:"birthday16" carbon:"type:timestampMicro" tz:"PRC"`
Birthday17 Carbon `json:"birthday17" carbon:"type:timestampNano" tz:"PRC"`
}
func TestCarbon_MarshalJSON(t *testing.T) {
loadErr := LoadTag(&person)
assert.Nil(t, loadErr)
var c = Parse("2020-08-05 13:14:15.999999999", PRC)
var person = Person{
Name: "gouguoyin",
Age: 18,
Birthday1: c,
Birthday2: c,
Birthday3: c,
Birthday4: c,
Birthday5: c,
Birthday6: c,
Birthday7: c,
Birthday8: c,
Birthday9: c,
Birthday10: c,
Birthday11: c,
Birthday12: c,
Birthday13: c,
Birthday14: c,
Birthday15: c,
Birthday16: c,
Birthday17: c,
}
data, marshalErr := json.Marshal(&person)
assert.Nil(t, marshalErr)
assert.Equal(t, "2020-08-05 13:14:15", person.Birthday01.String())
assert.Equal(t, "2020-08-05 13:14:15", person.Birthday02.String())
assert.Equal(t, "2020-08-05 13:14:15", person.Birthday03.String())
assert.Equal(t, "2020-08-05 13:14:15", person.Birthday04.String())
assert.Equal(t, "2020-08-05", person.Birthday1.String())
assert.Equal(t, "13:14:15", person.Birthday2.String())
assert.Equal(t, "2020-08-05 13:14:15", person.Birthday1.String())
assert.Equal(t, "2020-08-05 13:14:15", person.Birthday2.String())
assert.Equal(t, "2020-08-05 13:14:15", person.Birthday3.String())
assert.Equal(t, "2020-08-05", person.Birthday4.String())
assert.Equal(t, "13:14:15", person.Birthday5.String())
assert.Equal(t, "2020-08-05 13:14:15", person.Birthday4.String())
assert.Equal(t, "2020-08-05 13:14:15", person.Birthday5.String())
assert.Equal(t, "2020-08-05 13:14:15", person.Birthday6.String())
assert.Equal(t, "2020-08-05", person.Birthday7.String())
assert.Equal(t, "13:14:15", person.Birthday8.String())
assert.Equal(t, "2020-08-05 13:14:15", person.Birthday7.String())
assert.Equal(t, "2020-08-05 13:14:15", person.Birthday8.String())
assert.Equal(t, "2020-08-05 13:14:15", person.Birthday9.String())
assert.Equal(t, "2020-08-05", person.Birthday10.String())
assert.Equal(t, "13:14:15", person.Birthday11.String())
assert.Equal(t, "2020-08-05 13:14:15", person.Birthday10.String())
assert.Equal(t, "2020-08-05 13:14:15", person.Birthday11.String())
assert.Equal(t, "2020-08-05 13:14:15", person.Birthday12.String())
assert.Equal(t, "2020-08-05 13:14:15", person.Birthday13.String())
assert.Equal(t, "2020-08-05 13:14:15.999", person.Birthday14.String())
assert.Equal(t, "2020-08-05 13:14:15.999999", person.Birthday15.String())
assert.Equal(t, "2020-08-05 13:14:15.999999999", person.Birthday16.String())
assert.Equal(t, "20200805131415", person.Birthday17.String())
assert.Equal(t, "20200805131415.999", person.Birthday18.String())
assert.Equal(t, "20200805131415.999999", person.Birthday19.String())
assert.Equal(t, "20200805131415.999999999", person.Birthday20.String())
assert.Equal(t, "Wed, Aug 5, 2020 1:14 PM", person.Birthday21.String())
assert.Equal(t, "2020-08-05", person.Birthday22.String())
assert.Equal(t, "2020-08-05.999", person.Birthday23.String())
assert.Equal(t, "2020-08-05.999999", person.Birthday24.String())
assert.Equal(t, "2020-08-05.999999999", person.Birthday25.String())
assert.Equal(t, "20200805", person.Birthday26.String())
assert.Equal(t, "20200805.999", person.Birthday27.String())
assert.Equal(t, "20200805.999999", person.Birthday28.String())
assert.Equal(t, "20200805.999999999", person.Birthday29.String())
assert.Equal(t, "13:14:15", person.Birthday30.String())
assert.Equal(t, "13:14:15.999", person.Birthday31.String())
assert.Equal(t, "13:14:15.999999", person.Birthday32.String())
assert.Equal(t, "13:14:15.999999999", person.Birthday33.String())
assert.Equal(t, "131415", person.Birthday34.String())
assert.Equal(t, "131415.999", person.Birthday35.String())
assert.Equal(t, "131415.999999", person.Birthday36.String())
assert.Equal(t, "131415.999999999", person.Birthday37.String())
assert.Equal(t, "2020-08-05T13:14:15+08:00", person.Birthday38.String())
assert.Equal(t, "Wed Aug 5 13:14:15 2020", person.Birthday39.String())
assert.Equal(t, "Wednesday, 05-Aug-2020 13:14:15 CST", person.Birthday40.String())
assert.Equal(t, "1:14PM", person.Birthday41.String())
assert.Equal(t, "Wed, 05 Aug 2020 13:14:15 +0800", person.Birthday42.String())
assert.Equal(t, "Wed Aug 05 13:14:15 +0800 2020", person.Birthday43.String())
assert.Equal(t, "Wed Aug 5 13:14:15 CST 2020", person.Birthday44.String())
assert.Equal(t, "Wed, 05 Aug 20 13:14:15 +0800", person.Birthday45.String())
assert.Equal(t, "Wed, 05 Aug 2020 13:14:15 CST", person.Birthday46.String())
assert.Equal(t, "Wed, 05 Aug 2020 13:14:15 +0800", person.Birthday47.String())
assert.Equal(t, "Wed, 05 Aug 2020 13:14:15 +0800", person.Birthday48.String())
assert.Equal(t, "2020-08-05T13:14:15+08:00", person.Birthday49.String())
assert.Equal(t, "2020-08-05T13:14:15.999+08:00", person.Birthday50.String())
assert.Equal(t, "2020-08-05T13:14:15.999999+08:00", person.Birthday51.String())
assert.Equal(t, "2020-08-05T13:14:15.999999999+08:00", person.Birthday52.String())
assert.Equal(t, "Wed, 05 Aug 2020 13:14:15 CST", person.Birthday53.String())
assert.Equal(t, "05 Aug 20 13:14 CST", person.Birthday54.String())
assert.Equal(t, "05 Aug 20 13:14 +0800", person.Birthday55.String())
assert.Equal(t, "Wednesday, 05-Aug-20 13:14:15 CST", person.Birthday56.String())
assert.Equal(t, "2020-08-05T13:14:15+08:00", person.Birthday57.String())
assert.Equal(t, "2020-08-05T13:14:15.999+08:00", person.Birthday58.String())
assert.Equal(t, "2020-08-05T13:14:15.999999+08:00", person.Birthday59.String())
assert.Equal(t, "2020-08-05T13:14:15.999999999+08:00", person.Birthday60.String())
assert.Equal(t, "1596604455", person.Birthday61.String())
assert.Equal(t, "1596604455999", person.Birthday62.String())
assert.Equal(t, "1596604455999999", person.Birthday63.String())
assert.Equal(t, "1596604455999999999", person.Birthday64.String())
assert.Equal(t, "2020-08-05 13:14:15", person.Birthday14.String())
assert.Equal(t, "2020-08-05 13:14:15", person.Birthday15.String())
assert.Equal(t, "2020-08-05 13:14:15", person.Birthday16.String())
assert.Equal(t, "2020-08-05 13:14:15", person.Birthday17.String())
fmt.Printf("person output by json:\n%s\n", data)
}
func TestCarbon_UnmarshalJSON(t *testing.T) {
str := `{
"name": "gouguoyin",
"age": 18,
"birthday01": "2020-08-05 13:14:15",
"birthday02": "2020-08-05 13:14:15",
"birthday03": "2020-08-05 13:14:15",
"birthday04": "2020-08-05 13:14:15",
"birthday1": "2020-08-05",
"birthday2": "13:14:15",
"birthday3": "2020-08-05 13:14:15",
"birthday4": "2020-08-05",
"birthday5": "13:14:15",
"birthday6": "2020-08-05 13:14:15",
"birthday7": "2020-08-05",
"birthday8": "13:14:15",
"birthday9": "2020-08-05 13:14:15",
"birthday10": "2020-08-05",
"birthday11": "13:14:15",
"birthday12": "2020-08-05 13:14:15",
"birthday13": "2020-08-05 13:14:15",
"birthday14": "2020-08-05 13:14:15.999",
"birthday15": "2020-08-05 13:14:15.999999",
"birthday16": "2020-08-05 13:14:15.999999999",
"birthday17": "20200805131415",
"birthday18": "20200805131415.999",
"birthday19": "20200805131415.999999",
"birthday20": "20200805131415.999999999",
"birthday21": "Wed, Aug 5, 2020 1:14 PM",
"birthday22": "2020-08-05",
"birthday23": "2020-08-05.999",
"birthday24": "2020-08-05.999999",
"birthday25": "2020-08-05.999999999",
"birthday26": "20200805",
"birthday27": "20200805.999",
"birthday28": "20200805.999999",
"birthday29": "20200805.999999999",
"birthday30": "13:14:15",
"birthday31": "13:14:15.999",
"birthday32": "13:14:15.999999",
"birthday33": "13:14:15.999999999",
"birthday34": "131415",
"birthday35": "131415.999",
"birthday36": "131415.999999",
"birthday37": "131415.999999999",
"birthday38": "2020-08-05T13:14:15+08:00",
"birthday39": "Wed Aug 5 13:14:15 2020",
"birthday40": "Wednesday, 05-Aug-2020 13:14:15 CST",
"birthday41": "1:14PM",
"birthday42": "Wed, 05 Aug 2020 13:14:15 +0800",
"birthday43": "Wed Aug 05 13:14:15 +0800 2020",
"birthday44": "Wed Aug 5 13:14:15 CST 2020",
"birthday45": "Wed, 05 Aug 20 13:14:15 +0800",
"birthday46": "Wed, 05 Aug 2020 13:14:15 CST",
"birthday47": "Wed, 05 Aug 2020 13:14:15 +0800",
"birthday48": "Wed, 05 Aug 2020 13:14:15 +0800",
"birthday49": "2020-08-05T13:14:15+08:00",
"birthday50": "2020-08-05T13:14:15.999+08:00",
"birthday51": "2020-08-05T13:14:15.999999+08:00",
"birthday52": "2020-08-05T13:14:15.999999999+08:00",
"birthday53": "Wed, 05 Aug 2020 13:14:15 CST",
"birthday54": "05 Aug 20 13:14 CST",
"birthday55": "05 Aug 20 13:14 +0800",
"birthday56": "Wednesday, 05-Aug-20 13:14:15 CST",
"birthday57": "2020-08-05T13:14:15+08:00",
"birthday58": "2020-08-05T13:14:15.999+08:00",
"birthday59": "2020-08-05T13:14:15.999999+08:00",
"birthday60": "2020-08-05T13:14:15.999999999+08:00",
"birthday61": 1596604455,
"birthday62": 1596604455999,
"birthday63": 1596604455999999,
"birthday64": 1596604455999999999
"name":"gouguoyin",
"age":18,
"birthday1":"2020-08-05 13:14:15",
"birthday2":"2020-08-05 13:14:15",
"birthday3":"2020-08-05 13:14:15",
"birthday4":"2020-08-05 13:14:15",
"birthday5":"2020-08-05 13:14:15",
"birthday6":"2020-08-05 13:14:15",
"birthday7":"2020-08-05 13:14:15",
"birthday8":"2020-08-05 13:14:15",
"birthday9":"2020-08-05 13:14:15",
"birthday10":"2020-08-05 13:14:15",
"birthday11":"2020-08-05 13:14:15",
"birthday12":"2020-08-05 13:14:15",
"birthday13":"2020-08-05 13:14:15",
"birthday14":"2020-08-05 13:14:15",
"birthday15":"2020-08-05 13:14:15",
"birthday16":"2020-08-05 13:14:15",
"birthday17":"2020-08-05 13:14:15"
}`
var person Person
unmarshalErr := json.Unmarshal([]byte(str), &person)
assert.Nil(t, unmarshalErr)
assert.Equal(t, "2020-08-05 13:14:15", person.Birthday1.String())
assert.Equal(t, "2020-08-05 13:14:15", person.Birthday2.String())
assert.Equal(t, "2020-08-05 13:14:15", person.Birthday3.String())
assert.Equal(t, "2020-08-05 13:14:15", person.Birthday4.String())
assert.Equal(t, "2020-08-05 13:14:15", person.Birthday5.String())
assert.Equal(t, "2020-08-05 13:14:15", person.Birthday6.String())
assert.Equal(t, "2020-08-05 13:14:15", person.Birthday7.String())
assert.Equal(t, "2020-08-05 13:14:15", person.Birthday8.String())
assert.Equal(t, "2020-08-05 13:14:15", person.Birthday9.String())
assert.Equal(t, "2020-08-05 13:14:15", person.Birthday10.String())
assert.Equal(t, "2020-08-05 13:14:15", person.Birthday11.String())
assert.Equal(t, "2020-08-05 13:14:15", person.Birthday12.String())
assert.Equal(t, "2020-08-05 13:14:15", person.Birthday13.String())
assert.Equal(t, "2020-08-05 13:14:15", person.Birthday14.String())
assert.Equal(t, "2020-08-05 13:14:15", person.Birthday15.String())
assert.Equal(t, "2020-08-05 13:14:15", person.Birthday16.String())
assert.Equal(t, "2020-08-05 13:14:15", person.Birthday17.String())
fmt.Printf("Json string parse to person:\n%+v\n", person)
}
func TestCarbon_MarshalJSON_LoadTag(t *testing.T) {
var c = Parse("2020-08-05 13:14:15.999999999", PRC)
var person = Person{
Name: "gouguoyin",
Age: 18,
Birthday1: c,
Birthday2: c,
Birthday3: c,
Birthday4: c,
Birthday5: c,
Birthday6: c,
Birthday7: c,
Birthday8: c,
Birthday9: c,
Birthday10: c,
Birthday11: c,
Birthday12: c,
Birthday13: c,
Birthday14: c,
Birthday15: c,
Birthday16: c,
Birthday17: c,
}
loadErr := LoadTag(&person)
assert.Nil(t, loadErr)
data, marshalErr := json.Marshal(&person)
assert.Nil(t, marshalErr)
assert.Equal(t, "2020-08-05 13:14:15", person.Birthday1.String())
assert.Equal(t, "2020-08-05 13:14:15", person.Birthday2.String())
assert.Equal(t, "2020-08-05 13:14:15", person.Birthday3.String())
assert.Equal(t, "2020-08-05 13:14:15", person.Birthday4.String())
assert.Equal(t, "2020-08-05", person.Birthday5.String())
assert.Equal(t, "13:14:15", person.Birthday6.String())
assert.Equal(t, "2020-08-05 13:14:15", person.Birthday7.String())
assert.Equal(t, "2020-08-05", person.Birthday8.String())
assert.Equal(t, "13:14:15", person.Birthday9.String())
assert.Equal(t, "2020-08-05 13:14:15", person.Birthday10.String())
assert.Equal(t, "2020-08-05", person.Birthday11.String())
assert.Equal(t, "13:14:15", person.Birthday12.String())
assert.Equal(t, "2020-08-05 13:14:15", person.Birthday13.String())
assert.Equal(t, "1596604455", person.Birthday14.String())
assert.Equal(t, "1596604455999", person.Birthday15.String())
assert.Equal(t, "1596604455999999", person.Birthday16.String())
assert.Equal(t, "1596604455999999999", person.Birthday17.String())
fmt.Printf("person output by json:\n%s\n", data)
}
func TestCarbon_UnmarshalJSON_LoadTag(t *testing.T) {
str := `{
"name":"gouguoyin",
"age":18,
"birthday1":"2020-08-05 13:14:15",
"birthday2":"2020-08-05 13:14:15",
"birthday3":"2020-08-05 13:14:15",
"birthday4":"2020-08-05 13:14:15",
"birthday5":"2020-08-05",
"birthday6":"13:14:15",
"birthday7":"2020-08-05 13:14:15",
"birthday8":"2020-08-05",
"birthday9":"13:14:15",
"birthday10":"2020-08-05 13:14:15",
"birthday11":"2020-08-05",
"birthday12":"13:14:15",
"birthday13":"2020-08-05 13:14:15",
"birthday14":"1596604455",
"birthday15":"1596604455999",
"birthday16":"1596604455999999",
"birthday17":"1596604455999999999"
}`
var person Person
loadErr := LoadTag(&person)
assert.Nil(t, loadErr)
unmarshalErr := json.Unmarshal([]byte(str), &person)
assert.Nil(t, unmarshalErr)
assert.Equal(t, "2020-08-05 13:14:15", person.Birthday01.String())
assert.Equal(t, "2020-08-05 13:14:15", person.Birthday02.String())
assert.Equal(t, "2020-08-05 13:14:15", person.Birthday03.String())
assert.Equal(t, "2020-08-05 13:14:15", person.Birthday04.String())
assert.Equal(t, "2020-08-05", person.Birthday1.String())
assert.Equal(t, "13:14:15", person.Birthday2.String())
assert.Equal(t, "2020-08-05 13:14:15", person.Birthday1.String())
assert.Equal(t, "2020-08-05 13:14:15", person.Birthday2.String())
assert.Equal(t, "2020-08-05 13:14:15", person.Birthday3.String())
assert.Equal(t, "2020-08-05", person.Birthday4.String())
assert.Equal(t, "13:14:15", person.Birthday5.String())
assert.Equal(t, "2020-08-05 13:14:15", person.Birthday6.String())
assert.Equal(t, "2020-08-05", person.Birthday7.String())
assert.Equal(t, "13:14:15", person.Birthday8.String())
assert.Equal(t, "2020-08-05 13:14:15", person.Birthday9.String())
assert.Equal(t, "2020-08-05", person.Birthday10.String())
assert.Equal(t, "13:14:15", person.Birthday11.String())
assert.Equal(t, "2020-08-05 13:14:15", person.Birthday12.String())
assert.Equal(t, "2020-08-05 13:14:15", person.Birthday4.String())
assert.Equal(t, "2020-08-05", person.Birthday5.String())
assert.Equal(t, "13:14:15", person.Birthday6.String())
assert.Equal(t, "2020-08-05 13:14:15", person.Birthday7.String())
assert.Equal(t, "2020-08-05", person.Birthday8.String())
assert.Equal(t, "13:14:15", person.Birthday9.String())
assert.Equal(t, "2020-08-05 13:14:15", person.Birthday10.String())
assert.Equal(t, "2020-08-05", person.Birthday11.String())
assert.Equal(t, "13:14:15", person.Birthday12.String())
assert.Equal(t, "2020-08-05 13:14:15", person.Birthday13.String())
assert.Equal(t, "2020-08-05 13:14:15.999", person.Birthday14.String())
assert.Equal(t, "2020-08-05 13:14:15.999999", person.Birthday15.String())
assert.Equal(t, "2020-08-05 13:14:15.999999999", person.Birthday16.String())
assert.Equal(t, "20200805131415", person.Birthday17.String())
assert.Equal(t, "20200805131415.999", person.Birthday18.String())
assert.Equal(t, "20200805131415.999999", person.Birthday19.String())
assert.Equal(t, "20200805131415.999999999", person.Birthday20.String())
assert.Equal(t, "Wed, Aug 5, 2020 1:14 PM", person.Birthday21.String())
assert.Equal(t, "2020-08-05", person.Birthday22.String())
assert.Equal(t, "2020-08-05.999", person.Birthday23.String())
assert.Equal(t, "2020-08-05.999999", person.Birthday24.String())
assert.Equal(t, "2020-08-05.999999999", person.Birthday25.String())
assert.Equal(t, "20200805", person.Birthday26.String())
assert.Equal(t, "20200805.999", person.Birthday27.String())
assert.Equal(t, "20200805.999999", person.Birthday28.String())
assert.Equal(t, "20200805.999999999", person.Birthday29.String())
assert.Equal(t, "13:14:15", person.Birthday30.String())
assert.Equal(t, "13:14:15.999", person.Birthday31.String())
assert.Equal(t, "13:14:15.999999", person.Birthday32.String())
assert.Equal(t, "13:14:15.999999999", person.Birthday33.String())
assert.Equal(t, "131415", person.Birthday34.String())
assert.Equal(t, "131415.999", person.Birthday35.String())
assert.Equal(t, "131415.999999", person.Birthday36.String())
assert.Equal(t, "131415.999999999", person.Birthday37.String())
assert.Equal(t, "2020-08-05T13:14:15+08:00", person.Birthday38.String())
assert.Equal(t, "Wed Aug 5 13:14:15 2020", person.Birthday39.String())
assert.Equal(t, "Wednesday, 05-Aug-2020 13:14:15 CST", person.Birthday40.String())
assert.Equal(t, "1:14PM", person.Birthday41.String())
assert.Equal(t, "Wed, 05 Aug 2020 13:14:15 +0800", person.Birthday42.String())
assert.Equal(t, "Wed Aug 05 13:14:15 +0800 2020", person.Birthday43.String())
assert.Equal(t, "Wed Aug 5 13:14:15 CST 2020", person.Birthday44.String())
assert.Equal(t, "Wed, 05 Aug 20 13:14:15 +0800", person.Birthday45.String())
assert.Equal(t, "Wed, 05 Aug 2020 13:14:15 CST", person.Birthday46.String())
assert.Equal(t, "Wed, 05 Aug 2020 13:14:15 +0800", person.Birthday47.String())
assert.Equal(t, "Wed, 05 Aug 2020 13:14:15 +0800", person.Birthday48.String())
assert.Equal(t, "2020-08-05T13:14:15+08:00", person.Birthday49.String())
assert.Equal(t, "2020-08-05T13:14:15.999+08:00", person.Birthday50.String())
assert.Equal(t, "2020-08-05T13:14:15.999999+08:00", person.Birthday51.String())
assert.Equal(t, "2020-08-05T13:14:15.999999999+08:00", person.Birthday52.String())
assert.Equal(t, "Wed, 05 Aug 2020 13:14:15 CST", person.Birthday53.String())
assert.Equal(t, "05 Aug 20 13:14 CST", person.Birthday54.String())
assert.Equal(t, "05 Aug 20 13:14 +0800", person.Birthday55.String())
assert.Equal(t, "Wednesday, 05-Aug-20 13:14:15 CST", person.Birthday56.String())
assert.Equal(t, "2020-08-05T13:14:15+08:00", person.Birthday57.String())
assert.Equal(t, "2020-08-05T13:14:15.999+08:00", person.Birthday58.String())
assert.Equal(t, "2020-08-05T13:14:15.999999+08:00", person.Birthday59.String())
assert.Equal(t, "2020-08-05T13:14:15.999999999+08:00", person.Birthday60.String())
assert.Equal(t, "1596604455", person.Birthday61.String())
assert.Equal(t, "1596604455999", person.Birthday62.String())
assert.Equal(t, "1596604455999999", person.Birthday63.String())
assert.Equal(t, "1596604455999999999", person.Birthday64.String())
assert.Equal(t, "1596604455", person.Birthday14.String())
assert.Equal(t, "1596604455999", person.Birthday15.String())
assert.Equal(t, "1596604455999999", person.Birthday16.String())
assert.Equal(t, "1596604455999999999", person.Birthday17.String())
fmt.Printf("Json string parse to person:\n%+v\n", person)
}

View File

@ -11,18 +11,18 @@ func TestLanguage_SetLocale(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input Carbon
input string
locale string
expected string
}{
0: {Now(), "en", "1 day after"},
1: {Tomorrow(), "zh-CN", "1 天后"},
0: {"now", "en", "1 day after"},
1: {"tomorrow", "zh-CN", "1 天后"},
}
for index, test := range tests {
lang := NewLanguage()
lang.SetLocale(test.locale)
assert.Equal(test.expected, (test.input).AddDays(1).SetLanguage(lang).DiffForHumans(test.input), "Current test index is "+strconv.Itoa(index))
assert.Equal(test.expected, SetLanguage(lang).Parse(test.input).AddDays(1).DiffForHumans(Parse(test.input)), "Current test index is "+strconv.Itoa(index))
}
}
@ -45,7 +45,7 @@ func TestLanguage_SetResources1(t *testing.T) {
"before": "%s before",
"after": "%s after",
}
lang.SetResources(resources)
lang.SetLocale("en").SetResources(resources)
tests := []struct {
input1 string
@ -84,12 +84,13 @@ func TestLanguage_SetResources1(t *testing.T) {
24: {"2020-08-05 13:14:15", "2020-08-05 13:14:05", "10s after"},
}
c := SetLanguage(lang)
for index, test := range tests {
c1 := Parse(test.input1)
c2 := Parse(test.input2)
c1 := c.Parse(test.input1)
c2 := c.Parse(test.input2)
assert.Nil(c1.Error)
assert.Nil(c2.Error)
assert.Equal(test.expected, c1.SetLanguage(lang).DiffForHumans(c2), "Current test index is "+strconv.Itoa(index))
assert.Equal(test.expected, c1.DiffForHumans(c2), "Current test index is "+strconv.Itoa(index))
}
}
@ -97,11 +98,11 @@ func TestLanguage_SetResources2(t *testing.T) {
assert := assert.New(t)
lang := NewLanguage()
resources := map[string]string{
"xxx": "xxx",
}
lang.SetResources(resources)
lang.SetLocale("en")
tests := []struct {
input string
@ -116,31 +117,33 @@ func TestLanguage_SetResources2(t *testing.T) {
5: {"2021-08-05 13:14:15", ""},
}
c := SetLanguage(lang)
for index, test := range tests {
assert.Equal(test.expected, Parse(test.input).SetLanguage(lang).DiffForHumans(), "Current test index is "+strconv.Itoa(index))
assert.Equal(test.expected, c.Parse(test.input).DiffForHumans(), "Current test index is "+strconv.Itoa(index))
}
for index, test := range tests {
assert.Equal(test.expected, Parse(test.input).SetLanguage(lang).Constellation(), "Current test index is "+strconv.Itoa(index))
assert.Equal(test.expected, c.Parse(test.input).Constellation(), "Current test index is "+strconv.Itoa(index))
}
for index, test := range tests {
assert.Equal(test.expected, Parse(test.input).SetLanguage(lang).Season(), "Current test index is "+strconv.Itoa(index))
assert.Equal(test.expected, c.Parse(test.input).Season(), "Current test index is "+strconv.Itoa(index))
}
for index, test := range tests {
assert.Equal(test.expected, Parse(test.input).SetLanguage(lang).ToWeekString(), "Current test index is "+strconv.Itoa(index))
assert.Equal(test.expected, c.Parse(test.input).ToWeekString(), "Current test index is "+strconv.Itoa(index))
}
for index, test := range tests {
assert.Equal(test.expected, Parse(test.input).SetLanguage(lang).ToShortWeekString(), "Current test index is "+strconv.Itoa(index))
assert.Equal(test.expected, c.Parse(test.input).ToShortWeekString(), "Current test index is "+strconv.Itoa(index))
}
for index, test := range tests {
assert.Equal(test.expected, Parse(test.input).SetLanguage(lang).ToMonthString(), "Current test index is "+strconv.Itoa(index))
assert.Equal(test.expected, c.Parse(test.input).ToMonthString(), "Current test index is "+strconv.Itoa(index))
}
for index, test := range tests {
assert.Equal(test.expected, Parse(test.input).SetLanguage(lang).ToShortMonthString(), "Current test index is "+strconv.Itoa(index))
assert.Equal(test.expected, c.Parse(test.input).ToShortMonthString(), "Current test index is "+strconv.Itoa(index))
}
}

View File

@ -29,6 +29,11 @@ func TestCarbon_String(t *testing.T) {
assert.Nil(c.Error)
assert.Equal(test.expected, fmt.Sprintf("%s", Parse(test.input)), "Current test index is "+strconv.Itoa(index))
}
c := Parse("2020-08-05", PRC).SetTag(&tag{
carbon: "xxx",
})
assert.Equal("2020-08-05 00:00:00", c.String())
}
func TestCarbon_ToString(t *testing.T) {

View File

@ -27,150 +27,150 @@ func BenchmarkCarbon_SetLocale(b *testing.B) {
func BenchmarkCarbon_SetLanguage(b *testing.B) {
lang := NewLanguage()
for n := 0; n < b.N; n++ {
c.SetLanguage(lang)
SetLanguage(lang)
}
}
func BenchmarkCarbon_SetDateTime(b *testing.B) {
for n := 0; n < b.N; n++ {
c.SetDateTime(2020, 8, 5, 0, 0, 0)
NewCarbon().SetDateTime(2020, 8, 5, 0, 0, 0)
}
}
func BenchmarkCarbon_SetDateTimeMilli(b *testing.B) {
for n := 0; n < b.N; n++ {
c.SetDateTimeMilli(2020, 8, 5, 0, 0, 0, 0)
NewCarbon().SetDateTimeMilli(2020, 8, 5, 0, 0, 0, 0)
}
}
func BenchmarkCarbon_SetDateTimeMicro(b *testing.B) {
for n := 0; n < b.N; n++ {
c.SetDateTimeMicro(2020, 8, 5, 0, 0, 0, 0)
NewCarbon().SetDateTimeMicro(2020, 8, 5, 0, 0, 0, 0)
}
}
func BenchmarkCarbon_SetDateTimeNano(b *testing.B) {
for n := 0; n < b.N; n++ {
c.SetDateTimeNano(2020, 8, 5, 0, 0, 0, 0)
NewCarbon().SetDateTimeNano(2020, 8, 5, 0, 0, 0, 0)
}
}
func BenchmarkCarbon_SetDate(b *testing.B) {
for n := 0; n < b.N; n++ {
c.SetDate(2020, 8, 5)
NewCarbon().SetDate(2020, 8, 5)
}
}
func BenchmarkCarbon_SetDateMilli(b *testing.B) {
for n := 0; n < b.N; n++ {
c.SetDateMilli(2020, 8, 5, 0)
NewCarbon().SetDateMilli(2020, 8, 5, 0)
}
}
func BenchmarkCarbon_SetDateMicro(b *testing.B) {
for n := 0; n < b.N; n++ {
c.SetDateMicro(2020, 8, 5, 0)
NewCarbon().SetDateMicro(2020, 8, 5, 0)
}
}
func BenchmarkCarbon_SetDateNano(b *testing.B) {
for n := 0; n < b.N; n++ {
c.SetDateNano(2020, 8, 5, 0)
NewCarbon().SetDateNano(2020, 8, 5, 0)
}
}
func BenchmarkCarbon_SetTime(b *testing.B) {
for n := 0; n < b.N; n++ {
c.SetTime(13, 14, 15)
NewCarbon().SetTime(13, 14, 15)
}
}
func BenchmarkCarbon_SetTimeMilli(b *testing.B) {
for n := 0; n < b.N; n++ {
c.SetTimeMilli(13, 14, 15, 0)
NewCarbon().SetTimeMilli(13, 14, 15, 0)
}
}
func BenchmarkCarbon_SetTimeMicro(b *testing.B) {
for n := 0; n < b.N; n++ {
c.SetTimeMicro(13, 14, 15, 0)
NewCarbon().SetTimeMicro(13, 14, 15, 0)
}
}
func BenchmarkCarbon_SetTimeNano(b *testing.B) {
for n := 0; n < b.N; n++ {
c.SetTimeNano(13, 14, 15, 0)
NewCarbon().SetTimeNano(13, 14, 15, 0)
}
}
func BenchmarkCarbon_SetYear(b *testing.B) {
for n := 0; n < b.N; n++ {
c.SetYear(2020)
NewCarbon().SetYear(2020)
}
}
func BenchmarkCarbon_SetYearNoOverflow(b *testing.B) {
for n := 0; n < b.N; n++ {
c.SetYearNoOverflow(2020)
NewCarbon().SetYearNoOverflow(2020)
}
}
func BenchmarkCarbon_SetMonth(b *testing.B) {
for n := 0; n < b.N; n++ {
c.SetMonth(8)
NewCarbon().SetMonth(8)
}
}
func BenchmarkCarbon_SetMonthNoOverflow(b *testing.B) {
for n := 0; n < b.N; n++ {
c.SetMonthNoOverflow(8)
NewCarbon().SetMonthNoOverflow(8)
}
}
func BenchmarkCarbon_SetWeekStartsAt(b *testing.B) {
for n := 0; n < b.N; n++ {
c.SetWeekStartsAt(Sunday)
NewCarbon().SetWeekStartsAt(Sunday)
}
}
func BenchmarkCarbon_SetDay(b *testing.B) {
for n := 0; n < b.N; n++ {
c.SetDay(20)
NewCarbon().SetDay(20)
}
}
func BenchmarkCarbon_SetHour(b *testing.B) {
for n := 0; n < b.N; n++ {
c.SetHour(20)
NewCarbon().SetHour(20)
}
}
func BenchmarkCarbon_SetMinute(b *testing.B) {
for n := 0; n < b.N; n++ {
c.SetMinute(20)
NewCarbon().SetMinute(20)
}
}
func BenchmarkCarbon_SetSecond(b *testing.B) {
for n := 0; n < b.N; n++ {
c.SetSecond(20)
NewCarbon().SetSecond(20)
}
}
func BenchmarkCarbon_SetMillisecond(b *testing.B) {
for n := 0; n < b.N; n++ {
c.SetMillisecond(20)
NewCarbon().SetMillisecond(20)
}
}
func BenchmarkCarbon_SetMicrosecond(b *testing.B) {
for n := 0; n < b.N; n++ {
c.SetMicrosecond(20)
NewCarbon().SetMicrosecond(20)
}
}
func BenchmarkCarbon_SetNanosecond(b *testing.B) {
for n := 0; n < b.N; n++ {
c.SetNanosecond(20)
NewCarbon().SetNanosecond(20)
}
}

View File

@ -85,39 +85,6 @@ func TestCarbon_SetLocale(t *testing.T) {
}
}
func TestCarbon_SetLanguage(t *testing.T) {
lang := NewLanguage()
resources := map[string]string{
"seasons": "spring|summer|autumn|winter",
}
lang.SetLocale("en")
if lang.Error == nil {
lang.SetResources(resources)
}
assert := assert.New(t)
tests := []struct {
input string
expected string
}{
{"", ""},
{"2020-08-05", "summer"},
}
for index, test := range tests {
c := Parse(test.input).SetLanguage(lang)
assert.Nil(c.Error)
assert.Equal(test.expected, c.Season(), "Current test index is "+strconv.Itoa(index))
}
for index, test := range tests {
c := SetLanguage(lang).Parse(test.input)
assert.Nil(c.Error)
assert.Equal(test.expected, c.Season(), "Current test index is "+strconv.Itoa(index))
}
}
func TestCarbon_SetDateTime(t *testing.T) {
assert := assert.New(t)
@ -630,7 +597,7 @@ func TestError_Setter(t *testing.T) {
lang := NewLanguage()
lang.SetLocale(locale)
assert.NotNil(t, c.SetLanguage(lang).Error, "It should catch an exception in SetLanguage()")
assert.NotNil(t, SetLanguage(lang).Error, "It should catch an exception in SetLanguage()")
assert.NotNil(t, c.SetDateTime(year, month, day, hour, minute, second).Error, "It should catch an exception in SetDateTime()")
assert.NotNil(t, c.SetDateTimeMilli(year, month, day, hour, minute, second, millisecond).Error, "It should catch an exception in SetDateTimeMilli()")

View File

@ -2,10 +2,10 @@ package carbon
import "testing"
func BenchmarkCarbon_SetTag(b *testing.B) {
func BenchmarkTag_SetTag(b *testing.B) {
now := Now()
for n := 0; n < b.N; n++ {
now.SetTag(tag{
now.SetTag(&tag{
carbon: "datetime",
tz: Local,
})

View File

@ -3,18 +3,21 @@ package carbon
import "testing"
func BenchmarkCarbon_SetTestNow(b *testing.B) {
c := NewCarbon()
for n := 0; n < b.N; n++ {
c.SetTestNow(Yesterday())
}
}
func BenchmarkCarbon_UnSetTestNow(b *testing.B) {
c := NewCarbon()
for n := 0; n < b.N; n++ {
c.UnSetTestNow()
}
}
func BenchmarkCarbon_IsSetTestNow(b *testing.B) {
c := NewCarbon()
for n := 0; n < b.N; n++ {
c.IsSetTestNow()
}

View File

@ -6,18 +6,27 @@ func BenchmarkCarbon_Now(b *testing.B) {
for n := 0; n < b.N; n++ {
Now()
}
for n := 0; n < b.N; n++ {
Now(PRC)
}
}
func BenchmarkCarbon_Yesterday(b *testing.B) {
for n := 0; n < b.N; n++ {
Yesterday()
}
for n := 0; n < b.N; n++ {
Yesterday(PRC)
}
}
func BenchmarkCarbon_Tomorrow(b *testing.B) {
for n := 0; n < b.N; n++ {
Tomorrow()
}
for n := 0; n < b.N; n++ {
Tomorrow(PRC)
}
}
func BenchmarkCarbon_AddDuration(b *testing.B) {
@ -25,6 +34,9 @@ func BenchmarkCarbon_AddDuration(b *testing.B) {
for n := 0; n < b.N; n++ {
now.AddDuration("1s")
}
for n := 0; n < b.N; n++ {
NewCarbon().AddDuration("1s")
}
}
func BenchmarkCarbon_SubDuration(b *testing.B) {
@ -32,6 +44,9 @@ func BenchmarkCarbon_SubDuration(b *testing.B) {
for n := 0; n < b.N; n++ {
now.SubDuration("1s")
}
for n := 0; n < b.N; n++ {
NewCarbon().SubDuration("1s")
}
}
func BenchmarkCarbon_AddCenturies(b *testing.B) {
@ -39,6 +54,9 @@ func BenchmarkCarbon_AddCenturies(b *testing.B) {
for n := 0; n < b.N; n++ {
now.AddCenturies(1)
}
for n := 0; n < b.N; n++ {
NewCarbon().AddCenturies(1)
}
}
func BenchmarkCarbon_AddCenturiesNoOverflow(b *testing.B) {
@ -46,6 +64,9 @@ func BenchmarkCarbon_AddCenturiesNoOverflow(b *testing.B) {
for n := 0; n < b.N; n++ {
now.AddCenturiesNoOverflow(1)
}
for n := 0; n < b.N; n++ {
NewCarbon().AddCenturiesNoOverflow(1)
}
}
func BenchmarkCarbon_AddCentury(b *testing.B) {
@ -53,6 +74,9 @@ func BenchmarkCarbon_AddCentury(b *testing.B) {
for n := 0; n < b.N; n++ {
now.AddCentury()
}
for n := 0; n < b.N; n++ {
NewCarbon().AddCentury()
}
}
func BenchmarkCarbon_AddCenturyNoOverflow(b *testing.B) {
@ -60,6 +84,9 @@ func BenchmarkCarbon_AddCenturyNoOverflow(b *testing.B) {
for n := 0; n < b.N; n++ {
now.AddCenturyNoOverflow()
}
for n := 0; n < b.N; n++ {
NewCarbon().AddCenturyNoOverflow()
}
}
func BenchmarkCarbon_SubCenturies(b *testing.B) {
@ -67,6 +94,9 @@ func BenchmarkCarbon_SubCenturies(b *testing.B) {
for n := 0; n < b.N; n++ {
now.SubCenturies(1)
}
for n := 0; n < b.N; n++ {
NewCarbon().SubCenturies(1)
}
}
func BenchmarkCarbon_SubCenturiesNoOverflow(b *testing.B) {
@ -74,6 +104,9 @@ func BenchmarkCarbon_SubCenturiesNoOverflow(b *testing.B) {
for n := 0; n < b.N; n++ {
now.SubCenturiesNoOverflow(1)
}
for n := 0; n < b.N; n++ {
NewCarbon().SubCenturiesNoOverflow(1)
}
}
func BenchmarkCarbon_SubCentury(b *testing.B) {
@ -81,6 +114,9 @@ func BenchmarkCarbon_SubCentury(b *testing.B) {
for n := 0; n < b.N; n++ {
now.SubCentury()
}
for n := 0; n < b.N; n++ {
NewCarbon().SubCentury()
}
}
func BenchmarkCarbon_SubCenturyNoOverflow(b *testing.B) {
@ -88,6 +124,9 @@ func BenchmarkCarbon_SubCenturyNoOverflow(b *testing.B) {
for n := 0; n < b.N; n++ {
now.SubCenturyNoOverflow()
}
for n := 0; n < b.N; n++ {
NewCarbon().SubCenturyNoOverflow()
}
}
func BenchmarkCarbon_AddDecades(b *testing.B) {
@ -95,6 +134,9 @@ func BenchmarkCarbon_AddDecades(b *testing.B) {
for n := 0; n < b.N; n++ {
now.AddDecades(1)
}
for n := 0; n < b.N; n++ {
NewCarbon().AddDecades(1)
}
}
func BenchmarkCarbon_AddDecadesNoOverflow(b *testing.B) {
@ -102,6 +144,9 @@ func BenchmarkCarbon_AddDecadesNoOverflow(b *testing.B) {
for n := 0; n < b.N; n++ {
now.AddDecadesNoOverflow(1)
}
for n := 0; n < b.N; n++ {
NewCarbon().AddDecadesNoOverflow(1)
}
}
func BenchmarkCarbon_AddDecade(b *testing.B) {
@ -109,6 +154,9 @@ func BenchmarkCarbon_AddDecade(b *testing.B) {
for n := 0; n < b.N; n++ {
now.AddDecade()
}
for n := 0; n < b.N; n++ {
NewCarbon().AddDecade()
}
}
func BenchmarkCarbon_AddDecadeNoOverflow(b *testing.B) {
@ -116,6 +164,9 @@ func BenchmarkCarbon_AddDecadeNoOverflow(b *testing.B) {
for n := 0; n < b.N; n++ {
now.AddDecadeNoOverflow()
}
for n := 0; n < b.N; n++ {
NewCarbon().AddDecadeNoOverflow()
}
}
func BenchmarkCarbon_SubDecades(b *testing.B) {
@ -123,6 +174,9 @@ func BenchmarkCarbon_SubDecades(b *testing.B) {
for n := 0; n < b.N; n++ {
now.SubDecades(1)
}
for n := 0; n < b.N; n++ {
NewCarbon().SubDecades(1)
}
}
func BenchmarkCarbon_SubDecadesNoOverflow(b *testing.B) {
@ -130,6 +184,9 @@ func BenchmarkCarbon_SubDecadesNoOverflow(b *testing.B) {
for n := 0; n < b.N; n++ {
now.SubDecadesNoOverflow(1)
}
for n := 0; n < b.N; n++ {
NewCarbon().SubDecadesNoOverflow(1)
}
}
func BenchmarkCarbon_SubDecade(b *testing.B) {
@ -137,6 +194,9 @@ func BenchmarkCarbon_SubDecade(b *testing.B) {
for n := 0; n < b.N; n++ {
now.SubDecade()
}
for n := 0; n < b.N; n++ {
NewCarbon().SubDecade()
}
}
func BenchmarkCarbon_SubDecadeNoOverflow(b *testing.B) {
@ -144,6 +204,9 @@ func BenchmarkCarbon_SubDecadeNoOverflow(b *testing.B) {
for n := 0; n < b.N; n++ {
now.SubDecadeNoOverflow()
}
for n := 0; n < b.N; n++ {
NewCarbon().SubDecadeNoOverflow()
}
}
func BenchmarkCarbon_AddYears(b *testing.B) {
@ -151,6 +214,9 @@ func BenchmarkCarbon_AddYears(b *testing.B) {
for n := 0; n < b.N; n++ {
now.AddYears(1)
}
for n := 0; n < b.N; n++ {
NewCarbon().AddYears(1)
}
}
func BenchmarkCarbon_AddYearsNoOverflow(b *testing.B) {
@ -158,6 +224,9 @@ func BenchmarkCarbon_AddYearsNoOverflow(b *testing.B) {
for n := 0; n < b.N; n++ {
now.AddYearsNoOverflow(1)
}
for n := 0; n < b.N; n++ {
NewCarbon().AddYearsNoOverflow(1)
}
}
func BenchmarkCarbon_AddYear(b *testing.B) {
@ -165,6 +234,9 @@ func BenchmarkCarbon_AddYear(b *testing.B) {
for n := 0; n < b.N; n++ {
now.AddYear()
}
for n := 0; n < b.N; n++ {
NewCarbon().AddYear()
}
}
func BenchmarkCarbon_AddYearNoOverflow(b *testing.B) {
@ -172,6 +244,9 @@ func BenchmarkCarbon_AddYearNoOverflow(b *testing.B) {
for n := 0; n < b.N; n++ {
now.AddYearNoOverflow()
}
for n := 0; n < b.N; n++ {
NewCarbon().AddYearNoOverflow()
}
}
func BenchmarkCarbon_SubYears(b *testing.B) {
@ -179,6 +254,9 @@ func BenchmarkCarbon_SubYears(b *testing.B) {
for n := 0; n < b.N; n++ {
now.SubYears(1)
}
for n := 0; n < b.N; n++ {
NewCarbon().SubYears(1)
}
}
func BenchmarkCarbon_SubYearsNoOverflow(b *testing.B) {
@ -186,6 +264,9 @@ func BenchmarkCarbon_SubYearsNoOverflow(b *testing.B) {
for n := 0; n < b.N; n++ {
now.SubYearsNoOverflow(1)
}
for n := 0; n < b.N; n++ {
NewCarbon().SubYearsNoOverflow(1)
}
}
func BenchmarkCarbon_SubYear(b *testing.B) {
@ -193,6 +274,9 @@ func BenchmarkCarbon_SubYear(b *testing.B) {
for n := 0; n < b.N; n++ {
now.SubYear()
}
for n := 0; n < b.N; n++ {
NewCarbon().SubYear()
}
}
func BenchmarkCarbon_SubYearNoOverflow(b *testing.B) {
@ -200,6 +284,9 @@ func BenchmarkCarbon_SubYearNoOverflow(b *testing.B) {
for n := 0; n < b.N; n++ {
now.SubYearNoOverflow()
}
for n := 0; n < b.N; n++ {
NewCarbon().SubYearNoOverflow()
}
}
func BenchmarkCarbon_AddQuarters(b *testing.B) {
@ -207,6 +294,9 @@ func BenchmarkCarbon_AddQuarters(b *testing.B) {
for n := 0; n < b.N; n++ {
now.AddQuarters(1)
}
for n := 0; n < b.N; n++ {
NewCarbon().AddQuarters(1)
}
}
func BenchmarkCarbon_AddQuartersNoOverflow(b *testing.B) {
@ -214,6 +304,9 @@ func BenchmarkCarbon_AddQuartersNoOverflow(b *testing.B) {
for n := 0; n < b.N; n++ {
now.AddQuartersNoOverflow(1)
}
for n := 0; n < b.N; n++ {
NewCarbon().AddQuartersNoOverflow(1)
}
}
func BenchmarkCarbon_AddQuarter(b *testing.B) {
@ -221,6 +314,9 @@ func BenchmarkCarbon_AddQuarter(b *testing.B) {
for n := 0; n < b.N; n++ {
now.AddQuarter()
}
for n := 0; n < b.N; n++ {
NewCarbon().AddQuarter()
}
}
func BenchmarkCarbon_AddQuarterNoOverflow(b *testing.B) {
@ -228,6 +324,9 @@ func BenchmarkCarbon_AddQuarterNoOverflow(b *testing.B) {
for n := 0; n < b.N; n++ {
now.AddQuarter()
}
for n := 0; n < b.N; n++ {
NewCarbon().AddQuarter()
}
}
func BenchmarkCarbon_SubQuarters(b *testing.B) {
@ -235,6 +334,9 @@ func BenchmarkCarbon_SubQuarters(b *testing.B) {
for n := 0; n < b.N; n++ {
now.SubQuarters(1)
}
for n := 0; n < b.N; n++ {
NewCarbon().SubQuarters(1)
}
}
func BenchmarkCarbon_SubQuartersNoOverflow(b *testing.B) {
@ -242,6 +344,9 @@ func BenchmarkCarbon_SubQuartersNoOverflow(b *testing.B) {
for n := 0; n < b.N; n++ {
now.SubQuartersNoOverflow(1)
}
for n := 0; n < b.N; n++ {
NewCarbon().SubQuartersNoOverflow(1)
}
}
func BenchmarkCarbon_SubQuarter(b *testing.B) {
@ -249,6 +354,9 @@ func BenchmarkCarbon_SubQuarter(b *testing.B) {
for n := 0; n < b.N; n++ {
now.SubQuarter()
}
for n := 0; n < b.N; n++ {
NewCarbon().SubQuarter()
}
}
func BenchmarkCarbon_SubQuarterNoOverflow(b *testing.B) {
@ -256,6 +364,9 @@ func BenchmarkCarbon_SubQuarterNoOverflow(b *testing.B) {
for n := 0; n < b.N; n++ {
now.SubQuarterNoOverflow()
}
for n := 0; n < b.N; n++ {
NewCarbon().SubQuarterNoOverflow()
}
}
func BenchmarkCarbon_AddMonths(b *testing.B) {
@ -263,6 +374,9 @@ func BenchmarkCarbon_AddMonths(b *testing.B) {
for n := 0; n < b.N; n++ {
now.AddMonths(1)
}
for n := 0; n < b.N; n++ {
NewCarbon().AddMonths(1)
}
}
func BenchmarkCarbon_AddMonthsNoOverflow(b *testing.B) {
@ -270,6 +384,9 @@ func BenchmarkCarbon_AddMonthsNoOverflow(b *testing.B) {
for n := 0; n < b.N; n++ {
now.AddMonthsNoOverflow(1)
}
for n := 0; n < b.N; n++ {
NewCarbon().AddMonthsNoOverflow(1)
}
}
func BenchmarkCarbon_AddMonth(b *testing.B) {
@ -277,6 +394,9 @@ func BenchmarkCarbon_AddMonth(b *testing.B) {
for n := 0; n < b.N; n++ {
now.AddMonth()
}
for n := 0; n < b.N; n++ {
NewCarbon().AddMonth()
}
}
func BenchmarkCarbon_AddMonthNoOverflow(b *testing.B) {
@ -284,6 +404,9 @@ func BenchmarkCarbon_AddMonthNoOverflow(b *testing.B) {
for n := 0; n < b.N; n++ {
now.AddMonthNoOverflow()
}
for n := 0; n < b.N; n++ {
NewCarbon().AddMonthNoOverflow()
}
}
func BenchmarkCarbon_SubMonths(b *testing.B) {
@ -291,6 +414,9 @@ func BenchmarkCarbon_SubMonths(b *testing.B) {
for n := 0; n < b.N; n++ {
now.SubMonths(1)
}
for n := 0; n < b.N; n++ {
NewCarbon().SubMonths(1)
}
}
func BenchmarkCarbon_SubMonthsNoOverflow(b *testing.B) {
@ -298,6 +424,9 @@ func BenchmarkCarbon_SubMonthsNoOverflow(b *testing.B) {
for n := 0; n < b.N; n++ {
now.SubMonthsNoOverflow(1)
}
for n := 0; n < b.N; n++ {
NewCarbon().SubMonthsNoOverflow(1)
}
}
func BenchmarkCarbon_SubMonth(b *testing.B) {
@ -305,6 +434,9 @@ func BenchmarkCarbon_SubMonth(b *testing.B) {
for n := 0; n < b.N; n++ {
now.SubMonth()
}
for n := 0; n < b.N; n++ {
NewCarbon().SubMonth()
}
}
func BenchmarkCarbon_SubMonthNoOverflow(b *testing.B) {
@ -312,6 +444,9 @@ func BenchmarkCarbon_SubMonthNoOverflow(b *testing.B) {
for n := 0; n < b.N; n++ {
now.SubMonthNoOverflow()
}
for n := 0; n < b.N; n++ {
NewCarbon().SubMonthNoOverflow()
}
}
func BenchmarkCarbon_AddWeeks(b *testing.B) {
@ -319,6 +454,9 @@ func BenchmarkCarbon_AddWeeks(b *testing.B) {
for n := 0; n < b.N; n++ {
now.AddWeeks(1)
}
for n := 0; n < b.N; n++ {
NewCarbon().AddWeeks(1)
}
}
func BenchmarkCarbon_AddWeek(b *testing.B) {
@ -326,6 +464,9 @@ func BenchmarkCarbon_AddWeek(b *testing.B) {
for n := 0; n < b.N; n++ {
now.AddWeek()
}
for n := 0; n < b.N; n++ {
NewCarbon().AddWeek()
}
}
func BenchmarkCarbon_SubWeeks(b *testing.B) {
@ -333,6 +474,9 @@ func BenchmarkCarbon_SubWeeks(b *testing.B) {
for n := 0; n < b.N; n++ {
now.SubWeeks(1)
}
for n := 0; n < b.N; n++ {
NewCarbon().SubWeeks(1)
}
}
func BenchmarkCarbon_SubWeek(b *testing.B) {
@ -340,6 +484,9 @@ func BenchmarkCarbon_SubWeek(b *testing.B) {
for n := 0; n < b.N; n++ {
now.SubWeek()
}
for n := 0; n < b.N; n++ {
NewCarbon().SubWeek()
}
}
func BenchmarkCarbon_AddDays(b *testing.B) {
@ -347,6 +494,9 @@ func BenchmarkCarbon_AddDays(b *testing.B) {
for n := 0; n < b.N; n++ {
now.AddDays(1)
}
for n := 0; n < b.N; n++ {
NewCarbon().AddDays(1)
}
}
func BenchmarkCarbon_AddDay(b *testing.B) {
@ -354,6 +504,9 @@ func BenchmarkCarbon_AddDay(b *testing.B) {
for n := 0; n < b.N; n++ {
now.AddDay()
}
for n := 0; n < b.N; n++ {
NewCarbon().AddDay()
}
}
func BenchmarkCarbon_SubDays(b *testing.B) {
@ -361,6 +514,9 @@ func BenchmarkCarbon_SubDays(b *testing.B) {
for n := 0; n < b.N; n++ {
now.SubDays(1)
}
for n := 0; n < b.N; n++ {
NewCarbon().SubDays(1)
}
}
func BenchmarkCarbon_SubDay(b *testing.B) {
@ -368,6 +524,9 @@ func BenchmarkCarbon_SubDay(b *testing.B) {
for n := 0; n < b.N; n++ {
now.SubDay()
}
for n := 0; n < b.N; n++ {
NewCarbon().SubDay()
}
}
func BenchmarkCarbon_AddHours(b *testing.B) {
@ -375,6 +534,9 @@ func BenchmarkCarbon_AddHours(b *testing.B) {
for n := 0; n < b.N; n++ {
now.AddHours(1)
}
for n := 0; n < b.N; n++ {
NewCarbon().AddHours(1)
}
}
func BenchmarkCarbon_AddHour(b *testing.B) {
@ -382,6 +544,9 @@ func BenchmarkCarbon_AddHour(b *testing.B) {
for n := 0; n < b.N; n++ {
now.AddHour()
}
for n := 0; n < b.N; n++ {
NewCarbon().AddHour()
}
}
func BenchmarkCarbon_SubHours(b *testing.B) {
@ -389,6 +554,9 @@ func BenchmarkCarbon_SubHours(b *testing.B) {
for n := 0; n < b.N; n++ {
now.SubHours(1)
}
for n := 0; n < b.N; n++ {
NewCarbon().SubHours(1)
}
}
func BenchmarkCarbon_SubHour(b *testing.B) {
@ -396,6 +564,9 @@ func BenchmarkCarbon_SubHour(b *testing.B) {
for n := 0; n < b.N; n++ {
now.SubHour()
}
for n := 0; n < b.N; n++ {
NewCarbon().SubHour()
}
}
func BenchmarkCarbon_AddMinutes(b *testing.B) {
@ -403,6 +574,9 @@ func BenchmarkCarbon_AddMinutes(b *testing.B) {
for n := 0; n < b.N; n++ {
now.AddMinutes(1)
}
for n := 0; n < b.N; n++ {
NewCarbon().AddMinutes(1)
}
}
func BenchmarkCarbon_AddMinute(b *testing.B) {
@ -410,6 +584,9 @@ func BenchmarkCarbon_AddMinute(b *testing.B) {
for n := 0; n < b.N; n++ {
now.AddMinute()
}
for n := 0; n < b.N; n++ {
NewCarbon().AddMinute()
}
}
func BenchmarkCarbon_SubMinutes(b *testing.B) {
@ -417,6 +594,9 @@ func BenchmarkCarbon_SubMinutes(b *testing.B) {
for n := 0; n < b.N; n++ {
now.SubMinutes(1)
}
for n := 0; n < b.N; n++ {
NewCarbon().SubMinutes(1)
}
}
func BenchmarkCarbon_SubMinute(b *testing.B) {
@ -424,6 +604,9 @@ func BenchmarkCarbon_SubMinute(b *testing.B) {
for n := 0; n < b.N; n++ {
now.SubMinute()
}
for n := 0; n < b.N; n++ {
NewCarbon().SubMinute()
}
}
func BenchmarkCarbon_AddSeconds(b *testing.B) {
@ -431,6 +614,9 @@ func BenchmarkCarbon_AddSeconds(b *testing.B) {
for n := 0; n < b.N; n++ {
now.AddSeconds(1)
}
for n := 0; n < b.N; n++ {
NewCarbon().AddSeconds(1)
}
}
func BenchmarkCarbon_AddSecond(b *testing.B) {
@ -438,6 +624,9 @@ func BenchmarkCarbon_AddSecond(b *testing.B) {
for n := 0; n < b.N; n++ {
now.AddSecond()
}
for n := 0; n < b.N; n++ {
NewCarbon().AddSecond()
}
}
func BenchmarkCarbon_SubSeconds(b *testing.B) {
@ -445,6 +634,9 @@ func BenchmarkCarbon_SubSeconds(b *testing.B) {
for n := 0; n < b.N; n++ {
now.SubSeconds(1)
}
for n := 0; n < b.N; n++ {
NewCarbon().SubSeconds(1)
}
}
func BenchmarkCarbon_SubSecond(b *testing.B) {
@ -452,6 +644,9 @@ func BenchmarkCarbon_SubSecond(b *testing.B) {
for n := 0; n < b.N; n++ {
now.SubSecond()
}
for n := 0; n < b.N; n++ {
NewCarbon().SubSecond()
}
}
func BenchmarkCarbon_AddMilliseconds(b *testing.B) {
@ -459,6 +654,9 @@ func BenchmarkCarbon_AddMilliseconds(b *testing.B) {
for n := 0; n < b.N; n++ {
now.AddMilliseconds(1)
}
for n := 0; n < b.N; n++ {
NewCarbon().AddMilliseconds(1)
}
}
func BenchmarkCarbon_AddMillisecond(b *testing.B) {
@ -466,6 +664,9 @@ func BenchmarkCarbon_AddMillisecond(b *testing.B) {
for n := 0; n < b.N; n++ {
now.AddMillisecond()
}
for n := 0; n < b.N; n++ {
NewCarbon().AddMillisecond()
}
}
func BenchmarkCarbon_SubMilliseconds(b *testing.B) {
@ -473,6 +674,9 @@ func BenchmarkCarbon_SubMilliseconds(b *testing.B) {
for n := 0; n < b.N; n++ {
now.SubMilliseconds(1)
}
for n := 0; n < b.N; n++ {
NewCarbon().SubMilliseconds(1)
}
}
func BenchmarkCarbon_SubMillisecond(b *testing.B) {
@ -480,6 +684,9 @@ func BenchmarkCarbon_SubMillisecond(b *testing.B) {
for n := 0; n < b.N; n++ {
now.SubMillisecond()
}
for n := 0; n < b.N; n++ {
NewCarbon().SubMillisecond()
}
}
func BenchmarkCarbon_AddMicroseconds(b *testing.B) {
@ -487,6 +694,9 @@ func BenchmarkCarbon_AddMicroseconds(b *testing.B) {
for n := 0; n < b.N; n++ {
now.AddMicroseconds(1)
}
for n := 0; n < b.N; n++ {
NewCarbon().AddMicroseconds(1)
}
}
func BenchmarkCarbon_AddMicrosecond(b *testing.B) {
@ -494,6 +704,9 @@ func BenchmarkCarbon_AddMicrosecond(b *testing.B) {
for n := 0; n < b.N; n++ {
now.AddMicrosecond()
}
for n := 0; n < b.N; n++ {
NewCarbon().AddMicrosecond()
}
}
func BenchmarkCarbon_SubMicroseconds(b *testing.B) {
@ -501,6 +714,9 @@ func BenchmarkCarbon_SubMicroseconds(b *testing.B) {
for n := 0; n < b.N; n++ {
now.SubMicroseconds(1)
}
for n := 0; n < b.N; n++ {
NewCarbon().SubMicroseconds(1)
}
}
func BenchmarkCarbon_SubMicrosecond(b *testing.B) {
@ -508,6 +724,9 @@ func BenchmarkCarbon_SubMicrosecond(b *testing.B) {
for n := 0; n < b.N; n++ {
now.SubMicrosecond()
}
for n := 0; n < b.N; n++ {
NewCarbon().SubMicrosecond()
}
}
func BenchmarkCarbon_AddNanoseconds(b *testing.B) {
@ -515,6 +734,9 @@ func BenchmarkCarbon_AddNanoseconds(b *testing.B) {
for n := 0; n < b.N; n++ {
now.AddNanoseconds(1)
}
for n := 0; n < b.N; n++ {
NewCarbon().AddNanoseconds(1)
}
}
func BenchmarkCarbon_AddNanosecond(b *testing.B) {
@ -522,6 +744,9 @@ func BenchmarkCarbon_AddNanosecond(b *testing.B) {
for n := 0; n < b.N; n++ {
now.AddNanosecond()
}
for n := 0; n < b.N; n++ {
NewCarbon().AddNanosecond()
}
}
func BenchmarkCarbon_SubNanoseconds(b *testing.B) {
@ -529,6 +754,9 @@ func BenchmarkCarbon_SubNanoseconds(b *testing.B) {
for n := 0; n < b.N; n++ {
now.SubNanoseconds(1)
}
for n := 0; n < b.N; n++ {
NewCarbon().SubNanoseconds(1)
}
}
func BenchmarkCarbon_SubNanosecond(b *testing.B) {
@ -536,4 +764,7 @@ func BenchmarkCarbon_SubNanosecond(b *testing.B) {
for n := 0; n < b.N; n++ {
now.SubNanosecond()
}
for n := 0; n < b.N; n++ {
NewCarbon().SubNanosecond()
}
}