fix: align report date defaults with recent periods

This commit is contained in:
Yvan
2026-11-05 14:26:36 +08:00
parent 31584c73bf
commit 22ba319f7f
16 changed files with 181 additions and 70 deletions
+18
View File
@@ -0,0 +1,18 @@
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
}