EnxDev commented on code in PR #38017:
URL: https://github.com/apache/superset/pull/38017#discussion_r2832194500
##########
superset-frontend/plugins/plugin-chart-echarts/src/utils/formatters.ts:
##########
@@ -29,13 +29,82 @@ import {
SMART_DATE_ID,
SMART_DATE_VERBOSE_ID,
TimeFormatter,
+ TimeGranularity,
ValueFormatter,
} from '@superset-ui/core';
export const getSmartDateDetailedFormatter = () =>
getTimeFormatter(SMART_DATE_DETAILED_ID);
-export const getSmartDateFormatter = () => getTimeFormatter(SMART_DATE_ID);
+export const getSmartDateFormatter = (timeGrain?: string) => {
+ const baseFormatter = getTimeFormatter(SMART_DATE_ID);
+
+ // If no time grain provided, use the standard smart date formatter
+ if (!timeGrain) {
+ return baseFormatter;
+ }
+
+ // Create a wrapper that normalizes dates based on time grain
+ return new TimeFormatter({
+ id: SMART_DATE_ID,
+ label: baseFormatter.label,
+ formatFunc: (date: Date) => {
+ // Create a normalized date based on time grain to ensure consistent
smart formatting
+ const normalizedDate = new Date(date);
+
+ // Always remove milliseconds to prevent .XXXms format
+ normalizedDate.setMilliseconds(0);
+
+ // For all time grains, normalize using UTC methods to avoid timezone
issues
+ if (timeGrain === TimeGranularity.YEAR || timeGrain === 'P1Y') {
Review Comment:
Just to better understand, is there a specific reason for the double
comparison here, considering that TimeGranularity.YEAR equals 'P1Y'?
Is the same for the others
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]