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) {
|
||||
return null;
|
||||
}
|
||||
const dateFormats = PARSER_FORMATS.slice();
|
||||
// If a preferred parse format is given, set that to be the first parser used.
|
||||
if (options.dateFormat) {
|
||||
dateFormats.unshift(..._buildVariations(options.dateFormat, date));
|
||||
}
|
||||
const dateFormat = options.dateFormat || "YYYY-MM-DD";
|
||||
const dateFormats = [..._buildVariations(dateFormat, date), ...PARSER_FORMATS];
|
||||
const cleanDate = date.replace(SEPARATORS, ' ');
|
||||
let datetime = cleanDate.trim();
|
||||
let timeformat = '';
|
||||
@ -148,11 +145,8 @@ export function parseDateStrict(
|
||||
if (!date) {
|
||||
return;
|
||||
}
|
||||
const dateFormats = [];
|
||||
if (dateFormat) {
|
||||
dateFormats.push(..._buildVariations(dateFormat, date));
|
||||
}
|
||||
dateFormats.push(...UNAMBIGUOUS_FORMATS);
|
||||
dateFormat = dateFormat || "YYYY-MM-DD";
|
||||
const dateFormats = [..._buildVariations(dateFormat, date), ...UNAMBIGUOUS_FORMATS];
|
||||
const cleanDate = date.replace(SEPARATORS, ' ').trim();
|
||||
for (const format of dateFormats) {
|
||||
const m = moment.tz(cleanDate, format, true, timezone);
|
||||
@ -173,7 +167,7 @@ export function parseDateTime(dateTime: string, options: ParseOptions): number |
|
||||
return;
|
||||
}
|
||||
|
||||
const dateFormat = options.dateFormat || null;
|
||||
const dateFormat = options.dateFormat || "YYYY-MM-DD";
|
||||
const timezone = options.timezone || "UTC";
|
||||
|
||||
const dateOnly = parseDateStrict(dateTime, dateFormat, undefined, timezone);
|
||||
|
Loading…
Reference in New Issue
Block a user