mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
(core) Parsing pasted datetimes
Summary: Add function parseDateTime which parses a string containing both date and time componenents, intended for parsing pasted strings. Add DateTimeParser subclass of ValueParser. Test Plan: Extended parseDate.ts and CopyPaste.ts tests. Reviewers: dsagal Reviewed By: dsagal Differential Revision: https://phab.getgrist.com/D3152
This commit is contained in:
@@ -5,7 +5,7 @@ import * as gutil from 'app/common/gutil';
|
||||
import {safeJsonParse} from 'app/common/gutil';
|
||||
import {getCurrency, NumberFormatOptions} from 'app/common/NumberFormat';
|
||||
import NumberParse from 'app/common/NumberParse';
|
||||
import {parseDateStrict} from 'app/common/parseDate';
|
||||
import {parseDateStrict, parseDateTime} from 'app/common/parseDate';
|
||||
import {DateFormatOptions, DateTimeFormatOptions, formatDecoded, FormatOptions} from 'app/common/ValueFormatter';
|
||||
import flatMap = require('lodash/flatMap');
|
||||
|
||||
@@ -47,12 +47,16 @@ class DateParser extends ValueParser {
|
||||
}
|
||||
}
|
||||
|
||||
class DateTimeParser extends DateParser {
|
||||
class DateTimeParser extends ValueParser {
|
||||
constructor(type: string, widgetOpts: DateTimeFormatOptions, docSettings: DocumentSettings) {
|
||||
super(type, widgetOpts, docSettings);
|
||||
const timezone = gutil.removePrefix(type, "DateTime:") || '';
|
||||
this.widgetOpts = {...widgetOpts, timezone};
|
||||
}
|
||||
|
||||
public parse(value: string): any {
|
||||
return parseDateTime(value, this.widgetOpts);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -99,8 +103,6 @@ const parsers: { [type: string]: typeof ValueParser } = {
|
||||
ChoiceList: ChoiceListParser,
|
||||
};
|
||||
|
||||
// TODO these are not ready yet
|
||||
delete parsers.DateTime;
|
||||
|
||||
export function createParser(
|
||||
type: string, widgetOpts: FormatOptions, docSettings: DocumentSettings
|
||||
|
||||
Reference in New Issue
Block a user