From 9f261464799bbbc4bf491e596db52014ab5a6984 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Standa=20Luke=C5=A1?= Date: Sat, 11 Nov 2023 10:53:10 +0100 Subject: [PATCH] Fix error message in dotvvm.formatString date parsing --- .../Resources/Scripts/DotVVM.Globalize.ts | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/Framework/Framework/Resources/Scripts/DotVVM.Globalize.ts b/src/Framework/Framework/Resources/Scripts/DotVVM.Globalize.ts index 95928372c9..f1652270be 100644 --- a/src/Framework/Framework/Resources/Scripts/DotVVM.Globalize.ts +++ b/src/Framework/Framework/Resources/Scripts/DotVVM.Globalize.ts @@ -32,35 +32,34 @@ type GlobalizeFormattable = null | undefined | string | Date | number export function formatString(format: string | null | undefined, value: GlobalizeFormattable | KnockoutObservable, type: string | null) { value = ko.unwrap(value); + const originalValue = value; if (value == null || value === "") { return ""; } + if (format === "") { + format = null + } + if (typeof value === "string") { // DateTime, DateOnly or TimeOnly if (type === "dateonly") { value = serializationParseDateOnly(value); - if (format == null || format.length == 0) { - format = "D"; - } + format ??= "D" } else if (type == "timeonly") { value = serializationParseTimeOnly(value); - if (format == null || format.length == 0) { - format = "T"; - } + format ??= "T" } else { value = serializationParseDate(value); } if (value == null) { - throw new Error(`Could not parse ${value} as a date`); + throw new Error(`Could not parse ${originalValue} as a ${type || "date"}`); } } - if (format == null || format.length == 0) { - format = "G"; - } + format ??= "G" return getGlobalize().format(value, format, getCulture()); }