Files
kra-new/internal/biz/business/report_dates.go
T

19 lines
545 B
Go

package business
import "time"
// reportDateDefaults fills missing bounds without discarding an explicit date.
// Reports include the end date, so a 30-day period starts 29 days earlier.
func reportDateDefaults(begin, end *time.Time, days int, now time.Time) (*time.Time, *time.Time) {
if end == nil {
local := now.In(portraitLocation)
day := time.Date(local.Year(), local.Month(), local.Day(), 0, 0, 0, 0, portraitLocation)
end = &day
}
if begin == nil {
first := end.AddDate(0, 0, 1-days)
begin = &first
}
return begin, end
}