From 724095728ebb7309f5e6582448873abe9537bf2a Mon Sep 17 00:00:00 2001 From: Ramzan Date: Tue, 18 Aug 2020 19:06:49 -0400 Subject: [PATCH] helpers: add parseDate function --- src/helpers.tsx | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/helpers.tsx b/src/helpers.tsx index 1ba4938..91da9ea 100644 --- a/src/helpers.tsx +++ b/src/helpers.tsx @@ -119,4 +119,31 @@ export function mapPriority(priority: number): TaskPriorityType { } else { return TaskPriorityType.Undefined; } -} \ No newline at end of file +} + +export function parseDate(prop: ICAL.Property) { + const value = prop.getFirstValue(); + if ((value.day !== null) && (value.day !== undefined)) { + return { + day: value.day, + month: value.month - 1, + year: value.year ?? undefined, + }; + } else { + const time = prop.toJSON()[3]; + if (time.length === 6 && time.startsWith("--")) { + return { + day: parseInt(time.slice(4, 6)), + month: parseInt(time.slice(2, 4)) - 1, + }; + } else if (time.length === 8) { + return { + day: parseInt(time.slice(6, 8)), + month: parseInt(time.slice(4, 6)) - 1, + year: parseInt(time.slice(0, 4)), + }; + } + } + + return {}; +}