birthday-notifier/pkg/dateutil/date.go
2024-03-11 13:17:17 +01:00

25 lines
819 B
Go

package dateutil
import "time"
// IsToday uses ProjectToNextBirthday to get the next birthday and
// compares it to TodayStartOfDay
func IsToday(t time.Time) bool {
return ProjectToNextBirthday(t).
Equal(TodayStartOfDay())
}
// ProjectToNextBirthday takes a birth date and projects it to the
// next birthday being today or later
func ProjectToNextBirthday(t time.Time) time.Time {
projected := time.Date(time.Now().Year(), t.Month(), t.Day(), 0, 0, 0, 0, time.Local)
if projected.Before(TodayStartOfDay()) {
projected = time.Date(time.Now().Year()+1, t.Month(), t.Day(), 0, 0, 0, 0, time.Local)
}
return projected
}
// TodayStartOfDay gets the start of the current day
func TodayStartOfDay() time.Time {
return time.Date(time.Now().Year(), time.Now().Month(), time.Now().Day(), 0, 0, 0, 0, time.Local)
}