mirror of
https://github.com/gristlabs/grist-core.git
synced 2024-10-27 20:44:07 +00:00
(core) Use YYYY-MM-DD as default date format for parsing
Summary: By default, new date columns show "YYYY-MM-DD" as the date format in the UI, but under the hood it's stored as null/undefined, which affects parsing during pasting and type conversion. This changes the underlying parsing to always default to YYYY-MM-DD, as if that format was explicitly selected, making things more consistent. Test Plan: Updated some tests. Reviewers: georgegevoian Reviewed By: georgegevoian Subscribers: dsagal Differential Revision: https://phab.getgrist.com/D3265
This commit is contained in:
parent
afa90cc365
commit
8b5e837d9c
@ -104,11 +104,8 @@ export function parseDate(date: string, options: ParseOptions = {}): number | nu
|
|||||||
if (!date) {
|
if (!date) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
const dateFormats = PARSER_FORMATS.slice();
|
const dateFormat = options.dateFormat || "YYYY-MM-DD";
|
||||||
// If a preferred parse format is given, set that to be the first parser used.
|
const dateFormats = [..._buildVariations(dateFormat, date), ...PARSER_FORMATS];
|
||||||
if (options.dateFormat) {
|
|
||||||
dateFormats.unshift(..._buildVariations(options.dateFormat, date));
|
|
||||||
}
|
|
||||||
const cleanDate = date.replace(SEPARATORS, ' ');
|
const cleanDate = date.replace(SEPARATORS, ' ');
|
||||||
let datetime = cleanDate.trim();
|
let datetime = cleanDate.trim();
|
||||||
let timeformat = '';
|
let timeformat = '';
|
||||||
@ -148,11 +145,8 @@ export function parseDateStrict(
|
|||||||
if (!date) {
|
if (!date) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const dateFormats = [];
|
dateFormat = dateFormat || "YYYY-MM-DD";
|
||||||
if (dateFormat) {
|
const dateFormats = [..._buildVariations(dateFormat, date), ...UNAMBIGUOUS_FORMATS];
|
||||||
dateFormats.push(..._buildVariations(dateFormat, date));
|
|
||||||
}
|
|
||||||
dateFormats.push(...UNAMBIGUOUS_FORMATS);
|
|
||||||
const cleanDate = date.replace(SEPARATORS, ' ').trim();
|
const cleanDate = date.replace(SEPARATORS, ' ').trim();
|
||||||
for (const format of dateFormats) {
|
for (const format of dateFormats) {
|
||||||
const m = moment.tz(cleanDate, format, true, timezone);
|
const m = moment.tz(cleanDate, format, true, timezone);
|
||||||
@ -173,7 +167,7 @@ export function parseDateTime(dateTime: string, options: ParseOptions): number |
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const dateFormat = options.dateFormat || null;
|
const dateFormat = options.dateFormat || "YYYY-MM-DD";
|
||||||
const timezone = options.timezone || "UTC";
|
const timezone = options.timezone || "UTC";
|
||||||
|
|
||||||
const dateOnly = parseDateStrict(dateTime, dateFormat, undefined, timezone);
|
const dateOnly = parseDateStrict(dateTime, dateFormat, undefined, timezone);
|
||||||
|
Loading…
Reference in New Issue
Block a user