(core) ValueParser for Date columns

Summary: Adds parseDateStrict function based on parseDate, uses it in DateParser subclass of ValueParser.

Test Plan:
Tweaked parseDate test to check parseDateStrict.

Extended test in CopyPaste to test parsing dates as well as numbers.

Reviewers: dsagal

Reviewed By: dsagal

Differential Revision: https://phab.getgrist.com/D3088
This commit is contained in:
Alex Hall
2021-10-25 19:42:06 +02:00
parent 65e743931b
commit e58df5df5b
3 changed files with 86 additions and 17 deletions

View File

@@ -3,8 +3,8 @@ import * as gristTypes from 'app/common/gristTypes';
import * as gutil from 'app/common/gutil';
import { getCurrency, NumberFormatOptions } from 'app/common/NumberFormat';
import NumberParse from 'app/common/NumberParse';
import { parseDate } from 'app/common/parseDate';
import { DateTimeFormatOptions, FormatOptions } from 'app/common/ValueFormatter';
import { parseDateStrict } from 'app/common/parseDate';
import { DateFormatOptions, DateTimeFormatOptions, FormatOptions } from 'app/common/ValueFormatter';
export class ValueParser {
@@ -40,7 +40,7 @@ export class NumericParser extends ValueParser {
class DateParser extends ValueParser {
public parse(value: string): any {
return parseDate(value, this.widgetOpts);
return parseDateStrict(value, (this.widgetOpts as DateFormatOptions).dateFormat!);
}
}
@@ -60,7 +60,6 @@ const parsers: { [type: string]: typeof ValueParser } = {
};
// TODO these are not ready yet
delete parsers.Date;
delete parsers.DateTime;
export function createParser(