diff --git a/goextVersion.go b/goextVersion.go index 011d84c..c2600b1 100644 --- a/goextVersion.go +++ b/goextVersion.go @@ -1,5 +1,5 @@ package goext -const GoextVersion = "0.0.245" +const GoextVersion = "0.0.246" -const GoextVersionTimestamp = "2023-08-21T13:27:36+0200" +const GoextVersionTimestamp = "2023-08-21T14:15:06+0200" diff --git a/timeext/time.go b/timeext/time.go index bae5a51..677bbd7 100644 --- a/timeext/time.go +++ b/timeext/time.go @@ -22,6 +22,17 @@ func TimeToDatePart(t time.Time, tz *time.Location) time.Time { return time.Date(t.Year(), t.Month(), t.Day(), 0, 0, 0, 0, t.Location()) } +// TimeToDayStart returns a timestamp at the start of the day which contains t (= 00:00:00) +func TimeToDayStart(t time.Time, tz *time.Location) time.Time { + t = t.In(tz) + return time.Date(t.Year(), t.Month(), t.Day(), 0, 0, 0, 0, t.Location()) +} + +// TimeToDayEnd returns a timestamp at the end of the day which contains t (= 23:59:59) +func TimeToDayEnd(t time.Time, tz *time.Location) time.Time { + return TimeToDayStart(t, tz).AddDate(0, 1, 0).Add(-1) +} + // TimeToWeekStart returns a timestamp at the start of the week which contains t (= Monday 00:00:00) func TimeToWeekStart(t time.Time, tz *time.Location) time.Time { t = TimeToDatePart(t, tz)