Skip to content

Commit

Permalink
优化错误处理,引用errors.go里的错误
Browse files Browse the repository at this point in the history
  • Loading branch information
gouguoyin committed Jul 23, 2021
1 parent 6ea0479 commit 723b4dc
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package carbon

import (
"bytes"
"errors"
"fmt"
"time"
)

Expand Down Expand Up @@ -58,16 +56,16 @@ func format2layout(format string) string {
func getLocationByTimezone(timezone string) (*time.Location, error) {
loc, err := time.LoadLocation(timezone)
if err != nil {
err = errors.New(fmt.Sprintf("invalid timezone %q, please see the file %q for all valid timezones", timezone, "$GOROOT/lib/time/zoneinfo.zip"))
err = invalidTimezoneError(timezone)
}
return loc, err
}

// parseByDuration 通过持续时间解析
// parseByDuration 通过持续时长解析
func parseByDuration(duration string) (time.Duration, error) {
td, err := time.ParseDuration(duration)
if err != nil {
err = errors.New(fmt.Sprintf("invalid duration %q, please make sure the duration is valid", duration))
err = invalidDurationError(duration)
}
return td, err
}
Expand Down

0 comments on commit 723b4dc

Please sign in to comment.