Skip to content

Commit

Permalink
Issue kewisch#515 for date-time values that fail to parse, fall back …
Browse files Browse the repository at this point in the history
…to date only.
  • Loading branch information
kaie committed Jun 22, 2022
1 parent f52354c commit 5b4bcce
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions lib/ical/time.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

/**
Expand Down

0 comments on commit 5b4bcce

Please sign in to comment.