Skip to content

Commit

Permalink
更新
Browse files Browse the repository at this point in the history
  • Loading branch information
deatil committed Mar 13, 2023
1 parent d0d8c67 commit 87a1643
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 25 deletions.
2 changes: 1 addition & 1 deletion pkg/lakego-pkg/go-datebin/datebin/offset.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func (this Datebin) Offset(field string, offset int, timezone ...string) Datebin
if error == nil {
this.loc = loc
}

this.AppendError(error)
}

Expand Down
1 change: 0 additions & 1 deletion pkg/lakego-pkg/go-datebin/datebin/on.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,3 @@ func (this Datebin) OnError(fn ErrorFunc) Datebin {

return this
}

10 changes: 4 additions & 6 deletions pkg/lakego-pkg/go-datebin/datebin/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ func (this Datebin) Parse(date string) Datebin {
}

time, err := time.Parse(layout, date)
if err != nil {
return this
}
this.AppendError(err)

this.time = time

Expand All @@ -59,7 +57,7 @@ func (this Datebin) ParseWithLayout(date string, layout string, timezone ...stri
if err == nil {
this.loc = loc
}

this.AppendError(err)
}

Expand All @@ -73,11 +71,11 @@ func (this Datebin) ParseWithLayout(date string, layout string, timezone ...stri

// 用格式化字符解析时间字符
func (this Datebin) ParseWithFormat(date string, format string, timezone ...string) Datebin {
return this.ParseWithLayout(date, this.FormatParseLayout(format), timezone...)
return this.ParseWithLayout(date, this.formatParseLayout(format), timezone...)
}

// 格式化解析 layout
func (this Datebin) FormatParseLayout(str string) string {
func (this Datebin) formatParseLayout(str string) string {
var buffer bytes.Buffer

for i := 0; i < len(str); i++ {
Expand Down
24 changes: 12 additions & 12 deletions pkg/lakego-pkg/go-datebin/datebin/to.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ func (this Datebin) ToString(timezone ...string) string {
if error == nil {
this.loc = loc
}

this.AppendError(error)
}

if this.IsInvalid() {
return ""
}
Expand All @@ -36,10 +36,10 @@ func (this Datebin) ToStarString(timezone ...string) string {
if error == nil {
this.loc = loc
}

this.AppendError(error)
}

if this.IsInvalid() {
return ""
}
Expand Down Expand Up @@ -99,10 +99,10 @@ func (this Datebin) ToSeasonString(timezone ...string) string {
if error == nil {
this.loc = loc
}

this.AppendError(error)
}

if this.IsInvalid() {
return ""
}
Expand Down Expand Up @@ -136,10 +136,10 @@ func (this Datebin) ToWeekdayString(timezone ...string) string {
if error == nil {
this.loc = loc
}

this.AppendError(error)
}

if this.IsInvalid() {
return ""
}
Expand All @@ -156,10 +156,10 @@ func (this Datebin) Layout(layout string, timezone ...string) string {
if error == nil {
this.loc = loc
}

this.AppendError(error)
}

if this.IsInvalid() {
return ""
}
Expand All @@ -176,11 +176,11 @@ func (this Datebin) ToLayoutString(layout string, timezone ...string) string {
func (this Datebin) Format(layout string, timezone ...string) string {
if len(timezone) > 0 {
loc, error := this.GetLocationByTimezone(timezone[0])

this.loc = loc
this.AppendError(error)
}

if this.IsInvalid() {
return ""
}
Expand Down
17 changes: 12 additions & 5 deletions pkg/lakego-pkg/go-datebin/example.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,27 @@ import (
#### 获取错误信息及常规数据获取和设置

~~~go
var datebinErr error

// 方式1
var datebinErrs []error
date := datebin.
Now().
OnError(func(err error) {
datebinErr = err
OnError(func(err []error) {
datebinErrs = err
}).
ToDatetimeString()

// 方式2
errs := datebin.
Parse("2022-101-23 22:18:56").
GetErrors()

// 方式3
err := datebin.
Parse("2022-101-23 22:18:56").
GetError()
Error()
if err != nil {
// todo
}

// 常规数据设置及获取
datebin.WithTime(time time.Time) # 设置时间
Expand Down

0 comments on commit 87a1643

Please sign in to comment.