Skip to content

Commit

Permalink
更新
Browse files Browse the repository at this point in the history
  • Loading branch information
deatil committed Mar 8, 2024
1 parent 11f46e7 commit a3847fc
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 10 deletions.
21 changes: 13 additions & 8 deletions datebin/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,35 +147,40 @@ const (
// 时间格式化常量
// formats const
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
RFC2822Format = time.RFC1123Z
KitchenFormat = time.Kitchen
RFC3339Format = time.RFC3339
W3CFormat = RFC3339Format
AnsicFormat = time.ANSIC
UnixDateFormat = time.UnixDate
RubyDateFormat = time.RubyDate
KitchenFormat = time.Kitchen
StampFormat = time.Stamp
StampMilliFormat = time.StampMilli
StampMicroFormat = time.StampMicro
StampNanoFormat = time.StampNano
W3CFormat = RFC3339Format
RFC1036Format = "Mon, 02 Jan 06 15:04:05 -0700"
RFC7231Format = "Mon, 02 Jan 2006 15:04:05 GMT"
RFC3339MilliFormat = "2006-01-02T15:04:05.999Z07:00"
RFC3339MicroFormat = "2006-01-02T15:04:05.999999Z07:00"
RFC3339NanoFormat = "2006-01-02T15:04:05.999999999Z07:00"
CookieFormat = "Monday, 02-Jan-2006 15:04:05 MST"
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"
ISO8601ZuluFormat = "2006-01-02T15:04:05Z"
ISO8601ZuluMilliFormat = "2006-01-02T15:04:05.999Z"
ISO8601ZuluMicroFormat = "2006-01-02T15:04:05.999999Z"
ISO8601ZuluNanoFormat = "2006-01-02T15:04:05.999999999Z"
CookieFormat = "Monday, 02-Jan-2006 15:04:05 MST"
DayDateTimeFormat = "Mon, Jan 2, 2006 3:04 PM"
FormattedDateFormat = "Jan 2, 2006"
FormattedDayDateFormat = "Mon, Jan 2, 2006"
DatetimeNanoFormat = "2006-01-02 15:04:05.999999999"
DatetimeMicroFormat = "2006-01-02 15:04:05.999999"
DatetimeMilliFormat = "2006-01-02 15:04:05.999"
Expand Down
4 changes: 2 additions & 2 deletions datebin/is_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ func Test_IsFuture(t *testing.T) {
},
{
index: "index-2",
date: "2024-03-01 12:00:00",
date: "2055-03-01 12:00:00",
tz: "Local",
check: true,
},
Expand Down Expand Up @@ -333,7 +333,7 @@ func Test_IsPast(t *testing.T) {
},
{
index: "index-2",
date: "2024-03-01 12:00:00",
date: "2066-03-01 12:00:00",
tz: "Local",
check: false,
},
Expand Down
12 changes: 12 additions & 0 deletions datebin/to.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,12 @@ func (this Datebin) ToISO8601String(timezone ...string) string {
return this.ToLayoutString(ISO8601Format, timezone...)
}

// 输出 ISO8601Zulu 格式字符串
// output datetime with ISO8601Zulu layout
func (this Datebin) ToISO8601ZuluString(timezone ...string) string {
return this.ToLayoutString(ISO8601ZuluFormat, timezone...)
}

// 输出 RFC1036 格式字符串
// output datetime with RFC1036 layout
func (this Datebin) ToRFC1036String(timezone ...string) string {
Expand Down Expand Up @@ -380,6 +386,12 @@ func (this Datebin) ToFormattedDateString(timezone ...string) string {
return this.ToLayoutString(FormattedDateFormat, timezone...)
}

// 输出 FormattedDayDate 格式字符串
// output datetime with FormattedDayDate layout
func (this Datebin) ToFormattedDayDateString(timezone ...string) string {
return this.ToLayoutString(FormattedDayDateFormat, timezone...)
}

// 输出 Datetime 格式字符串
// output datetime with Datetime layout
func (this Datebin) ToDatetimeString(timezone ...string) string {
Expand Down
18 changes: 18 additions & 0 deletions datebin/to_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,15 @@ func Test_ToOtherFormatString(t *testing.T) {
},
toDate: "2023-05-03T21:15:12+08:00",
},
{
index: "index-ToISO8601ZuluString",
layout: "2006-01-02 15:04:05",
date: "2023-05-03 21:15:12",
toLayout: func(d Datebin) string {
return d.ToISO8601ZuluString()
},
toDate: "2023-05-03T21:15:12Z",
},
{
index: "index-ToRFC1036String",
layout: "2006-01-02 15:04:05",
Expand Down Expand Up @@ -632,6 +641,15 @@ func Test_ToOtherFormatString(t *testing.T) {
},
toDate: "May 3, 2023",
},
{
index: "index-ToFormattedDayDateString",
layout: "2006-01-02 15:04:05",
date: "2023-05-03 21:15:12",
toLayout: func(d Datebin) string {
return d.ToFormattedDayDateString()
},
toDate: "Wed, May 3, 2023",
},
{
index: "index-ToDatetimeString",
layout: "2006-01-02 15:04:05",
Expand Down
2 changes: 2 additions & 0 deletions docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,12 +210,14 @@ date := datebin.
// ToKitchenString()
// ToCookieString()
// ToISO8601String()
// ToISO8601ZuluString()
// ToRFC1036String()
// ToRFC7231String()
// ToAtomString()
// ToW3CString()
// ToDayDateTimeString()
// ToFormattedDateString()
// ToFormattedDayDateString()
// ToDatetimeString()
// ToDateString()
// ToTimeString()
Expand Down
2 changes: 2 additions & 0 deletions docs_cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,14 @@ date := datebin.
// ToKitchenString()
// ToCookieString()
// ToISO8601String()
// ToISO8601ZuluString()
// ToRFC1036String()
// ToRFC7231String()
// ToAtomString()
// ToW3CString()
// ToDayDateTimeString()
// ToFormattedDateString()
// ToFormattedDayDateString()
// ToDatetimeString()
// ToDateString()
// ToTimeString()
Expand Down

0 comments on commit a3847fc

Please sign in to comment.