diff --git a/README.md b/README.md index 1645350..074c033 100755 --- a/README.md +++ b/README.md @@ -164,6 +164,15 @@ c.Now().SubMonths(3).ToDateTimeString() // 2020-06-08 13:00:00 // 一月前 c.Now().SubMonth().ToDateTimeString() // 2020-08-08 13:00:00 +// 三周后 +c.Now().AddWeeks(3).ToDateTimeString() // 2020-09-29 13:00:00 +// 一周后 +c.Now().AddWeek().ToDateTimeString() // 2020-09-15 13:00:00 +// 三周前 +c.Now().SubWeeks(3).ToDateTimeString() // 2020-08-17 13:00:00 +// 一周前 +c.Now().SubWeek().ToDateTimeString() // 2020-09-01 13:00:00 + // 三天后 c.Now().AddDays(3).ToDateTimeString() // 2020-09-11 13:00:00 // 一天后 diff --git a/carbon.go b/carbon.go index a32b779..76094b1 100755 --- a/carbon.go +++ b/carbon.go @@ -120,6 +120,30 @@ func (c *Carbon) SubMonth() *Carbon { return c } +// AddWeeks N周后 +func (c *Carbon) AddWeeks(weeks int) *Carbon { + c.Time = c.Time.AddDate(0, 0, weeks*7) + return c +} + +// AddWeek 1周后 +func (c *Carbon) AddWeek() *Carbon { + c.Time = c.Time.AddDate(0, 0, 7) + return c +} + +// SubWeeks N周前 +func (c *Carbon) SubWeeks(weeks int) *Carbon { + c.Time = c.Time.AddDate(0, 0, -weeks*7) + return c +} + +// SubMonth 减少1月 +func (c *Carbon) SubWeek() *Carbon { + c.Time = c.Time.AddDate(0, 0, -7) + return c +} + // AddDays N天后 func (c *Carbon) AddDays(days int) *Carbon { c.Time = c.Time.AddDate(0, 0, days)