:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(charts): label a newest-first date axis with dates (#89994)
Sinan Kucukkoseleraca8dd9451bc
diff --git a/packages/quill/packages/charts/src/utils/dates.test.ts b/packages/quill/packages/charts/src/utils/dates.test.tsindex 0db1b698e0d3..ecbe3954e177 100644--- a/packages/quill/packages/charts/src/utils/dates.test.ts+++ b/packages/quill/packages/charts/src/utils/dates.test.ts@@ -59,6 +59,51 @@ describe('createXAxisTickCallback', () => {allDays: ['2025-04-01 10:00:00', '2025-04-01 10:01:00', '2025-04-01 10:02:00'],expected: ['10:00', '10:01', '10:02'],},+ {+ scenario: 'hourly, single day, newest-first → still HH:mm, no date markers',+ interval: undefined,+ allDays: hourlyDates('2025-04-01', 6).reverse(),+ expected: ['05:00', '04:00', '03:00', '02:00', '01:00', '00:00'],+ },+ {+ scenario: 'inferred day interval from newest-first daily results',+ interval: undefined,+ allDays: ['2025-04-03 00:00:00', '2025-04-02 00:00:00', '2025-04-01 00:00:00'],+ expected: ['Apr 3', 'Apr 2', 'April'],+ },+ {+ scenario: 'weekly, long span, newest-first → same month labels as oldest-first',+ interval: 'week' as const,+ allDays: weeklyDates('2025-09-01', 18).reverse(),+ expected: sparseLabels(18, {+ 0: 'December',+ 5: 'November',+ 9: 'October',+ 13: 'September',+ }),+ },+ {+ scenario: 'hourly, multi-day, newest-first → date at each day start, HH:mm every 6h',+ interval: 'hour' as const,+ allDays: hourlyDates('2025-02-15', 72).reverse(),+ expected: sparseLabels(72, {+ 0: 'Feb 17',+ 5: '18:00',+ 11: '12:00',+ 17: '06:00',+ 23: '00:00',+ 24: 'Feb 16',+ 29: '18:00',+ 35: '12:00',+ 41: '06:00',+ 47: '00:00',+ 48: 'Feb 15',+ 53: '18:00',+ 59: '12:00',+ 65: '06:00',+ 71: '00:00',+ }),+ },{scenario: 'second interval formats as HH:mm',interval: 'second' as const,diff --git a/packages/quill/packages/charts/src/utils/dates.ts b/packages/quill/packages/charts/src/utils/dates.tsindex 3e240792d152..cc0590f86de3 100644--- a/packages/quill/packages/charts/src/utils/dates.ts+++ b/packages/quill/packages/charts/src/utils/dates.ts@@ -89,8 +89,8 @@ export function createTooltipDateFormatter({}function pickMode(interval: TimeInterval, parsedDates: Dayjs[], first: Dayjs, last: Dayjs): TickMode {- const spanMonths = (last.year() - first.year()) * 12 + last.month() - first.month()- const spanDays = last.diff(first, 'day')+ const spanMonths = Math.abs((last.year() - first.year()) * 12 + last.month() - first.month())+ const spanDays = Math.abs(last.diff(first, 'day'))if (interval === 'quarter') {return { type: 'quarter' }@@ -167,14 +167,14 @@ function inferInterval(parsedDates: Dayjs[]): TimeInterval {if (parsedDates.length < 2) {return 'day'}- const diffHours = parsedDates[1].diff(parsedDates[0], 'hour')+ const diffHours = Math.abs(parsedDates[1].diff(parsedDates[0], 'hour'))if (diffHours < 1) {return 'minute'}if (diffHours < 24) {return 'hour'}- const diffDays = parsedDates[1].diff(parsedDates[0], 'day')+ const diffDays = Math.abs(parsedDates[1].diff(parsedDates[0], 'day'))if (diffDays >= 300) {return 'year'}