fix(grid): format Mongo shell date values
This commit is contained in:
1 parent
b855923a21
commit
cd51e247cb
2 files changed
+26
No files matched your search
@@ -51,6 +51,7 @@ const STRICT_LOCAL_DATETIME_INPUT_PATTERNS = [
|
||||
];
|
||||
const ISO_OFFSET_DATETIME_PATTERN = /^(\d{4})([-/])(\d{2})\2(\d{2})T(\d{2}):(\d{2}):(\d{2})(\.\d{1,9})?(Z|[+-]\d{2}:\d{2})$/;
|
||||
const FRACTIONAL_LOCAL_DATETIME_PATTERN = /^(\d{4})([-/])(\d{1,2})\2(\d{1,2})([ T])(\d{1,2}):(\d{1,2}):(\d{1,2})\.(\d{1,9})$/;
|
||||
const MONGO_SHELL_DATE_PATTERN = /^(?:ISODate|new Date)\(\s*(["'])(.+)\1\s*\)$/;
|
||||
|
||||
export interface CustomColumnFormatterConfig {
|
||||
id: string;
|
||||
@@ -262,6 +263,11 @@ function resolveDateTimeValue(value: string | number, unit: DateTimeFormatterUni
|
||||
if (!trimmed) {
|
||||
return undefined;
|
||||
}
|
||||
const mongoShellDate = unwrapMongoShellDate(trimmed);
|
||||
if (mongoShellDate !== undefined) {
|
||||
return parseStrictDateTimeString(mongoShellDate);
|
||||
}
|
||||
|
||||
const timestamp = parseTimestampMilliseconds(trimmed, unit);
|
||||
if (timestamp !== undefined) {
|
||||
const parsedTimestamp = dayjs(timestamp);
|
||||
@@ -279,6 +285,10 @@ function resolveDateTimeValue(value: string | number, unit: DateTimeFormatterUni
|
||||
return parsedTimestamp.isValid() ? parsedTimestamp : undefined;
|
||||
}
|
||||
|
||||
function unwrapMongoShellDate(value: string): string | undefined {
|
||||
return value.match(MONGO_SHELL_DATE_PATTERN)?.[2];
|
||||
}
|
||||
|
||||
function normalizeDateTimePattern(pattern: unknown): string {
|
||||
return typeof pattern === "string" && pattern.trim() ? pattern : DEFAULT_DATETIME_PATTERN;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user