Skip to content

Commit

Permalink
v2.1.3 XXXFormat->XXXLayout
Browse files Browse the repository at this point in the history
  • Loading branch information
gouguoyin committed Apr 24, 2022
1 parent 8490da7 commit e879f7d
Show file tree
Hide file tree
Showing 8 changed files with 141 additions and 138 deletions.
1 change: 1 addition & 0 deletions README.cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -913,6 +913,7 @@ fmt.Sprintf("%s", carbon.Parse("2020-08-05 13:14:15")) // 2020-08-05 13:14:15
carbon.Parse("2020-08-05 13:14:15").ToString() // 2020-08-05 13:14:15.999999 +0800 CST

// 输出指定布局的字符串,Layout()是ToLayoutString()的简写
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
Expand Down
1 change: 1 addition & 0 deletions README.jp.md
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,7 @@ fmt.Sprintf("%s", carbon.Parse("2020-08-05 13:14:15")) // 2020-08-05 13:14:15
carbon.Parse("2020-08-05 13:14:15").ToString() // 2020-08-05 13:14:15.999999 +0800 CST

// レイアウトを指定する文字列を出力, Layout() は 是ToLayoutString() の略記です
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
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -908,6 +908,7 @@ fmt.Sprintf("%s", carbon.Parse("2020-08-05 13:14:15")) // 2020-08-05 13:14:15
carbon.Parse("2020-08-05 13:14:15").ToString() // 2020-08-05 13:14:15.999999 +0800 CST

// Output a string by layout, Layout() is shorthand for ToLayoutString()
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
Expand Down
82 changes: 41 additions & 41 deletions carbon.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,44 +122,44 @@ const (
SecondsPerMinute = 60 // 每分钟60秒
)

// formats constant
// 时间格式化常量
// layouts constant
// 时间布局常量
const (
ANSICFormat = time.ANSIC
UnixDateFormat = time.UnixDate
RubyDateFormat = time.RubyDate
RFC822Format = time.RFC822
RFC822ZFormat = time.RFC822Z
RFC850Format = time.RFC850
RFC1123Format = time.RFC1123
RFC1123ZFormat = time.RFC1123Z
RssFormat = time.RFC1123Z
KitchenFormat = time.Kitchen
RFC2822Format = time.RFC1123Z
CookieFormat = "Monday, 02-Jan-2006 15:04:05 MST"
RFC3339Format = "2006-01-02T15:04:05Z07:00"
RFC3339MilliFormat = "2006-01-02T15:04:05.999Z07:00"
RFC3339MicroFormat = "2006-01-02T15:04:05.999999Z07:00"
RFC3339NanoFormat = "2006-01-02T15:04:05.999999999Z07:00"
ISO8601Format = "2006-01-02T15:04:05-07:00"
ISO8601MilliFormat = "2006-01-02T15:04:05.999-07:00"
ISO8601MicroFormat = "2006-01-02T15:04:05.999999-07:00"
ISO8601NanoFormat = "2006-01-02T15:04:05.999999999-07:00"
RFC1036Format = "Mon, 02 Jan 06 15:04:05 -0700"
RFC7231Format = "Mon, 02 Jan 2006 15:04:05 GMT"
DayDateTimeFormat = "Mon, Jan 2, 2006 3:04 PM"
DateTimeFormat = "2006-01-02 15:04:05"
DateTimeMilliFormat = "2006-01-02 15:04:05.999"
DateTimeMicroFormat = "2006-01-02 15:04:05.999999"
DateTimeNanoFormat = "2006-01-02 15:04:05.999999999"
DateFormat = "2006-01-02"
TimeFormat = "15:04:05"
ShortDateTimeFormat = "20060102150405"
ShortDateTimeMilliFormat = "20060102150405.999"
ShortDateTimeMicroFormat = "20060102150405.999999"
ShortDateTimeNanoFormat = "20060102150405.999999999"
ShortDateFormat = "20060102"
ShortTimeFormat = "150405"
ANSICLayout = time.ANSIC
UnixDateLayout = time.UnixDate
RubyDateLayout = time.RubyDate
RFC822Layout = time.RFC822
RFC822ZLayout = time.RFC822Z
RFC850Layout = time.RFC850
RFC1123Layout = time.RFC1123
RFC1123ZLayout = time.RFC1123Z
RssLayout = time.RFC1123Z
KitchenLayout = time.Kitchen
RFC2822Layout = time.RFC1123Z
CookieLayout = "Monday, 02-Jan-2006 15:04:05 MST"
RFC3339Layout = "2006-01-02T15:04:05Z07:00"
RFC3339MilliLayout = "2006-01-02T15:04:05.999Z07:00"
RFC3339MicroLayout = "2006-01-02T15:04:05.999999Z07:00"
RFC3339NanoLayout = "2006-01-02T15:04:05.999999999Z07:00"
ISO8601Layout = "2006-01-02T15:04:05-07:00"
ISO8601MilliLayout = "2006-01-02T15:04:05.999-07:00"
ISO8601MicroLayout = "2006-01-02T15:04:05.999999-07:00"
ISO8601NanoLayout = "2006-01-02T15:04:05.999999999-07:00"
RFC1036Layout = "Mon, 02 Jan 06 15:04:05 -0700"
RFC7231Layout = "Mon, 02 Jan 2006 15:04:05 GMT"
DayDateTimeLayout = "Mon, Jan 2, 2006 3:04 PM"
DateTimeLayout = "2006-01-02 15:04:05"
DateTimeMilliLayout = "2006-01-02 15:04:05.999"
DateTimeMicroLayout = "2006-01-02 15:04:05.999999"
DateTimeNanoLayout = "2006-01-02 15:04:05.999999999"
DateLayout = "2006-01-02"
TimeLayout = "15:04:05"
ShortDateTimeLayout = "20060102150405"
ShortDateTimeMilliLayout = "20060102150405.999"
ShortDateTimeMicroLayout = "20060102150405.999999"
ShortDateTimeNanoLayout = "20060102150405.999999999"
ShortDateLayout = "20060102"
ShortTimeLayout = "150405"
)

