Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add timex method #63

Merged
merged 2 commits into from Oct 4, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 24 additions & 0 deletions timex/timex.go
Expand Up @@ -154,6 +154,11 @@ func (t *Time) AddDay(day int) *Time {
return t.AddSeconds(day * OneDaySec)
}

// SubDay add some day time for the time
func (t *Time) SubDay(day int) *Time {
return t.AddSeconds(-day * OneDaySec)
}

// Tomorrow time. get tomorrow time for the time
func (t *Time) Tomorrow() *Time {
return t.AddSeconds(OneDaySec)
Expand All @@ -170,11 +175,21 @@ func (t *Time) AddHour(hours int) *Time {
return t.AddSeconds(hours * OneHourSec)
}

// SubHour add some hour time
func (t *Time) SubHour(hours int) *Time {
return t.AddSeconds(-hours * OneHourSec)
}

// AddMinutes add some minutes time for the time
func (t *Time) AddMinutes(minutes int) *Time {
return t.AddSeconds(minutes * OneMinSec)
}

// SubMinutes add some minutes time for the time
func (t *Time) SubMinutes(minutes int) *Time {
return t.AddSeconds(-minutes * OneMinSec)
}

// AddSeconds add some seconds time the time
func (t *Time) AddSeconds(seconds int) *Time {
return &Time{
Expand All @@ -184,6 +199,15 @@ func (t *Time) AddSeconds(seconds int) *Time {
}
}

// SubSeconds add some seconds time the time
func (t *Time) SubSeconds(seconds int) *Time {
return &Time{
Time: t.Add(time.Duration(-seconds) * time.Second),
// with layout
Layout: DefaultLayout,
}
}

// Diff calc diff duration for t - u.
// alias of time.Time.Sub()
func (t Time) Diff(u time.Time) time.Duration {
Expand Down