Skip to content

Commit

Permalink
Merge pull request #63 from guanhui07/add_timex_method
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Oct 4, 2022
2 parents 7eaa5e5 + 801ba66 commit 01f229c
Showing 1 changed file with 24 additions and 0 deletions.
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

0 comments on commit 01f229c

Please sign in to comment.