This commit is contained in:
王昆 2024-05-05 02:13:14 -03:00 committed by GitHub
commit 8a2c53198d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 17 additions and 6 deletions

View File

@ -26,7 +26,7 @@ export const PREVIEW_TIME = new Date(Date.UTC(2017, 1, 14, 11, 22, 33));
// Use type augmentation to indicate that
// an instance of TimeFormatter is also a function
interface TimeFormatter {
(value: Date | number | null | undefined): string;
(value: Date | number | object | null | undefined): string;
}
class TimeFormatter extends ExtensibleFunction {
@ -47,7 +47,9 @@ class TimeFormatter extends ExtensibleFunction {
formatFunc: TimeFormatFunction;
useLocalTime?: boolean;
}) {
super((value: Date | number | null | undefined) => this.format(value));
super((value: Date | number | object | null | undefined) =>
this.format(value),
);
const {
id = isRequired('config.id'),
@ -64,7 +66,7 @@ class TimeFormatter extends ExtensibleFunction {
this.useLocalTime = useLocalTime;
}
format(value: Date | number | null | undefined) {
format(value: Date | number | object | null | undefined): string {
return stringifyTimeInput(value, time => this.formatFunc(time));
}

View File

@ -18,12 +18,18 @@
*/
export default function stringifyTimeInput(
value: Date | number | undefined | null,
value: Date | number | object | undefined | null,
fn: (time: Date) => string,
) {
if (value === null || value === undefined) {
return `${value}`;
}
return fn(value instanceof Date ? value : new Date(value));
return fn(
value instanceof Date
? value
: typeof value === 'number'
? new Date(value)
: new Date(parseInt(String(value?.toString()), 10)),
);
}

View File

@ -40,6 +40,9 @@ export default class DateWithFormatter extends Date {
if (typeof value === 'string') {
value = normalizeTimestamp(value);
}
if (typeof value === 'object') {
value = parseInt(String(value?.toString()), 10);
}
super(value as string);

View File

@ -347,7 +347,7 @@ export const useTableColumns = (
if (
colType === GenericDataType.Temporal &&
originalFormattedTimeColumnIndex === -1 &&
typeof value === 'number'
(typeof value === 'number' || typeof value === 'object')
) {
return timeFormatter(value);
}