Skip to content

Commit c20fd0b

Browse files
committed
Fix fixtures test failing on days 29-31
generateMonths used AddDate on the current day, which causes Go to normalize impossible dates (e.g. Feb 29 in non-leap years → Mar 1), producing duplicate month values and UNIQUE constraint violations.
1 parent 560740a commit c20fd0b

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

cmd/fixtures/main.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,13 @@ func run(dbPath string) error {
112112
}
113113

114114
func generateMonths(count int) []int {
115+
// Use the 1st of the month to avoid AddDate normalizing
116+
// days that don't exist (e.g. Feb 29 in non-leap years).
115117
now := time.Now()
118+
first := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, time.UTC)
116119
months := make([]int, count)
117120
for i := range count {
118-
t := now.AddDate(0, -i, 0)
121+
t := first.AddDate(0, -i, 0)
119122
months[i] = t.Year()*monthMultiplier + int(t.Month())
120123
}
121124
return months

0 commit comments

Comments
 (0)