Skip to content

Commit

Permalink
Don't convert Long to Int before adding time value to the calendar.
Browse files Browse the repository at this point in the history
  • Loading branch information
kizitonwose committed Mar 24, 2020
1 parent 7dfcfee commit 6b4d9d3
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions time/src/main/kotlin/com/kizitonwose/time/Extensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,12 @@ import kotlin.concurrent.scheduleAtFixedRate
*/

//region Calendar
operator fun Calendar.plus(other: Interval<TimeUnit>): Calendar {
val newCalendar = clone() as Calendar
newCalendar.add(Calendar.MILLISECOND, other.inMilliseconds.longValue.toInt())
return newCalendar
operator fun Calendar.plus(other: Interval<TimeUnit>): Calendar = (clone() as Calendar).apply {
timeInMillis += other.inMilliseconds.longValue
}

operator fun Calendar.minus(other: Interval<TimeUnit>): Calendar {
val newCalendar = clone() as Calendar
newCalendar.add(Calendar.MILLISECOND, -other.inMilliseconds.longValue.toInt())
return newCalendar
operator fun Calendar.minus(other: Interval<TimeUnit>): Calendar = (clone() as Calendar).apply {
timeInMillis -= other.inMilliseconds.longValue
}
//endregion

Expand Down

0 comments on commit 6b4d9d3

Please sign in to comment.