Skip to content

Commit

Permalink
fix sub methods
Browse files Browse the repository at this point in the history
  • Loading branch information
guanhui07 committed Oct 3, 2022
1 parent 1f09356 commit 801ba66
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions timex/timex.go
Expand Up @@ -156,7 +156,7 @@ func (t *Time) AddDay(day int) *Time {

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

// Tomorrow time. get tomorrow time for the time
Expand All @@ -177,7 +177,7 @@ func (t *Time) AddHour(hours int) *Time {

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

// AddMinutes add some minutes time for the time
Expand All @@ -187,7 +187,7 @@ func (t *Time) AddMinutes(minutes int) *Time {

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

// AddSeconds add some seconds time the time
Expand All @@ -199,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 801ba66

Please sign in to comment.