(core) Converting big number (9 digits or more) to date directly

Summary:
Interpret huge numbers (>8 digits) as timestamps when converting numeric column to date.
Convert date/date time columns to timestamp when converted from numeric/int column.

Test Plan: Updated

Reviewers: georgegevoian

Reviewed By: georgegevoian

Subscribers: dsagal, alexmojaki

Differential Revision: https://phab.getgrist.com/D4030
This commit is contained in:
Jarosław Sadziński
2023-10-05 08:48:14 +02:00
parent 498ad07d38
commit ad299f338a
5 changed files with 77 additions and 7 deletions

View File

@@ -11,6 +11,7 @@ import {csvDecodeRow} from 'app/common/csvFormat';
import * as gristTypes from 'app/common/gristTypes';
import {isFullReferencingType} from 'app/common/gristTypes';
import * as gutil from 'app/common/gutil';
import {isNonNullish} from 'app/common/gutil';
import NumberParse from 'app/common/NumberParse';
import {dateTimeWidgetOptions, guessDateFormat, timeFormatOptions} from 'app/common/parseDate';
import {TableData} from 'app/common/TableData';
@@ -134,7 +135,8 @@ export async function prepTransformColInfo(docModel: DocModel, origCol: ColumnRe
if (!dateFormat) {
// Guess date and time format if there aren't any already
const colValues = tableData.getColValues(sourceCol.colId()) || [];
dateFormat = guessDateFormat(colValues.map(String));
const strValues = colValues.map(v => isNonNullish(v) ? String(v) : null);
dateFormat = guessDateFormat(strValues);
widgetOptions = {...widgetOptions, ...(dateTimeWidgetOptions(dateFormat, true))};
}
if (toType === 'DateTime' && !widgetOptions.timeFormat) {