diff --git a/util.go b/util.go index a648f14..ec132b3 100644 --- a/util.go +++ b/util.go @@ -42,6 +42,16 @@ func EndOfDayStr(f ...string) string { return EndOfDay().Format(time.DateTime) } +// GetPreviousDay 获取指定日期的前一天 +func GetPreviousDay(t time.Time) time.Time { + return t.AddDate(0, 0, -1) +} + +// GetNextDay 获取指定日期的下一天 +func GetNextDay(t time.Time) time.Time { + return t.AddDate(0, 0, 1) +} + // ===================================================================================================================== // 周 @@ -312,3 +322,8 @@ func GetDatesInRange(start, end time.Time) []time.Time { func DayOfYear(t time.Time) int { return t.YearDay() } + +// InDuration 判断指定时间是否在指定时间段内 +func InDuration(t, start, end time.Time) bool { + return t.After(start) && t.Before(end) +}