Files
purchases-ios/Sources/FoundationExtensions/Date+Extensions.swift
T
NachoSoto d4ecc7b298 DispatchTimeInterval & Date: avoid 32-bit overflows, fix watchOS crashes (#2342)
Fixes #2338, [SDKONCALL-237], [SDK-2974].

`Int` is actually 32 bits in 32-bit platforms, like `watchOS` still is
(sort of).
This fixes 2 potential `Int` overflows: `Date.millisecondsSince1970` and
`DispatchTimeInterval` arithmetic using `nanoseconds`.

See also #2340.

[SDKONCALL-237]:
https://revenuecats.atlassian.net/browse/SDKONCALL-237?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
2023-03-16 13:24:16 -07:00

29 lines
702 B
Swift

//
// Copyright RevenueCat Inc. All Rights Reserved.
//
// Licensed under the MIT License (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://opensource.org/licenses/MIT
//
// Date+Extensions.swift
//
// Created by Josh Holtz on 6/28/21.
//
import Foundation
extension Date {
init(millisecondsSince1970: UInt64) {
self.init(timeIntervalSince1970: TimeInterval(millisecondsSince1970) / 1000)
}
/// - Important: this needs to be 64 bits because `Int` is 32 bits in watchOS
var millisecondsSince1970: UInt64 {
return UInt64(self.timeIntervalSince1970 * 1000)
}
}