Skip to content

Commit

Permalink
Fix the broken tests for SKAN v2
Browse files Browse the repository at this point in the history
Summary:
- Fix the broken tests on master.
- The DateComponents takes daylight saving time into account, so when you ask to subtract 35 days, it doesn't subtract exactly 35×24×60×60 seconds. Instead, it goes back 35 calendar days, which due to daylight saving time changes, can result in a slightly different number of total seconds.

Differential Revision: D51377252

fbshipit-source-id: ec579ee3890988ac3dc564c095f5ae4f71134519
  • Loading branch information
Tao Xu authored and facebook-github-bot committed Nov 16, 2023
1 parent 4de7da5 commit a42e870
Showing 1 changed file with 8 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -452,15 +452,11 @@ final class SKAdNetworkReporterTestsV2: XCTestCase {
}

func testGetCurrentPostbackWindow() {
// 1st postback window, 0-2 days
var addComponents = DateComponents()
addComponents.day = -1
addComponents.hour = -23
addComponents.minute = -59
addComponents.second = -59
let currentDate = Date()

let calendar = Calendar(identifier: .gregorian)
var expiredDate = calendar.date(byAdding: addComponents, to: Date())
// 1st postback window, 0-2 days
var secondsInPast = 2 * 24 * 60 * 60 - 1
var expiredDate = currentDate.addingTimeInterval(-TimeInterval(secondsInPast))
userDefaultsSpy.set(
expiredDate,
forKey: "com.facebook.sdk:FBSDKSettingsInstallTimestamp"
Expand All @@ -471,11 +467,8 @@ final class SKAdNetworkReporterTestsV2: XCTestCase {
)

// 2nd postback window, 3-7 days
addComponents.day = -6
addComponents.hour = -23
addComponents.minute = -59
addComponents.second = -59
expiredDate = calendar.date(byAdding: addComponents, to: Date())
secondsInPast = 7 * 24 * 60 * 60 - 1
expiredDate = currentDate.addingTimeInterval(-TimeInterval(secondsInPast))
userDefaultsSpy.set(
expiredDate,
forKey: "com.facebook.sdk:FBSDKSettingsInstallTimestamp"
Expand All @@ -486,11 +479,8 @@ final class SKAdNetworkReporterTestsV2: XCTestCase {
)

// 3rd postback window, 8-35 days
addComponents.day = -34
addComponents.hour = -23
addComponents.minute = -59
addComponents.second = -59
expiredDate = calendar.date(byAdding: addComponents, to: Date())
secondsInPast = 35 * 24 * 60 * 60 - 1
expiredDate = currentDate.addingTimeInterval(-TimeInterval(secondsInPast))
userDefaultsSpy.set(
expiredDate,
forKey: "com.facebook.sdk:FBSDKSettingsInstallTimestamp"
Expand Down

0 comments on commit a42e870

Please sign in to comment.