Skip to content

Commit

Permalink
♻️ refactor: update codebase #2
Browse files Browse the repository at this point in the history
  • Loading branch information
pnguyen215 committed Oct 25, 2024
1 parent e90a20f commit 69cffc1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions const.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,14 +319,14 @@ const (
)

var (
// ApplyTimeRegexp is a regular expression that matches various time formats such as:
// TimeFormatRegexp is a regular expression that matches various time formats such as:
// 15:04:05, 15:04:05.000, 15:04:05.000000, 15, 2017-01-01 15:04, 2021-07-20T00:59:10Z,
// 2021-07-20T00:59:10+08:00, 2021-07-20T00:00:10-07:00, etc.
ApplyTimeRegexp = regexp.MustCompile(`(\s+|^\s*|T)\d{1,2}((:\d{1,2})*|((:\d{1,2}){2}\.(\d{3}|\d{6}|\d{9})))(\s*$|[Z+-])`)
TimeFormatRegexp = regexp.MustCompile(`(\s+|^\s*|T)\d{1,2}((:\d{1,2})*|((:\d{1,2}){2}\.(\d{3}|\d{6}|\d{9})))(\s*$|[Z+-])`)

// OnlyTimeRegexp is a regular expression that matches time formats such as:
// TimeOnlyRegexp is a regular expression that matches time formats such as:
// 15:04:05, 15, 15:04:05.000, 15:04:05.000000, etc.
OnlyTimeRegexp = regexp.MustCompile(`^\s*\d{1,2}((:\d{1,2})*|((:\d{1,2}){2}\.(\d{3}|\d{6}|\d{9})))\s*$`)
TimeOnlyRegexp = regexp.MustCompile(`^\s*\d{1,2}((:\d{1,2})*|((:\d{1,2}){2}\.(\d{3}|\d{6}|\d{9})))\s*$`)
)

var (
Expand Down
4 changes: 2 additions & 2 deletions time.go
Original file line number Diff line number Diff line change
Expand Up @@ -623,8 +623,8 @@ func (t *Timex) Parse(s ...string) (value time.Time, err error) {
)

for _, str := range s {
hasTimeInStr := ApplyTimeRegexp.MatchString(str) // match 15:04:05, 15
onlyTimeInStr = hasTimeInStr && onlyTimeInStr && OnlyTimeRegexp.MatchString(str)
hasTimeInStr := TimeFormatRegexp.MatchString(str) // match 15:04:05, 15
onlyTimeInStr = hasTimeInStr && onlyTimeInStr && TimeOnlyRegexp.MatchString(str)
if value, err = t.parseWithFormat(str, currentLocation); err == nil {
location := value.Location()
parseTime = FormatTimex(value)
Expand Down

0 comments on commit 69cffc1

Please sign in to comment.