From 1bb4ed17f02267598f62a45fb6deb93985365868 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=85=89=E6=98=A5?= Date: Tue, 7 Jun 2022 18:05:19 +0800 Subject: [PATCH] =?UTF-8?q?-=20time=EF=BC=9A=E5=A2=9E=E5=8A=A0=E6=AF=94?= =?UTF-8?q?=E8=BE=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 1 + gotime/compare.go | 65 +++++++++++++++++++++++++++++ gotime/{Tomorrow.go => tomorrow.go} | 0 3 files changed, 66 insertions(+) create mode 100644 gotime/compare.go rename gotime/{Tomorrow.go => tomorrow.go} (100%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 41536710..cb3587f5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ - jobs:优化配置 - jobs:增加自定义目录配置 +- time:增加比较 ## v2022-05-31 diff --git a/gotime/compare.go b/gotime/compare.go new file mode 100644 index 00000000..bc899641 --- /dev/null +++ b/gotime/compare.go @@ -0,0 +1,65 @@ +package gotime + +import "time" + +// Gt 是否大于 +func (p Pro) Gt(t2 time.Time) bool { + return p.Time.After(t2) +} + +// Lt 是否小于 +func (p Pro) Lt(t2 time.Time) bool { + return p.Time.Before(t2) +} + +// Eq 是否等于 +func (p Pro) Eq(t2 time.Time) bool { + return p.Time.Equal(t2) +} + +// Ne 是否不等于 +func (p Pro) Ne(t2 time.Time) bool { + return !p.Eq(t2) +} + +// Gte 是否大于等于 +func (p Pro) Gte(t2 time.Time) bool { + return p.Gt(t2) || p.Eq(t2) +} + +// Lte 是否小于等于 +func (p Pro) Lte(t2 time.Time) bool { + return p.Lt(t2) || p.Eq(t2) +} + +// Between 是否在两个时间之间(不包括这两个时间) +func (p Pro) Between(start time.Time, end time.Time) bool { + if p.Gt(start) && p.Lt(end) { + return true + } + return false +} + +// BetweenIncludedStart 是否在两个时间之间(包括开始时间) +func (p Pro) BetweenIncludedStart(start time.Time, end time.Time) bool { + if p.Gte(start) && p.Lt(end) { + return true + } + return false +} + +// BetweenIncludedEnd 是否在两个时间之间(包括结束时间) +func (p Pro) BetweenIncludedEnd(start time.Time, end time.Time) bool { + if p.Gt(start) && p.Lte(end) { + return true + } + return false +} + +// BetweenIncludedBoth 是否在两个时间之间(包括这两个时间) +func (p Pro) BetweenIncludedBoth(start time.Time, end time.Time) bool { + if p.Gte(start) && p.Lte(end) { + return true + } + return false +} diff --git a/gotime/Tomorrow.go b/gotime/tomorrow.go similarity index 100% rename from gotime/Tomorrow.go rename to gotime/tomorrow.go