fix(core): Fix timezone-dependent test failures in Insights weekly compaction (#15680)

This commit is contained in:
Matt Habermehl
2025-06-02 06:07:06 -04:00
committed by GitHub
parent e53116aff3
commit 096806af15
2 changed files with 6 additions and 6 deletions

View File

@@ -436,7 +436,7 @@ describe('compaction', () => {
// 2000-01-03 is a Monday // 2000-01-03 is a Monday
DateTime.utc(2000, 1, 3, 0, 0), DateTime.utc(2000, 1, 3, 0, 0),
DateTime.utc(2000, 1, 5, 23, 59), DateTime.utc(2000, 1, 5, 23, 59),
DateTime.utc(2000, 1, 11, 1, 0), DateTime.utc(2000, 1, 10, 1, 0),
], ],
batches: [2, 1], batches: [2, 1],
}, },
@@ -446,9 +446,9 @@ describe('compaction', () => {
// 2000-01-03 is a Monday // 2000-01-03 is a Monday
DateTime.utc(2000, 1, 3, 0, 0), DateTime.utc(2000, 1, 3, 0, 0),
DateTime.utc(2000, 1, 4, 23, 59), DateTime.utc(2000, 1, 4, 23, 59),
DateTime.utc(2000, 1, 11, 0, 0), DateTime.utc(2000, 1, 10, 0, 0),
DateTime.utc(2000, 1, 12, 23, 59), DateTime.utc(2000, 1, 11, 23, 59),
DateTime.utc(2000, 1, 18, 23, 59), DateTime.utc(2000, 1, 17, 23, 59),
], ],
batches: [2, 2, 1], batches: [2, 2, 1],
}, },
@@ -482,7 +482,7 @@ describe('compaction', () => {
const allCompacted = await insightsByPeriodRepository.find({ order: { periodStart: 1 } }); const allCompacted = await insightsByPeriodRepository.find({ order: { periodStart: 1 } });
expect(allCompacted).toHaveLength(batches.length); expect(allCompacted).toHaveLength(batches.length);
for (const [index, compacted] of allCompacted.entries()) { for (const [index, compacted] of allCompacted.entries()) {
expect(compacted.periodStart.getDay()).toBe(1); expect(compacted.periodStart.getUTCDay()).toBe(1);
expect(compacted.value).toBe(batches[index]); expect(compacted.value).toBe(batches[index]);
} }
}); });

View File

@@ -90,7 +90,7 @@ export class InsightsByPeriodRepository extends Repository<InsightsByPeriod> {
// SQLite by default // SQLite by default
let periodStartExpr = let periodStartExpr =
periodUnitToCompactInto === 'week' periodUnitToCompactInto === 'week'
? "strftime('%Y-%m-%d 00:00:00.000', date(periodStart, 'weekday 0', '-6 days'))" ? "strftime('%Y-%m-%d 00:00:00.000', date(periodStart, '-6 days', 'weekday 1'))"
: `strftime('%Y-%m-%d ${periodUnitToCompactInto === 'hour' ? '%H' : '00'}:00:00.000', periodStart)`; : `strftime('%Y-%m-%d ${periodUnitToCompactInto === 'hour' ? '%H' : '00'}:00:00.000', periodStart)`;
if (dbType === 'mysqldb' || dbType === 'mariadb') { if (dbType === 'mysqldb' || dbType === 'mariadb') {
periodStartExpr = periodStartExpr =