From 6b4d9d3b14ced7514c3bc2add44d349f2581417b Mon Sep 17 00:00:00 2001 From: Kizito Nwose Date: Tue, 24 Mar 2020 12:44:13 +0100 Subject: [PATCH] Don't convert Long to Int before adding time value to the calendar. --- .../main/kotlin/com/kizitonwose/time/Extensions.kt | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/time/src/main/kotlin/com/kizitonwose/time/Extensions.kt b/time/src/main/kotlin/com/kizitonwose/time/Extensions.kt index 90cb4d8..9f45f39 100644 --- a/time/src/main/kotlin/com/kizitonwose/time/Extensions.kt +++ b/time/src/main/kotlin/com/kizitonwose/time/Extensions.kt @@ -9,16 +9,12 @@ import kotlin.concurrent.scheduleAtFixedRate */ //region Calendar -operator fun Calendar.plus(other: Interval): Calendar { - val newCalendar = clone() as Calendar - newCalendar.add(Calendar.MILLISECOND, other.inMilliseconds.longValue.toInt()) - return newCalendar +operator fun Calendar.plus(other: Interval): Calendar = (clone() as Calendar).apply { + timeInMillis += other.inMilliseconds.longValue } -operator fun Calendar.minus(other: Interval): Calendar { - val newCalendar = clone() as Calendar - newCalendar.add(Calendar.MILLISECOND, -other.inMilliseconds.longValue.toInt()) - return newCalendar +operator fun Calendar.minus(other: Interval): Calendar = (clone() as Calendar).apply { + timeInMillis -= other.inMilliseconds.longValue } //endregion