From 5b4bccec7a3af17b924731bf93dcfae6af6054f1 Mon Sep 17 00:00:00 2001 From: Kai Engert Date: Wed, 22 Jun 2022 10:37:31 +0200 Subject: [PATCH] Issue #515 for date-time values that fail to parse, fall back to date only. --- lib/ical/time.js | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/lib/ical/time.js b/lib/ical/time.js index 5cfd2cbd..7c0b000d 100644 --- a/lib/ical/time.js +++ b/lib/ical/time.js @@ -1150,11 +1150,24 @@ * @return {ICAL.Time} The date/time instance */ ICAL.Time.fromString = function fromString(aValue, aProperty) { - if (aValue.length > 10) { - return ICAL.Time.fromDateTimeString(aValue, aProperty); - } else { - return ICAL.Time.fromDateString(aValue); + let useDateOnly = true; + let result; + + try { + if (aValue.length > 10) { + result = ICAL.Time.fromDateTimeString(aValue, aProperty); + // If we arrive here, parsing worked, we can skip the fallback. + useDateOnly = false; + } + } catch (e) {} + + if (useDateOnly) { + // Either the input is short, or parsing the long string failed, + // fall back to using the date, only. + result = ICAL.Time.fromDateString(aValue); } + + return result; }; /**