mirror of
https://gitee.com/dromara/carbon.git
synced 2024-11-29 18:57:37 +08:00
新增 GoString
,ToIso8601ZuluString
,ToIso8601ZuluMilliString
,ToIso8601ZuluMicroString
,ToIso8601ZuluNanoString
方法
This commit is contained in:
parent
9ea513ad01
commit
4454eb844a
20
README.cn.md
20
README.cn.md
@ -62,8 +62,7 @@ carbon.SetDefault(carbon.Default{
|
||||
Locale: "zh-CN",
|
||||
})
|
||||
```
|
||||
|
||||
> 如果没有设置,默认布局模板是 `2006-01-02 15:04:05`, 默认时区是 `Local`, 默认一周开始日期是 `Sunday(周日)`, 默认语言是 `en`
|
||||
> 建议在入口文件如 `main.go` 中设置
|
||||
|
||||
##### `Carbon` 和 `time.Time` 互转
|
||||
|
||||
@ -1093,6 +1092,14 @@ carbon.Parse("2020-08-05 13:14:15.999999999").ToIso8601MilliString() // 2020-08-
|
||||
carbon.Parse("2020-08-05 13:14:15.999999999").ToIso8601MicroString() // 2020-08-05T13:14:15.999999+08:00
|
||||
// 输出 ISO8601Nano 格式字符串
|
||||
carbon.Parse("2020-08-05 13:14:15.999999999").ToIso8601NanoString() // 2020-08-05T13:14:15.999999999+08:00
|
||||
// 输出 ISO8601Zulu 格式字符串
|
||||
carbon.Parse("2020-08-05 13:14:15.999999999").ToIso8601ZuluString() // 2020-08-05T13:14:15Z
|
||||
// 输出 ISO8601ZuluMilli 格式字符串
|
||||
carbon.Parse("2020-08-05 13:14:15.999999999").ToIso8601ZuluMilliString() // 2020-08-05T13:14:15.999Z
|
||||
// 输出 ISO8601ZuluMicro 格式字符串
|
||||
carbon.Parse("2020-08-05 13:14:15.999999999").ToIso8601ZuluMicroString() // 2020-08-05T13:14:15.999999Z
|
||||
// 输出 ISO8601ZuluNano 格式字符串
|
||||
carbon.Parse("2020-08-05 13:14:15.999999999").ToIso8601ZuluNanoString() // 2020-08-05T13:14:15.999999999Z
|
||||
|
||||
// 输出 RFC822 格式字符串
|
||||
carbon.Parse("2020-08-05 13:14:15").ToRfc822String() // 05 Aug 20 13:14 CST
|
||||
@ -1126,13 +1133,18 @@ fmt.Printf("%s", carbon.Parse("2020-08-05 13:14:15")) // 2020-08-05 13:14:15
|
||||
// 输出"2006-01-02 15:04:05.999999999 -0700 MST"格式字符串
|
||||
carbon.Parse("2020-08-05 13:14:15").ToString() // 2020-08-05 13:14:15.999999 +0800 CST
|
||||
|
||||
// 输出指定布局的字符串,Layout()是ToLayoutString()的简写
|
||||
// 输出 "Jan 2, 2006" 格式字符串
|
||||
carbon.Parse("2020-08-05 13:14:15").ToFormattedDateString() // Aug 5, 2020
|
||||
// 输出 "Mon, Jan 2, 2006" 格式字符串
|
||||
carbon.Parse("2020-08-05 13:14:15").ToFormattedDayDateString() // Wed, Aug 5, 2020
|
||||
|
||||
// 输出指定布局的字符串
|
||||
carbon.Parse("2020-08-05 13:14:15").Layout(carbon.ISO8601Layout) // 2020-08-05T13:14:15+08:00
|
||||
carbon.Parse("2020-08-05 13:14:15").Layout("20060102150405") // 20200805131415
|
||||
carbon.Parse("2020-08-05 13:14:15").Layout("2006年01月02日 15时04分05秒") // 2020年08月05日 13时14分15秒
|
||||
carbon.Parse("2020-08-05 13:14:15").Layout("It is 2006-01-02 15:04:05") // It is 2020-08-05 13:14:15
|
||||
|
||||
// 输出指定格式的字符串,Format()是ToFormatString()的简写(如果使用的字母与格式化字符冲突时,请使用\符号转义该字符)
|
||||
// 输出指定格式的字符串(如果使用的字母与格式化字符冲突时,请使用\符号转义该字符)
|
||||
carbon.Parse("2020-08-05 13:14:15").Format("YmdHis") // 20200805131415
|
||||
carbon.Parse("2020-08-05 13:14:15").Format("Y年m月d日 H时i分s秒") // 2020年08月05日 13时14分15秒
|
||||
carbon.Parse("2020-08-05 13:14:15").Format("l jS \\o\\f F Y h:i:s A") // Wednesday 5th of August 2020 01:14:15 PM
|
||||
|
19
README.jp.md
19
README.jp.md
@ -67,7 +67,7 @@ carbon.SetDefault(carbon.Default{
|
||||
})
|
||||
```
|
||||
|
||||
> 設定されていない場合,デフォルトのレイアウト テンプレートは `2006-01-02 15:04:05`,デフォルトのタイムゾーンは `Local`,デフォルトの週の開始日は `日曜日`,デフォルトの言語は `en` です。
|
||||
>エントリファイル(` main.go `など)に設定することをお勧めします
|
||||
|
||||
##### Carbon と time.Time 交換
|
||||
|
||||
@ -1093,6 +1093,14 @@ carbon.Parse("2020-08-05 13:14:15.999999999").ToIso8601MilliString() // 2020-08-
|
||||
carbon.Parse("2020-08-05 13:14:15.999999999").ToIso8601MicroString() // 2020-08-05T13:14:15.999999+08:00
|
||||
// ISO8601Nano フォーマット文字列を出力
|
||||
carbon.Parse("2020-08-05 13:14:15.999999999").ToIso8601NanoString() // 2020-08-05T13:14:15.999999999+08:00
|
||||
// ISO8601Zulu フォーマット文字列を出力
|
||||
carbon.Parse("2020-08-05 13:14:15.999999999").ToIso8601ZuluString() // 2020-08-05T13:14:15Z
|
||||
// ISO8601ZuluMilli フォーマット文字列を出力
|
||||
carbon.Parse("2020-08-05 13:14:15.999999999").ToIso8601ZuluMilliString() // 2020-08-05T13:14:15.999Z
|
||||
// ISO8601ZuluMicro フォーマット文字列を出力
|
||||
carbon.Parse("2020-08-05 13:14:15.999999999").ToIso8601ZuluMicroString() // 2020-08-05T13:14:15.999999Z
|
||||
// ISO8601ZuluNano フォーマット文字列を出力
|
||||
carbon.Parse("2020-08-05 13:14:15.999999999").ToIso8601ZuluNanoString() // 2020-08-05T13:14:15.999999999Z
|
||||
|
||||
// RFC822 フォーマット文字列を出力
|
||||
carbon.Parse("2020-08-05 13:14:15").ToRfc822String() // 05 Aug 20 13:14 CST
|
||||
@ -1126,13 +1134,18 @@ fmt.Printf("%s", carbon.Parse("2020-08-05 13:14:15")) // 2020-08-05 13:14:15
|
||||
// "2006-01-02 15:04:05.999999999 -0700 MST" フォーマット文字列を出力
|
||||
carbon.Parse("2020-08-05 13:14:15").ToString() // 2020-08-05 13:14:15.999999 +0800 CST
|
||||
|
||||
// レイアウトを指定する文字列を出力, Layout() は 是ToLayoutString() の略記です
|
||||
// "Jan 2, 2006" フォーマット文字列を出力
|
||||
carbon.Parse("2020-08-05 13:14:15").ToFormattedDateString() // Aug 5, 2020
|
||||
// "Mon, Jan 2, 2006" フォーマット文字列を出力
|
||||
carbon.Parse("2020-08-05 13:14:15").ToFormattedDayDateString() // Wed, Aug 5, 2020
|
||||
|
||||
// レイアウトを指定する文字列を出力
|
||||
carbon.Parse("2020-08-05 13:14:15").Layout(carbon.ISO8601Layout) // 2020-08-05T13:14:15+08:00
|
||||
carbon.Parse("2020-08-05 13:14:15").Layout("20060102150405") // 20200805131415
|
||||
carbon.Parse("2020-08-05 13:14:15").Layout("2006年01月02日 15时04分05秒") // 2020年08月05日 13时14分15秒
|
||||
carbon.Parse("2020-08-05 13:14:15").Layout("It is 2006-01-02 15:04:05") // It is 2020-08-05 13:14:15
|
||||
|
||||
// 指定されたフォーマットの文字列を出力, Format() は 是ToFormatString() の略記です
|
||||
// 指定されたフォーマットの文字列を出力
|
||||
carbon.Parse("2020-08-05 13:14:15").Format("YmdHis") // 20200805131415
|
||||
carbon.Parse("2020-08-05 13:14:15").Format("Y年m月d日 H时i分s秒") // 2020年08月05日 13时14分15秒
|
||||
carbon.Parse("2020-08-05 13:14:15").Format("l jS \\o\\f F Y h:i:s A") // Wednesday 5th of August 2020 01:14:15 PM
|
||||
|
22
README.md
22
README.md
@ -65,8 +65,7 @@ carbon.SetDefault(carbon.Default{
|
||||
Locale: "en",
|
||||
})
|
||||
```
|
||||
|
||||
> If not set, the default layout is `2006-01-02 15:04:05`, the default timezone is `Local`, the default week start date is `Sunday` and the default language locale is `en`
|
||||
> Suggest setting in the entry file such as `main.go`
|
||||
|
||||
##### Convert between `Carbon` and `time.Time`
|
||||
|
||||
@ -1088,6 +1087,14 @@ carbon.Parse("2020-08-05 13:14:15.999999999").ToIso8601MilliString() // 2020-08-
|
||||
carbon.Parse("2020-08-05 13:14:15.999999999").ToIso8601MicroString() // 2020-08-05T13:14:15.999999+08:00
|
||||
// Output ISO8601 with nanosecond format string
|
||||
carbon.Parse("2020-08-05 13:14:15.999999999").ToIso8601NanoString() // 2020-08-05T13:14:15.999999999+08:00
|
||||
// Output ISO8601Zulu format string
|
||||
carbon.Parse("2020-08-05 13:14:15.999999999").ToIso8601ZuluString() // 2020-08-05T13:14:15Z
|
||||
// Output ISO8601Zulu with millisecond format string
|
||||
carbon.Parse("2020-08-05 13:14:15.999999999").ToIso8601ZuluMilliString() // 2020-08-05T13:14:15.999Z
|
||||
// Output ISO8601Zulu with microsecond format string
|
||||
carbon.Parse("2020-08-05 13:14:15.999999999").ToIso8601ZuluMicroString() // 2020-08-05T13:14:15.999999Z
|
||||
// Output ISO8601Zulu with nanosecond format string
|
||||
carbon.Parse("2020-08-05 13:14:15.999999999").ToIso8601ZuluNanoString() // 2020-08-05T13:14:15.999999999Z
|
||||
|
||||
// Output RFC822 format string
|
||||
carbon.Parse("2020-08-05 13:14:15").ToRfc822String() // 05 Aug 20 13:14 CST
|
||||
@ -1110,7 +1117,7 @@ carbon.Parse("2020-08-05 13:14:15").ToRfc7231String() // Wed, 05 Aug 2020 13:14:
|
||||
carbon.Parse("2020-08-05T13:14:15.999999999+08:00").ToRfc3339String() // 2020-08-05T13:14:15+08:00
|
||||
// Output RFC3339 with millisecond format string
|
||||
carbon.Parse("2020-08-05T13:14:15.999999999+08:00").ToRfc3339MilliString() // 2020-08-05T13:14:15.999+08:00
|
||||
// Output RFC3339 with microsecond format string
|
||||
// Output RFC3339 with microsecond format string
|
||||
carbon.Parse("2020-08-05T13:14:15.999999999+08:00").ToRfc3339MicroString() // 2020-08-05T13:14:15.999999+08:00
|
||||
// Output RFC3339 with nanosecond format string
|
||||
carbon.Parse("2020-08-05T13:14:15.999999999+08:00").ToRfc3339NanoString() // 2020-08-05T13:14:15.999999999+08:00
|
||||
@ -1121,13 +1128,18 @@ fmt.Printf("%s", carbon.Parse("2020-08-05 13:14:15")) // 2020-08-05 13:14:15
|
||||
// Output "2006-01-02 15:04:05.999999999 -0700 MST" format string
|
||||
carbon.Parse("2020-08-05 13:14:15").ToString() // 2020-08-05 13:14:15.999999 +0800 CST
|
||||
|
||||
// Output string by layout, Layout() is shorthand for ToLayoutString()
|
||||
// Output "Jan 2, 2006" format string
|
||||
carbon.Parse("2020-08-05 13:14:15").ToFormattedDateString() // Aug 5, 2020
|
||||
// Output "Mon, Jan 2, 2006" format string
|
||||
carbon.Parse("2020-08-05 13:14:15").ToFormattedDayDateString() // Wed, Aug 5, 2020
|
||||
|
||||
// Output string by layout
|
||||
carbon.Parse("2020-08-05 13:14:15").Layout(carbon.ISO8601Layout) // 2020-08-05T13:14:15+08:00
|
||||
carbon.Parse("2020-08-05 13:14:15").Layout("20060102150405") // 20200805131415
|
||||
carbon.Parse("2020-08-05 13:14:15").Layout("2006年01月02日 15时04分05秒") // 2020年08月05日 13时14分15秒
|
||||
carbon.Parse("2020-08-05 13:14:15").Layout("It is 2006-01-02 15:04:05") // It is 2020-08-05 13:14:15
|
||||
|
||||
// Output string by format, Format() is shorthand for ToFormatString()
|
||||
// Output string by format
|
||||
carbon.Parse("2020-08-05 13:14:15").Format("YmdHis") // 20200805131415
|
||||
carbon.Parse("2020-08-05 13:14:15").Format("Y年m月d日 H时i分s秒") // 2020年08月05日 13时14分15秒
|
||||
carbon.Parse("2020-08-05 13:14:15").Format("l jS \\o\\f F Y h:i:s A") // Wednesday 5th of August 2020 01:14:15 PM
|
||||
|
103
outputer.go
103
outputer.go
@ -21,6 +21,15 @@ func (c Carbon) String() string {
|
||||
return c.ToDateTimeString(c.Location())
|
||||
}
|
||||
|
||||
// GoString implements fmt.GoStringer and formats c to be printed in Go source code.
|
||||
// 实现 fmt.GoStringer 接口,并格式化 c 以在 Go 源代码中打印
|
||||
func (c Carbon) GoString() string {
|
||||
if c.IsInvalid() {
|
||||
return ""
|
||||
}
|
||||
return c.StdTime().GoString()
|
||||
}
|
||||
|
||||
// ToString outputs a string in "2006-01-02 15:04:05.999999999 -0700 MST" layout.
|
||||
// 输出 "2006-01-02 15:04:05.999999999 -0700 MST" 格式字符串
|
||||
func (c Carbon) ToString(timezone ...string) string {
|
||||
@ -569,6 +578,54 @@ func (c Carbon) ToIso8601NanoString(timezone ...string) string {
|
||||
return c.StdTime().Format(ISO8601NanoLayout)
|
||||
}
|
||||
|
||||
// ToIso8601ZuluString outputs a string in "2006-01-02T15:04:05Z" layout.
|
||||
// 输出 "2006-01-02T15:04:05Z" 格式字符串
|
||||
func (c Carbon) ToIso8601ZuluString(timezone ...string) string {
|
||||
if len(timezone) > 0 {
|
||||
c.loc, c.Error = getLocationByTimezone(timezone[0])
|
||||
}
|
||||
if c.IsInvalid() {
|
||||
return ""
|
||||
}
|
||||
return c.StdTime().Format(ISO8601ZuluLayout)
|
||||
}
|
||||
|
||||
// ToIso8601ZuluMilliString outputs a string in "2006-01-02T15:04:05.999Z" layout.
|
||||
// 输出 "2006-01-02T15:04:05.999Z" 格式字符串
|
||||
func (c Carbon) ToIso8601ZuluMilliString(timezone ...string) string {
|
||||
if len(timezone) > 0 {
|
||||
c.loc, c.Error = getLocationByTimezone(timezone[0])
|
||||
}
|
||||
if c.IsInvalid() {
|
||||
return ""
|
||||
}
|
||||
return c.StdTime().Format(ISO8601ZuluMilliLayout)
|
||||
}
|
||||
|
||||
// ToIso8601ZuluMicroString outputs a string in "2006-01-02T15:04:05.999999Z" layout.
|
||||
// 输出 "2006-01-02T15:04:05.999999Z" 格式字符串
|
||||
func (c Carbon) ToIso8601ZuluMicroString(timezone ...string) string {
|
||||
if len(timezone) > 0 {
|
||||
c.loc, c.Error = getLocationByTimezone(timezone[0])
|
||||
}
|
||||
if c.IsInvalid() {
|
||||
return ""
|
||||
}
|
||||
return c.StdTime().Format(ISO8601ZuluMicroLayout)
|
||||
}
|
||||
|
||||
// ToIso8601ZuluNanoString outputs a string in "2006-01-02T15:04:05.999999999Z" layout.
|
||||
// 输出 "2006-01-02T15:04:05.999999999Z" 格式字符串
|
||||
func (c Carbon) ToIso8601ZuluNanoString(timezone ...string) string {
|
||||
if len(timezone) > 0 {
|
||||
c.loc, c.Error = getLocationByTimezone(timezone[0])
|
||||
}
|
||||
if c.IsInvalid() {
|
||||
return ""
|
||||
}
|
||||
return c.StdTime().Format(ISO8601ZuluNanoLayout)
|
||||
}
|
||||
|
||||
// ToRfc822String outputs a string in "02 Jan 06 15:04 MST" layout.
|
||||
// 输出 "02 Jan 06 15:04 MST" 格式字符串
|
||||
func (c Carbon) ToRfc822String(timezone ...string) string {
|
||||
@ -713,9 +770,33 @@ func (c Carbon) ToRfc7231String(timezone ...string) string {
|
||||
return c.StdTime().Format(RFC7231Layout)
|
||||
}
|
||||
|
||||
// ToLayoutString outputs a string by layout.
|
||||
// ToFormattedDateString outputs a string in "Jan 2, 2006" layout.
|
||||
// 输出 "Jan 2, 2006" 格式字符串
|
||||
func (c Carbon) ToFormattedDateString(timezone ...string) string {
|
||||
if len(timezone) > 0 {
|
||||
c.loc, c.Error = getLocationByTimezone(timezone[0])
|
||||
}
|
||||
if c.IsInvalid() {
|
||||
return ""
|
||||
}
|
||||
return c.StdTime().Format(FormattedDateLayout)
|
||||
}
|
||||
|
||||
// ToFormattedDayDateString outputs a string in "Mon, Jan 2, 2006" layout.
|
||||
// 输出 "Jan 2, 2006" 格式字符串
|
||||
func (c Carbon) ToFormattedDayDateString(timezone ...string) string {
|
||||
if len(timezone) > 0 {
|
||||
c.loc, c.Error = getLocationByTimezone(timezone[0])
|
||||
}
|
||||
if c.IsInvalid() {
|
||||
return ""
|
||||
}
|
||||
return c.StdTime().Format(FormattedDayDateLayout)
|
||||
}
|
||||
|
||||
// Layout outputs a string by layout.
|
||||
// 输出指定布局模板的时间字符串
|
||||
func (c Carbon) ToLayoutString(layout string, timezone ...string) string {
|
||||
func (c Carbon) Layout(layout string, timezone ...string) string {
|
||||
if len(timezone) > 0 {
|
||||
c.loc, c.Error = getLocationByTimezone(timezone[0])
|
||||
}
|
||||
@ -725,15 +806,9 @@ func (c Carbon) ToLayoutString(layout string, timezone ...string) string {
|
||||
return c.StdTime().Format(layout)
|
||||
}
|
||||
|
||||
// Layout outputs a string by layout, it is shorthand for ToLayoutString.
|
||||
// 输出指定布局模板的时间字符串, 是 ToLayoutString 的简写
|
||||
func (c Carbon) Layout(layout string, timezone ...string) string {
|
||||
return c.ToLayoutString(layout, timezone...)
|
||||
}
|
||||
|
||||
// ToFormatString outputs a string by format.
|
||||
// Format outputs a string by format.
|
||||
// 输出指定格式模板的时间字符串
|
||||
func (c Carbon) ToFormatString(format string, timezone ...string) string {
|
||||
func (c Carbon) Format(format string, timezone ...string) string {
|
||||
if len(timezone) > 0 {
|
||||
c.loc, c.Error = getLocationByTimezone(timezone[0])
|
||||
}
|
||||
@ -824,16 +899,10 @@ func (c Carbon) ToFormatString(format string, timezone ...string) string {
|
||||
return buffer.String()
|
||||
}
|
||||
|
||||
// Format outputs a string by format, it is shorthand for ToFormatString.
|
||||
// 输出指定格式模板的时间字符串, 是 ToFormatString 的简写
|
||||
func (c Carbon) Format(format string, timezone ...string) string {
|
||||
return c.ToFormatString(format, timezone...)
|
||||
}
|
||||
|
||||
// Deprecated: it will be removed in the future, use StdTime instead.
|
||||
//
|
||||
// ToStdTime converts Carbon to standard time.Time.
|
||||
// 将 Carbon 转换成标准 time.Time,未来将移除,请用 StdTime 替换
|
||||
// 将 Carbon 转换成标准 time.Time
|
||||
func (c Carbon) ToStdTime() time.Time {
|
||||
return c.StdTime()
|
||||
}
|
||||
|
@ -303,6 +303,34 @@ func BenchmarkCarbon_ToIso8601NanoString(b *testing.B) {
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkCarbon_ToIso8601ZuluString(b *testing.B) {
|
||||
now := Now()
|
||||
for n := 0; n < b.N; n++ {
|
||||
now.ToIso8601ZuluString()
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkCarbon_ToIso8601ZuluMilliString(b *testing.B) {
|
||||
now := Now()
|
||||
for n := 0; n < b.N; n++ {
|
||||
now.ToIso8601ZuluMilliString()
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkCarbon_ToIso8601ZuluMicroString(b *testing.B) {
|
||||
now := Now()
|
||||
for n := 0; n < b.N; n++ {
|
||||
now.ToIso8601ZuluMicroString()
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkCarbon_ToIso8601ZuluNanoString(b *testing.B) {
|
||||
now := Now()
|
||||
for n := 0; n < b.N; n++ {
|
||||
now.ToIso8601ZuluNanoString()
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkCarbon_ToRfc822String(b *testing.B) {
|
||||
now := Now()
|
||||
for n := 0; n < b.N; n++ {
|
||||
@ -387,10 +415,17 @@ func BenchmarkCarbon_ToRfc7231String(b *testing.B) {
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkCarbon_ToLayoutString(b *testing.B) {
|
||||
func BenchmarkCarbon_ToFormattedDateString(b *testing.B) {
|
||||
now := Now()
|
||||
for n := 0; n < b.N; n++ {
|
||||
now.ToLayoutString("2006-01-02", "2020-08-05")
|
||||
now.ToFormattedDateString()
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkCarbon_ToFormattedDayDateString(b *testing.B) {
|
||||
now := Now()
|
||||
for n := 0; n < b.N; n++ {
|
||||
now.ToFormattedDayDateString()
|
||||
}
|
||||
}
|
||||
|
||||
@ -401,13 +436,6 @@ func BenchmarkCarbon_Layout(b *testing.B) {
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkCarbon_ToFormatString(b *testing.B) {
|
||||
now := Now()
|
||||
for n := 0; n < b.N; n++ {
|
||||
now.ToFormatString("2006-01-02", "Y-m-d")
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkCarbon_Format(b *testing.B) {
|
||||
now := Now()
|
||||
for n := 0; n < b.N; n++ {
|
||||
@ -415,9 +443,9 @@ func BenchmarkCarbon_Format(b *testing.B) {
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkCarbon_ToStdTime(b *testing.B) {
|
||||
func BenchmarkCarbon_GoTime(b *testing.B) {
|
||||
now := Now()
|
||||
for n := 0; n < b.N; n++ {
|
||||
now.ToStdTime()
|
||||
now.GoString()
|
||||
}
|
||||
}
|
||||
|
@ -36,6 +36,29 @@ func TestCarbon_String(t *testing.T) {
|
||||
assert.Equal("2020-08-05 00:00:00", c.String())
|
||||
}
|
||||
|
||||
func TestCarbon_GoString(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
tests := []struct {
|
||||
input string
|
||||
expected string
|
||||
}{
|
||||
{"", ""},
|
||||
{"0", ""},
|
||||
{"0000-00-00", ""},
|
||||
{"00:00:00", ""},
|
||||
{"0000-00-00 00:00:00", ""},
|
||||
|
||||
{"2020-08-05 13:14:15", "time.Date(2020, time.August, 5, 13, 14, 15, 0, time.Local)"},
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
assert.Equal(test.expected, Parse(test.input).GoString(), "Current test index is "+strconv.Itoa(index))
|
||||
}
|
||||
}
|
||||
|
||||
func TestCarbon_ToString(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
@ -52,12 +75,6 @@ func TestCarbon_ToString(t *testing.T) {
|
||||
{"2020-08-05 13:14:15", "2020-08-05 13:14:15 +0800 CST"},
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
assert.Equal(test.expected, c.ToString(), "Current test index is "+strconv.Itoa(index))
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
@ -92,12 +109,6 @@ func TestCarbon_ToMonthString(t *testing.T) {
|
||||
{"2020-12-05", "December"},
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
assert.Equal(test.expected, c.ToMonthString(), "Current test index is "+strconv.Itoa(index))
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
@ -132,12 +143,6 @@ func TestCarbon_ToShortMonthString(t *testing.T) {
|
||||
{"2020-12-05", "Dec"},
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
assert.Equal(test.expected, c.ToShortMonthString(), "Current test index is "+strconv.Itoa(index))
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
@ -167,12 +172,6 @@ func TestCarbon_ToWeekString(t *testing.T) {
|
||||
{"2020-08-07", "Friday"},
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
assert.Equal(test.expected, c.ToWeekString(), "Current test index is "+strconv.Itoa(index))
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
@ -202,12 +201,6 @@ func TestCarbon_ToShortWeekString(t *testing.T) {
|
||||
{"2020-08-07", "Fri"},
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
assert.Equal(test.expected, c.ToShortWeekString(), "Current test index is "+strconv.Itoa(index))
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
@ -231,12 +224,6 @@ func TestCarbon_ToDayDateTimeString(t *testing.T) {
|
||||
{"2020-08-05 13:14:15", "Wed, Aug 5, 2020 1:14 PM"},
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
assert.Equal(test.expected, c.ToDayDateTimeString(), "Current test index is "+strconv.Itoa(index))
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
@ -261,12 +248,6 @@ func TestCarbon_ToDateTimeString(t *testing.T) {
|
||||
{"2020-08-05", "2020-08-05 00:00:00"},
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
assert.Equal(test.expected, c.ToDateTimeString(), "Current test index is "+strconv.Itoa(index))
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
@ -291,12 +272,6 @@ func TestCarbon_ToDateTimeMilliString(t *testing.T) {
|
||||
{"2020-08-05", "2020-08-05 00:00:00"},
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
assert.Equal(test.expected, c.ToDateTimeMilliString(), "Current test index is "+strconv.Itoa(index))
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
@ -321,12 +296,6 @@ func TestCarbon_ToDateTimeMicroString(t *testing.T) {
|
||||
{"2020-08-05", "2020-08-05 00:00:00"},
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
assert.Equal(test.expected, c.ToDateTimeMicroString(), "Current test index is "+strconv.Itoa(index))
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
@ -351,12 +320,6 @@ func TestCarbon_ToDateTimeNanoString(t *testing.T) {
|
||||
{"2020-08-05", "2020-08-05 00:00:00"},
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
assert.Equal(test.expected, c.ToDateTimeNanoString(), "Current test index is "+strconv.Itoa(index))
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
@ -381,12 +344,6 @@ func TestCarbon_ToShortDateTimeString(t *testing.T) {
|
||||
{"2020-08-05", "20200805000000"},
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
assert.Equal(test.expected, c.ToShortDateTimeString(), "Current test index is "+strconv.Itoa(index))
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
@ -411,12 +368,6 @@ func TestCarbon_ToShortDateTimeMilliString(t *testing.T) {
|
||||
{"2020-08-05", "20200805000000"},
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
assert.Equal(test.expected, c.ToShortDateTimeMilliString(), "Current test index is "+strconv.Itoa(index))
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
@ -441,12 +392,6 @@ func TestCarbon_ToShortDateTimeMicroString(t *testing.T) {
|
||||
{"2020-08-05", "20200805000000"},
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
assert.Equal(test.expected, c.ToShortDateTimeMicroString(), "Current test index is "+strconv.Itoa(index))
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
@ -471,12 +416,6 @@ func TestCarbon_ToShortDateTimeNanoString(t *testing.T) {
|
||||
{"2020-08-05", "20200805000000"},
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
assert.Equal(test.expected, c.ToShortDateTimeNanoString(), "Current test index is "+strconv.Itoa(index))
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
@ -501,12 +440,6 @@ func TestCarbon_ToDateString(t *testing.T) {
|
||||
{"2020-08-05", "2020-08-05"},
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
assert.Equal(test.expected, c.ToDateString(), "Current test index is "+strconv.Itoa(index))
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
@ -531,12 +464,6 @@ func TestCarbon_ToDateMilliString(t *testing.T) {
|
||||
{"2020-08-05", "2020-08-05"},
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
assert.Equal(test.expected, c.ToDateMilliString(), "Current test index is "+strconv.Itoa(index))
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
@ -561,12 +488,6 @@ func TestCarbon_ToDateMicroString(t *testing.T) {
|
||||
{"2020-08-05", "2020-08-05"},
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
assert.Equal(test.expected, c.ToDateMicroString(), "Current test index is "+strconv.Itoa(index))
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
@ -591,12 +512,6 @@ func TestCarbon_ToDateNanoString(t *testing.T) {
|
||||
{"2020-08-05", "2020-08-05"},
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
assert.Equal(test.expected, c.ToDateNanoString(), "Current test index is "+strconv.Itoa(index))
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
@ -621,12 +536,6 @@ func TestCarbon_ToShortDateString(t *testing.T) {
|
||||
{"2020-08-05", "20200805"},
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
assert.Equal(test.expected, c.ToShortDateString(), "Current test index is "+strconv.Itoa(index))
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
@ -651,12 +560,6 @@ func TestCarbon_ToShortDateMilliString(t *testing.T) {
|
||||
{"2020-08-05", "20200805"},
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
assert.Equal(test.expected, c.ToShortDateMilliString(), "Current test index is "+strconv.Itoa(index))
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
@ -681,12 +584,6 @@ func TestCarbon_ToShortDateNanoString(t *testing.T) {
|
||||
{"2020-08-05", "20200805"},
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
assert.Equal(test.expected, c.ToShortDateNanoString(), "Current test index is "+strconv.Itoa(index))
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
@ -711,12 +608,6 @@ func TestCarbon_ToShortDateMicroString(t *testing.T) {
|
||||
{"2020-08-05", "20200805"},
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
assert.Equal(test.expected, c.ToShortDateMicroString(), "Current test index is "+strconv.Itoa(index))
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
@ -741,12 +632,6 @@ func TestCarbon_ToTimeString(t *testing.T) {
|
||||
{"2020-08-05", "00:00:00"},
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
assert.Equal(test.expected, c.ToTimeString(), "Current test index is "+strconv.Itoa(index))
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
@ -771,12 +656,6 @@ func TestCarbon_ToTimeMilliString(t *testing.T) {
|
||||
{"2020-08-05", "00:00:00"},
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
assert.Equal(test.expected, c.ToTimeMilliString(), "Current test index is "+strconv.Itoa(index))
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
@ -801,12 +680,6 @@ func TestCarbon_ToTimeMicroString(t *testing.T) {
|
||||
{"2020-08-05", "00:00:00"},
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
assert.Equal(test.expected, c.ToTimeMicroString(), "Current test index is "+strconv.Itoa(index))
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
@ -831,12 +704,6 @@ func TestCarbon_ToTimeNanoString(t *testing.T) {
|
||||
{"2020-08-05", "00:00:00"},
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
assert.Equal(test.expected, c.ToTimeNanoString(), "Current test index is "+strconv.Itoa(index))
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
@ -861,12 +728,6 @@ func TestCarbon_ToShortTimeString(t *testing.T) {
|
||||
{"2020-08-05", "000000"},
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
assert.Equal(test.expected, c.ToShortTimeString(), "Current test index is "+strconv.Itoa(index))
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
@ -891,12 +752,6 @@ func TestCarbon_ToShortTimeMilliString(t *testing.T) {
|
||||
{"2020-08-05", "000000"},
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
assert.Equal(test.expected, c.ToShortTimeMilliString(), "Current test index is "+strconv.Itoa(index))
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
@ -921,12 +776,6 @@ func TestCarbon_ToShortTimeMicroString(t *testing.T) {
|
||||
{"2020-08-05", "000000"},
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
assert.Equal(test.expected, c.ToShortTimeMicroString(), "Current test index is "+strconv.Itoa(index))
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
@ -951,12 +800,6 @@ func TestCarbon_ToShortTimeNanoString(t *testing.T) {
|
||||
{"2020-08-05", "000000"},
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
assert.Equal(test.expected, c.ToShortTimeNanoString(), "Current test index is "+strconv.Itoa(index))
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
@ -981,12 +824,6 @@ func TestCarbon_ToAtomString(t *testing.T) {
|
||||
{"2020-08-05", "2020-08-05T00:00:00+08:00"},
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
assert.Equal(test.expected, c.ToAtomString(), "Current test index is "+strconv.Itoa(index))
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
@ -1011,12 +848,6 @@ func TestCarbon_ToAnsicString(t *testing.T) {
|
||||
{"2020-08-05", "Wed Aug 5 00:00:00 2020"},
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
assert.Equal(test.expected, c.ToAnsicString(), "Current test index is "+strconv.Itoa(index))
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
@ -1041,12 +872,6 @@ func TestCarbon_ToCookieString(t *testing.T) {
|
||||
{"2020-08-05", "Wednesday, 05-Aug-2020 00:00:00 CST"},
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
assert.Equal(test.expected, c.ToCookieString(), "Current test index is "+strconv.Itoa(index))
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
@ -1071,12 +896,6 @@ func TestCarbon_ToRssString(t *testing.T) {
|
||||
{"2020-08-05", "Wed, 05 Aug 2020 00:00:00 +0800"},
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
assert.Equal(test.expected, c.ToRssString(), "Current test index is "+strconv.Itoa(index))
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
@ -1101,12 +920,6 @@ func TestCarbon_ToW3cString(t *testing.T) {
|
||||
{"2020-08-05", "2020-08-05T00:00:00+08:00"},
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
assert.Equal(test.expected, c.ToW3cString(), "Current test index is "+strconv.Itoa(index))
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
@ -1131,12 +944,6 @@ func TestCarbon_ToUnixDateString(t *testing.T) {
|
||||
{"2020-08-05", "Wed Aug 5 00:00:00 CST 2020"},
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
assert.Equal(test.expected, c.ToUnixDateString(), "Current test index is "+strconv.Itoa(index))
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
@ -1161,12 +968,6 @@ func TestCarbon_ToRubyDateString(t *testing.T) {
|
||||
{"2020-08-05", "Wed Aug 05 00:00:00 +0800 2020"},
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
assert.Equal(test.expected, c.ToRubyDateString(), "Current test index is "+strconv.Itoa(index))
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
@ -1191,12 +992,6 @@ func TestCarbon_ToKitchenString(t *testing.T) {
|
||||
{"2020-08-05", "12:00AM"},
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
assert.Equal(test.expected, test.expected, c.ToKitchenString(), "Current test index is "+strconv.Itoa(index))
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
@ -1221,12 +1016,6 @@ func TestCarbon_ToIso8601String(t *testing.T) {
|
||||
{"2020-08-05", "2020-08-05T00:00:00+08:00"},
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
assert.Equal(test.expected, c.ToIso8601String(), "Current test index is "+strconv.Itoa(index))
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
@ -1251,12 +1040,6 @@ func TestCarbon_ToIso8601MilliString(t *testing.T) {
|
||||
{"2020-08-05", "2020-08-05T00:00:00+08:00"},
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
assert.Equal(test.expected, c.ToIso8601MilliString(), "Current test index is "+strconv.Itoa(index))
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
@ -1281,12 +1064,6 @@ func TestCarbon_ToIso8601MicroString(t *testing.T) {
|
||||
{"2020-08-05", "2020-08-05T00:00:00+08:00"},
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
assert.Equal(test.expected, c.ToIso8601MicroString(), "Current test index is "+strconv.Itoa(index))
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
@ -1314,13 +1091,103 @@ func TestCarbon_ToIso8601NanoString(t *testing.T) {
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
assert.Equal(test.expected, c.ToIso8601NanoString(), "Current test index is "+strconv.Itoa(index))
|
||||
assert.Equal(test.expected, c.ToIso8601NanoString(PRC), "Current test index is "+strconv.Itoa(index))
|
||||
}
|
||||
}
|
||||
|
||||
func TestCarbon_ToIso8601ZuluString(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
tests := []struct {
|
||||
input string
|
||||
expected string
|
||||
}{
|
||||
{"", ""},
|
||||
{"0", ""},
|
||||
{"0000-00-00", ""},
|
||||
{"00:00:00", ""},
|
||||
{"0000-00-00 00:00:00", ""},
|
||||
|
||||
{"2020-08-05 13:14:15", "2020-08-05T13:14:15Z"},
|
||||
{"2020-08-05", "2020-08-05T00:00:00Z"},
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
assert.Equal(test.expected, c.ToIso8601NanoString(PRC), "Current test index is "+strconv.Itoa(index))
|
||||
assert.Equal(test.expected, c.ToIso8601ZuluString(PRC), "Current test index is "+strconv.Itoa(index))
|
||||
}
|
||||
}
|
||||
|
||||
func TestCarbon_ToIso8601ZuluMilliString(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
tests := []struct {
|
||||
input string
|
||||
expected string
|
||||
}{
|
||||
{"", ""},
|
||||
{"0", ""},
|
||||
{"0000-00-00", ""},
|
||||
{"00:00:00", ""},
|
||||
{"0000-00-00 00:00:00", ""},
|
||||
|
||||
{"2020-08-05 13:14:15.999999999", "2020-08-05T13:14:15.999Z"},
|
||||
{"2020-08-05", "2020-08-05T00:00:00Z"},
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
assert.Equal(test.expected, c.ToIso8601ZuluMilliString(PRC), "Current test index is "+strconv.Itoa(index))
|
||||
}
|
||||
}
|
||||
|
||||
func TestCarbon_ToIso8601ZuluMicroString(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
tests := []struct {
|
||||
input string
|
||||
expected string
|
||||
}{
|
||||
{"", ""},
|
||||
{"0", ""},
|
||||
{"0000-00-00", ""},
|
||||
{"00:00:00", ""},
|
||||
{"0000-00-00 00:00:00", ""},
|
||||
|
||||
{"2020-08-05 13:14:15.999999999", "2020-08-05T13:14:15.999999Z"},
|
||||
{"2020-08-05", "2020-08-05T00:00:00Z"},
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
assert.Equal(test.expected, c.ToIso8601ZuluMicroString(PRC), "Current test index is "+strconv.Itoa(index))
|
||||
}
|
||||
}
|
||||
|
||||
func TestCarbon_ToIso8601ZuluNanoString(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
tests := []struct {
|
||||
input string
|
||||
expected string
|
||||
}{
|
||||
{"", ""},
|
||||
{"0", ""},
|
||||
{"0000-00-00", ""},
|
||||
{"00:00:00", ""},
|
||||
{"0000-00-00 00:00:00", ""},
|
||||
|
||||
{"2020-08-05 13:14:15.999999999", "2020-08-05T13:14:15.999999999Z"},
|
||||
{"2020-08-05", "2020-08-05T00:00:00Z"},
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
assert.Equal(test.expected, c.ToIso8601ZuluNanoString(PRC), "Current test index is "+strconv.Itoa(index))
|
||||
}
|
||||
}
|
||||
|
||||
@ -1341,12 +1208,6 @@ func TestCarbon_ToRfc822String(t *testing.T) {
|
||||
{"2020-08-05", "05 Aug 20 00:00 CST"},
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
assert.Equal(test.expected, c.ToRfc822String(), "Current test index is "+strconv.Itoa(index))
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
@ -1371,12 +1232,6 @@ func TestCarbon_ToRfc822zString(t *testing.T) {
|
||||
{"2020-08-05", "05 Aug 20 00:00 +0800"},
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
assert.Equal(test.expected, c.ToRfc822zString(), "Current test index is "+strconv.Itoa(index))
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
@ -1401,12 +1256,6 @@ func TestCarbon_ToRfc850String(t *testing.T) {
|
||||
{"2020-08-05", "Wednesday, 05-Aug-20 00:00:00 CST"},
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
assert.Equal(test.expected, c.ToRfc850String(), "Current test index is "+strconv.Itoa(index))
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
@ -1431,12 +1280,6 @@ func TestCarbon_ToRfc1036String(t *testing.T) {
|
||||
{"2020-08-05", "Wed, 05 Aug 20 00:00:00 +0800"},
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
assert.Equal(test.expected, c.ToRfc1036String(), "Current test index is "+strconv.Itoa(index))
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
@ -1461,12 +1304,6 @@ func TestCarbon_ToRfc1123String(t *testing.T) {
|
||||
{"2020-08-05", "Wed, 05 Aug 2020 00:00:00 CST"},
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
assert.Equal(test.expected, c.ToRfc1123String(), "Current test index is "+strconv.Itoa(index))
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
@ -1491,12 +1328,6 @@ func TestCarbon_ToRfc1123zString(t *testing.T) {
|
||||
{"2020-08-05", "Wed, 05 Aug 2020 00:00:00 +0800"},
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
assert.Equal(test.expected, c.ToRfc1123zString(), "Current test index is "+strconv.Itoa(index))
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
@ -1521,12 +1352,6 @@ func TestCarbon_ToRfc2822String(t *testing.T) {
|
||||
{"2020-08-05", "Wed, 05 Aug 2020 00:00:00 +0800"},
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
assert.Equal(test.expected, c.ToRfc2822String(), "Current test index is "+strconv.Itoa(index))
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
@ -1550,12 +1375,6 @@ func TestCarbon_ToRfc3339String(t *testing.T) {
|
||||
{"2020-08-05 13:14:15", "2020-08-05T13:14:15+08:00"},
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
assert.Equal(test.expected, c.ToRfc3339String(), "Current test index is "+strconv.Itoa(index))
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
@ -1579,12 +1398,6 @@ func TestCarbon_ToRfc3339MilliString(t *testing.T) {
|
||||
{"2020-08-05T13:14:15.999999999+08:00", "2020-08-05T13:14:15.999+08:00"},
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
assert.Equal(test.expected, c.ToRfc3339MilliString(), "Current test index is "+strconv.Itoa(index))
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
@ -1608,12 +1421,6 @@ func TestCarbon_ToRfc3339MicroString(t *testing.T) {
|
||||
{"2020-08-05T13:14:15.999999999+08:00", "2020-08-05T13:14:15.999999+08:00"},
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
assert.Equal(test.expected, c.ToRfc3339MicroString(), "Current test index is "+strconv.Itoa(index))
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
@ -1637,12 +1444,6 @@ func TestCarbon_ToRfc3339NanoString(t *testing.T) {
|
||||
{"2020-08-05T13:14:15.999999999+08:00", "2020-08-05T13:14:15.999999999+08:00"},
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
assert.Equal(test.expected, c.ToRfc3339NanoString(), "Current test index is "+strconv.Itoa(index))
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
@ -1670,13 +1471,55 @@ func TestCarbon_ToRfc7231String(t *testing.T) {
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
assert.Equal(test.expected, c.ToRfc7231String(), "Current test index is "+strconv.Itoa(index))
|
||||
assert.Equal(test.expected, c.ToRfc7231String(PRC), "Current test index is "+strconv.Itoa(index))
|
||||
}
|
||||
}
|
||||
|
||||
func TestCarbon_ToFormattedDateString(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
tests := []struct {
|
||||
input string
|
||||
expected string
|
||||
}{
|
||||
{"", ""},
|
||||
{"0", ""},
|
||||
{"0000-00-00", ""},
|
||||
{"00:00:00", ""},
|
||||
{"0000-00-00 00:00:00", ""},
|
||||
|
||||
{"2020-08-05 13:14:15", "Aug 5, 2020"},
|
||||
{"2020-08-05", "Aug 5, 2020"},
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
assert.Equal(test.expected, c.ToRfc7231String(PRC), "Current test index is "+strconv.Itoa(index))
|
||||
assert.Equal(test.expected, c.ToFormattedDateString(PRC), "Current test index is "+strconv.Itoa(index))
|
||||
}
|
||||
}
|
||||
|
||||
func TestCarbon_ToFormattedDayDateString(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
tests := []struct {
|
||||
input string
|
||||
expected string
|
||||
}{
|
||||
{"", ""},
|
||||
{"0", ""},
|
||||
{"0000-00-00", ""},
|
||||
{"00:00:00", ""},
|
||||
{"0000-00-00 00:00:00", ""},
|
||||
|
||||
{"2020-08-05 13:14:15", "Wed, Aug 5, 2020"},
|
||||
{"2020-08-05", "Wed, Aug 5, 2020"},
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
assert.Equal(test.expected, c.ToFormattedDayDateString(PRC), "Current test index is "+strconv.Itoa(index))
|
||||
}
|
||||
}
|
||||
|
||||
@ -1698,29 +1541,11 @@ func TestCarbon_Layout(t *testing.T) {
|
||||
{"2020-08-05 13:14:15", "Mon, 02 Jan 2006 15:04:05 GMT", "Wed, 05 Aug 2020 13:14:15 GMT"},
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
assert.Equal(test.expected, c.Layout(test.param), "Current test index is "+strconv.Itoa(index))
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
assert.Equal(test.expected, c.ToLayoutString(test.param), "Current test index is "+strconv.Itoa(index))
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
assert.Equal(test.expected, c.Layout(test.param, PRC), "Current test index is "+strconv.Itoa(index))
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
assert.Equal(test.expected, c.ToLayoutString(test.param, PRC), "Current test index is "+strconv.Itoa(index))
|
||||
}
|
||||
}
|
||||
|
||||
func TestCarbon_Format(t *testing.T) {
|
||||
@ -1780,18 +1605,6 @@ func TestCarbon_Format(t *testing.T) {
|
||||
assert.Nil(c.Error)
|
||||
assert.Equal(test.expected, c.SetLocale(test.locale).Format(test.format), "Current test index is "+strconv.Itoa(index))
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
assert.Equal(test.expected, c.SetLocale(test.locale).ToFormatString(test.format), "Current test index is "+strconv.Itoa(index))
|
||||
}
|
||||
|
||||
for index, test := range tests {
|
||||
c := Parse(test.input, PRC)
|
||||
assert.Nil(c.Error)
|
||||
assert.Equal(test.expected, c.SetLocale(test.locale).ToFormatString(test.format, PRC), "Current test index is "+strconv.Itoa(index))
|
||||
}
|
||||
}
|
||||
|
||||
func TestCarbon_ToStdTime(t *testing.T) {
|
||||
|
Loading…
Reference in New Issue
Block a user