Reputation: 1685
I am running into this issue on this part of the code with SwiftMoment https://github.com/akosma/SwiftMoment
public func moment(_ timetoken: Int64) -> Moment {
return moment(Int(timetoken / 10000))
}
I am not sure why it's happenning. If you have any insights, feel free to share. Thanks!
here is the timetoken value:
timetoken 14915504189961350
It's happening on Simulator MacOS Sierra 10.12.4
Xcode 8.3.1 iOS 10.3.1 iPhone 5
Update
The issue doesnt appear on iPhone 7
Upvotes: 3
Views: 1335
Reputation: 539685
The iPhone 5 is a 32-bit device, which means that Int
is a 32-bit
integer, and the result of timetoken / 10000
does not fit into an
Int
. In contrast to some other programming languages, an integer overflow is a fatal runtime error in Swift (which is good, because otherwise
you would just get a wrong result).
I would suggest to convert the value to a TimeInterval
instead
(which is a floating point type, actually just a type alias for Double
) and then call
public func moment(_ seconds: TimeInterval) -> Moment
instead of
public func moment(_ milliseconds: Int) -> Moment
Upvotes: 4