mirror of
https://github.com/RevenueCat/purchases-ios
synced 2026-11-11 22:55:55 +05:45
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
31 lines
903 B
Swift
31 lines
903 B
Swift
//
|
|
// Created by RevenueCat on 3/4/20.
|
|
// Copyright (c) 2020 Purchases. All rights reserved.
|
|
//
|
|
|
|
import Nimble
|
|
import XCTest
|
|
|
|
@testable import RevenueCat
|
|
|
|
class DateExtensionsTests: TestCase {
|
|
|
|
func testMillisecondsSince1970ConvertsCorrectlyWithCurrentTime() {
|
|
let date = Date()
|
|
expect(date.millisecondsSince1970) == UInt64(date.timeIntervalSince1970 * 1000)
|
|
}
|
|
|
|
func testMillisecondsSince1970ConvertsCorrectlyWithFixedTime() {
|
|
let secondsSince1970: TimeInterval = 1619555571.0
|
|
let millisecondsSince1970UInt64: UInt64 = 1619555571000
|
|
let date = Date(timeIntervalSince1970: secondsSince1970)
|
|
expect(date.millisecondsSince1970) == millisecondsSince1970UInt64
|
|
}
|
|
|
|
func testMillisecondsSince1970() {
|
|
let date = Date()
|
|
expect(Date(millisecondsSince1970: date.millisecondsSince1970)).to(beCloseTo(date, within: 0.01))
|
|
}
|
|
|
|
}
|