refactor(moment): Replace Moment.js with DayJs (#31310)

This commit is contained in:
Mehmet Salih Yavuz
2024-12-23 20:42:43 +03:00
committed by GitHub
parent b382ef1058
commit a193d790b2
41 changed files with 268 additions and 212 deletions

View File

@@ -16,7 +16,8 @@
* specific language governing permissions and limitations
* under the License.
*/
import moment from 'moment';
import dayjs from 'dayjs';
import utc from 'dayjs/plugin/utc';
import {
ChartProps,
getMetricLabel,
@@ -27,9 +28,11 @@ import {
} from '@superset-ui/core';
import { getComparisonFontSize, getHeaderFontSize } from './utils';
dayjs.extend(utc);
export const parseMetricValue = (metricValue: number | string | null) => {
if (typeof metricValue === 'string') {
const dateObject = moment.utc(metricValue, moment.ISO_8601, true);
const dateObject = dayjs.utc(metricValue, undefined, true);
if (dateObject.isValid()) {
return dateObject.valueOf();
}

View File

@@ -17,7 +17,8 @@
* under the License.
*/
import moment from 'moment';
import dayjs from 'dayjs';
import utc from 'dayjs/plugin/utc';
import {
getTimeFormatter,
getTimeFormatterForGranularity,
@@ -25,9 +26,11 @@ import {
TimeGranularity,
} from '@superset-ui/core';
dayjs.extend(utc);
export const parseMetricValue = (metricValue: number | string | null) => {
if (typeof metricValue === 'string') {
const dateObject = moment.utc(metricValue, moment.ISO_8601, true);
const dateObject = dayjs.utc(metricValue, undefined, true);
if (dateObject.isValid()) {
return dateObject.valueOf();
}