Skip to content

Commit

Permalink
enhance: time/timeutil: add/update constants
Browse files Browse the repository at this point in the history
  • Loading branch information
grokify committed Nov 26, 2023
1 parent fa72c24 commit 1f736ba
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
16 changes: 10 additions & 6 deletions time/timeutil/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@ package timeutil
import "time"

const (
Day = 24 * time.Hour
Week = 7 * Day
Day = 24 * time.Hour
Week = 7 * Day
WorkDay = 8 * time.Hour
WorkWeek = 5 * WorkDay
WorkDay996 = 12 * time.Hour
WorkWeek996 = 6 * WorkDay996

DaysPerWeek = float32(7)
HoursPerDay = float32(24)
DaysPerWeek = float32(7)

SecondsPerDay = 24 * 60 * 60
SecondsPerWeek = 7 * SecondsPerDay
SecondsPerYear = (365 * SecondsPerDay) + (6 * 60 * 60)
DaySeconds = 24 * 60 * 60
WeekSeconds = 7 * DaySeconds
YearSeconds = (365 * DaySeconds) + (6 * 60 * 60)

MonthsEN = `["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]`
)
6 changes: 3 additions & 3 deletions time/timeutil/duration.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ func ParseDuration(s string) (time.Duration, error) {
return zeroDuration, err
}
if units == "d" {
s = fmt.Sprintf("%vs", i*SecondsPerDay)
s = fmt.Sprintf("%vs", i*DaySeconds)
} else if units == "w" {
s = fmt.Sprintf("%vs", i*SecondsPerWeek)
s = fmt.Sprintf("%vs", i*WeekSeconds)
} else if units == "y" {
s = fmt.Sprintf("%vs", i*SecondsPerYear)
s = fmt.Sprintf("%vs", i*YearSeconds)
} else {
return zeroDuration, errors.New("timeutil.ParseDuration Parse Error")
}
Expand Down

0 comments on commit 1f736ba

Please sign in to comment.