From b85b4e3acf7138ce9a3f475788901f9a060031d4 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 13 Feb 2021 21:52:54 +0100 Subject: [PATCH] properly handle exporting and importing during day reminders --- .../simplemobiletools/calendar/pro/helpers/IcsExporter.kt | 4 +++- .../simplemobiletools/calendar/pro/helpers/IcsImporter.kt | 6 +++++- .../com/simplemobiletools/calendar/pro/helpers/Parser.kt | 2 ++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/IcsExporter.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/IcsExporter.kt index 15a1bee51..67a60a109 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/IcsExporter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/IcsExporter.kt @@ -95,7 +95,9 @@ class IcsExporter { writeLn("$ATTENDEE$MAILTO$attendee") } } - writeLn("$TRIGGER-${Parser().getDurationCode(reminder.minutes.toLong())}") + + val sign = if (reminder.minutes < -1) "" else "-" + writeLn("$TRIGGER$sign${Parser().getDurationCode(Math.abs(reminder.minutes.toLong()))}") writeLn(END_ALARM) } } diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/IcsImporter.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/IcsImporter.kt index 02dcfa0f8..a837e72c9 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/IcsImporter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/IcsImporter.kt @@ -113,7 +113,11 @@ class IcsImporter(val activity: SimpleActivity) { curReminderTriggerAction = if (action == DISPLAY) REMINDER_NOTIFICATION else REMINDER_EMAIL } } else if (line.startsWith(TRIGGER)) { - curReminderTriggerMinutes = Parser().parseDurationSeconds(line.substring(TRIGGER.length)) / 60 + val value = line.substring(TRIGGER.length) + curReminderTriggerMinutes = Parser().parseDurationSeconds(value) / 60 + if (!value.startsWith("-")) { + curReminderTriggerMinutes *= -1 + } } else if (line.startsWith(CATEGORY_COLOR)) { val color = line.substring(CATEGORY_COLOR.length) if (color.trimStart('-').areDigitsOnly()) { diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/Parser.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/Parser.kt index b9420dac7..40191384b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/Parser.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/Parser.kt @@ -230,10 +230,12 @@ class Parser { days = Math.floor((remainder / DAY_MINUTES).toDouble()).toInt() remainder -= days * DAY_MINUTES } + if (remainder >= 60) { hours = Math.floor((remainder / 60).toDouble()).toInt() remainder -= hours * 60 } + return "P${days}DT${hours}H${remainder}M0S" } }