From e403004bace75ad6e3dfe14fd6c449f644948210 Mon Sep 17 00:00:00 2001 From: Adam Thayer Date: Thu, 30 Aug 2018 21:29:44 -0700 Subject: [PATCH] Fix Issue with 32-bit ARM Doing all intervals in microseconds means that long intervals (evening, morning) wind up being integer overflows. Which in Swift, look like crashes. --- Sources/Core/Behavior.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sources/Core/Behavior.swift b/Sources/Core/Behavior.swift index ea56df3..94e6c64 100644 --- a/Sources/Core/Behavior.swift +++ b/Sources/Core/Behavior.swift @@ -125,6 +125,7 @@ public struct DefaultLightBehavior: Behavior { let desiredChanges = (mergedSegment.totalBrightnessChange * targetChanges).rounded(.awayFromZero) let desiredInterval = mergedSegment.duration / max(1.0, desiredChanges) let interval = min(mergedSegment.duration, max(0.010, desiredInterval)) - return .repeating(mergedSegment.startDate, .microseconds(Int(interval * 1_000_000.0))) + let finalInterval: DispatchTimeInterval = interval < 1000.0 ? .microseconds(Int(interval * 1_000_000.0)) : .milliseconds(Int(interval * 1_000.0)) + return .repeating(mergedSegment.startDate, finalInterval) } }