From 3720c2d88fb26d3e7970b36f58955cb2cbf8076c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=85=89=E6=98=A5?= Date: Mon, 30 May 2022 09:42:05 +0800 Subject: [PATCH] =?UTF-8?q?-=20time=EF=BC=9A=E5=A2=9E=E5=8A=A0=20`BeforeMi?= =?UTF-8?q?nute`=20=E8=8E=B7=E5=8F=96n=E5=88=86=E9=92=9F=E5=89=8D=E7=9A=84?= =?UTF-8?q?=E6=97=B6=E9=97=B4=E6=96=B9=E6=B3=95=20-=20time=EF=BC=9A?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20`AfterMinute`=20=E8=8E=B7=E5=8F=96n?= =?UTF-8?q?=E5=88=86=E9=92=9F=E5=90=8E=E7=9A=84=E6=97=B6=E9=97=B4=E6=96=B9?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 2 ++ gotime/gotime.go | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c2279548..6058d17f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ ## v2022-05-30 - array:增加 `RemoveDuplicateElement` 去重方法 +- time:增加 `BeforeMinute` 获取n分钟前的时间方法 +- time:增加 `AfterMinute` 获取n分钟后的时间方法 ## v2022-05-27 diff --git a/gotime/gotime.go b/gotime/gotime.go index b10633b4..3bd7dfe0 100644 --- a/gotime/gotime.go +++ b/gotime/gotime.go @@ -49,6 +49,20 @@ func (p Pro) AfterSeconds(seconds int) Pro { return p } +// BeforeMinute 获取n分钟前的时间 +func (p Pro) BeforeMinute(seconds int) Pro { + st, _ := time.ParseDuration(fmt.Sprintf("-%dm", seconds)) + p.Time = p.Time.Add(st) + return p +} + +// AfterMinute 获取n分钟后的时间 +func (p Pro) AfterMinute(seconds int) Pro { + st, _ := time.ParseDuration(fmt.Sprintf("+%dm", seconds)) + p.Time = p.Time.Add(st) + return p +} + // BeforeHour 获取n小时前的时间 func (p Pro) BeforeHour(hour int) Pro { st, _ := time.ParseDuration(fmt.Sprintf("-%dh", hour))