fix(datetime): default to current date when no value given (#17443)

* fix(datetime): default to current date when no value given

* test(datetime): add spec test

* move getDateValue to utils
This commit is contained in:
Liam DeBeasi
2019-02-14 16:31:59 -05:00
committed by GitHub
parent 08fe8e470a
commit a1ec5f607b
3 changed files with 50 additions and 2 deletions

View File

@ -1,3 +1,16 @@
/**
* Gets a date value given a format
* Defaults to the current date if
* no date given
*/
export function getDateValue(date: DatetimeData, format: string): number {
const getValue = getValueFromFormat(date, format);
if (getValue) { return getValue; }
const defaultDate = parseDate(new Date().toISOString());
return getValueFromFormat((defaultDate as DatetimeData), format);
}
export function renderDatetime(template: string, value: DatetimeData | undefined, locale: LocaleData): string | undefined {
if (value === undefined) {