// Carbon defines a Carbon struct.
Expand Down Expand Up @@ -222,9 +222,9 @@ func (c Carbon) Tomorrow(timezone ...string) Carbon {
}
if c.IsZero() {
c.time = c.Now().Carbon2Time().AddDate(0, 0, 1)
} else {
c.time = c.Carbon2Time().AddDate(0, 0, 1)
return c
}
c.time = c.Carbon2Time().AddDate(0, 0, 1)
return c
}

Expand All @@ -245,9 +245,9 @@ func (c Carbon) Yesterday(timezone ...string) Carbon {
}
if c.IsZero() {
c.time = c.Now().Carbon2Time().AddDate(0, 0, -1)
} else {
c.time = c.Carbon2Time().AddDate(0, 0, -1)
return c
}
c.time = c.Carbon2Time().AddDate(0, 0, -1)
return c
}

Expand Down
18 changes: 9 additions & 9 deletions carbon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,24 @@ func TestCarbon_Now(t *testing.T) {
assert := assert.New(t)

actual1 := Now().ToDateString()
expected1 := time.Now().Format(DateFormat)
expected1 := time.Now().Format(DateLayout)
assert.Equal(expected1, actual1)

actual2 := Now(Local).ToDateString()
expected2 := time.Now().In(time.Local).Format(DateFormat)
expected2 := time.Now().In(time.Local).Format(DateLayout)
assert.Equal(expected2, actual2)
}

func TestCarbon_Yesterday(t *testing.T) {
assert := assert.New(t)

c1 := Yesterday()
expected1 := time.Now().AddDate(0, 0, -1).Format(DateFormat)
expected1 := time.Now().AddDate(0, 0, -1).Format(DateLayout)
assert.Nil(c1.Error)
assert.Equal(expected1, c1.ToDateString())

c2 := Yesterday(Local)
expected2 := time.Now().In(time.Local).AddDate(0, 0, -1).Format(DateFormat)
expected2 := time.Now().In(time.Local).AddDate(0, 0, -1).Format(DateLayout)
assert.Nil(c2.Error)
assert.Equal(expected2, c2.ToDateString())

Expand All @@ -41,12 +41,12 @@ func TestCarbon_Tomorrow(t *testing.T) {
assert := assert.New(t)

c1 := Tomorrow()
expected1 := time.Now().AddDate(0, 0, 1).Format(DateFormat)
expected1 := time.Now().AddDate(0, 0, 1).Format(DateLayout)
assert.Nil(c1.Error)
assert.Equal(expected1, c1.ToDateString())

c2 := Tomorrow(Local)
expected2 := time.Now().In(time.Local).AddDate(0, 0, 1).Format(DateFormat)
expected2 := time.Now().In(time.Local).AddDate(0, 0, 1).Format(DateLayout)
assert.Nil(c2.Error)
assert.Equal(expected2, c2.ToDateString())

Expand All @@ -58,16 +58,16 @@ func TestCarbon_Tomorrow(t *testing.T) {
func TestCarbon_Time2Carbon(t *testing.T) {
assert := assert.New(t)

expected := time.Now().Format(DateTimeFormat)
expected := time.Now().Format(DateTimeLayout)
actual := Time2Carbon(time.Now()).ToDateTimeString()
assert.Equal(expected, actual)
}

func TestCarbon_Carbon2Time(t *testing.T) {
assert := assert.New(t)

expected := time.Now().Format(DateTimeFormat)
actual := Now().Carbon2Time().Format(DateTimeFormat)
expected := time.Now().Format(DateTimeLayout)
actual := Now().Carbon2Time().Format(DateTimeLayout)
assert.Equal(expected, actual)
}

Expand Down
Loading

0 comments on commit e879f7d

Please sign in to comment.