Skip to content

Commit c8420eb

Browse files
authored
ref: Convert SentryDateUtil to Swift (#6307)
* ref: Convert `SentryDateUtil` to Swift * Use Int64 * Go back to use Int since has the same behavior than long on ObjC * Fix static func
1 parent 08fc5f9 commit c8420eb

File tree

8 files changed

+51
-95
lines changed

8 files changed

+51
-95
lines changed

Sentry.xcodeproj/project.pbxproj

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -530,8 +530,6 @@
530530
7BD4BD4B27EB2DC20071F4FF /* SentryDiscardedEventTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BD4BD4A27EB2DC20071F4FF /* SentryDiscardedEventTests.swift */; };
531531
7BD4BD4D27EB31820071F4FF /* SentryClientReportTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BD4BD4C27EB31820071F4FF /* SentryClientReportTests.swift */; };
532532
7BD4E8E827FD95900086C410 /* SentryMigrateSessionInitTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 7BD4E8E727FD95900086C410 /* SentryMigrateSessionInitTests.m */; };
533-
7BD729962463E83300EA3610 /* SentryDateUtil.h in Headers */ = {isa = PBXBuildFile; fileRef = 7BD729952463E83300EA3610 /* SentryDateUtil.h */; };
534-
7BD729982463E93500EA3610 /* SentryDateUtil.m in Sources */ = {isa = PBXBuildFile; fileRef = 7BD729972463E93500EA3610 /* SentryDateUtil.m */; };
535533
7BD7299A2463EA4A00EA3610 /* SentryDateUtilTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BD729992463EA4A00EA3610 /* SentryDateUtilTests.swift */; };
536534
7BD86EC5264A63F6005439DB /* SentrySysctlObjC.h in Headers */ = {isa = PBXBuildFile; fileRef = 7BD86EC4264A63F6005439DB /* SentrySysctlObjC.h */; };
537535
7BD86EC7264A641D005439DB /* SentrySysctlObjC.m in Sources */ = {isa = PBXBuildFile; fileRef = 7BD86EC6264A641D005439DB /* SentrySysctlObjC.m */; };
@@ -982,9 +980,9 @@
982980
F41362112E1C55AF00B84443 /* SentryScopePersistentStore+Tags.swift in Sources */ = {isa = PBXBuildFile; fileRef = F41362102E1C55AF00B84443 /* SentryScopePersistentStore+Tags.swift */; };
983981
F41362132E1C566100B84443 /* SentryScopePersistentStore+User.swift in Sources */ = {isa = PBXBuildFile; fileRef = F41362122E1C566100B84443 /* SentryScopePersistentStore+User.swift */; };
984982
F41362152E1C568400B84443 /* SentryScopePersistentStore+Context.swift in Sources */ = {isa = PBXBuildFile; fileRef = F41362142E1C568400B84443 /* SentryScopePersistentStore+Context.swift */; };
985-
F429D3AA2E8562EF00DBF387 /* RateLimitParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = F429D3A82E8562EF00DBF387 /* RateLimitParser.swift */; };
986983
F429D37F2E8532A300DBF387 /* HttpDateParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = F429D37D2E8532A300DBF387 /* HttpDateParser.swift */; };
987984
F429D39A2E85360F00DBF387 /* RetryAfterHeaderParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = F429D3992E85360F00DBF387 /* RetryAfterHeaderParser.swift */; };
985+
F429D3AA2E8562EF00DBF387 /* RateLimitParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = F429D3A82E8562EF00DBF387 /* RateLimitParser.swift */; };
988986
F443DB272E09BE8C009A9045 /* LoadValidatorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F443DB262E09BE8C009A9045 /* LoadValidatorTests.swift */; };
989987
F44858132E03579D0013E63B /* SentryCrashDynamicLinker+Test.h in Headers */ = {isa = PBXBuildFile; fileRef = F44858122E0357940013E63B /* SentryCrashDynamicLinker+Test.h */; };
990988
F451FAA62E0B304E0050ACF2 /* LoadValidator.swift in Sources */ = {isa = PBXBuildFile; fileRef = F451FAA52E0B304E0050ACF2 /* LoadValidator.swift */; };
@@ -1015,6 +1013,7 @@
10151013
F4DC35582E1FFE1F0077CE89 /* SentryVideoFrameProcessorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4DC35572E1FFE1B0077CE89 /* SentryVideoFrameProcessorTests.swift */; };
10161014
F4DCC9DD2E4AA9D0008ECE45 /* SentrySDKSettingsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4DCC9DC2E4AA9D0008ECE45 /* SentrySDKSettingsTests.swift */; };
10171015
F4DCC9E52E4AACE0008ECE45 /* SentrySDKSettings+Equality.m in Sources */ = {isa = PBXBuildFile; fileRef = F4DCC9E42E4AACE0008ECE45 /* SentrySDKSettings+Equality.m */; };
1016+
F4E1E9812E8C2B150007B080 /* SentryDateUtil.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4E1E9802E8C2B150007B080 /* SentryDateUtil.swift */; };
10181017
F4E3DCCB2E1579240093CB80 /* SentryScopePersistentStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4E3DCCA2E1579240093CB80 /* SentryScopePersistentStore.swift */; };
10191018
F4FE9DBD2E621F100014FED5 /* SentryRandom.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4FE9DBC2E621F100014FED5 /* SentryRandom.swift */; };
10201019
F4FE9DFD2E622CD70014FED5 /* SentryDefaultObjCRuntimeWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4FE9DFB2E622CD70014FED5 /* SentryDefaultObjCRuntimeWrapper.swift */; };
@@ -1801,8 +1800,6 @@
18011800
7BD4BD4A27EB2DC20071F4FF /* SentryDiscardedEventTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryDiscardedEventTests.swift; sourceTree = "<group>"; };
18021801
7BD4BD4C27EB31820071F4FF /* SentryClientReportTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryClientReportTests.swift; sourceTree = "<group>"; };
18031802
7BD4E8E727FD95900086C410 /* SentryMigrateSessionInitTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryMigrateSessionInitTests.m; sourceTree = "<group>"; };
1804-
7BD729952463E83300EA3610 /* SentryDateUtil.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryDateUtil.h; path = include/SentryDateUtil.h; sourceTree = "<group>"; };
1805-
7BD729972463E93500EA3610 /* SentryDateUtil.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryDateUtil.m; sourceTree = "<group>"; };
18061803
7BD729992463EA4A00EA3610 /* SentryDateUtilTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryDateUtilTests.swift; sourceTree = "<group>"; };
18071804
7BD86EC4264A63F6005439DB /* SentrySysctlObjC.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentrySysctlObjC.h; path = include/SentrySysctlObjC.h; sourceTree = "<group>"; };
18081805
7BD86EC6264A641D005439DB /* SentrySysctlObjC.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentrySysctlObjC.m; sourceTree = "<group>"; };
@@ -2322,9 +2319,9 @@
23222319
F41362102E1C55AF00B84443 /* SentryScopePersistentStore+Tags.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SentryScopePersistentStore+Tags.swift"; sourceTree = "<group>"; };
23232320
F41362122E1C566100B84443 /* SentryScopePersistentStore+User.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SentryScopePersistentStore+User.swift"; sourceTree = "<group>"; };
23242321
F41362142E1C568400B84443 /* SentryScopePersistentStore+Context.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SentryScopePersistentStore+Context.swift"; sourceTree = "<group>"; };
2325-
F429D3A82E8562EF00DBF387 /* RateLimitParser.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RateLimitParser.swift; sourceTree = "<group>"; };
23262322
F429D37D2E8532A300DBF387 /* HttpDateParser.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HttpDateParser.swift; sourceTree = "<group>"; };
23272323
F429D3992E85360F00DBF387 /* RetryAfterHeaderParser.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RetryAfterHeaderParser.swift; sourceTree = "<group>"; };
2324+
F429D3A82E8562EF00DBF387 /* RateLimitParser.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RateLimitParser.swift; sourceTree = "<group>"; };
23282325
F443DB262E09BE8C009A9045 /* LoadValidatorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoadValidatorTests.swift; sourceTree = "<group>"; };
23292326
F44858122E0357940013E63B /* SentryCrashDynamicLinker+Test.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "SentryCrashDynamicLinker+Test.h"; sourceTree = "<group>"; };
23302327
F451FAA52E0B304E0050ACF2 /* LoadValidator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoadValidator.swift; sourceTree = "<group>"; };
@@ -2356,6 +2353,7 @@
23562353
F4DCC9DC2E4AA9D0008ECE45 /* SentrySDKSettingsTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentrySDKSettingsTests.swift; sourceTree = "<group>"; };
23572354
F4DCC9E32E4AACE0008ECE45 /* SentrySDKSettings+Equality.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "SentrySDKSettings+Equality.h"; sourceTree = "<group>"; };
23582355
F4DCC9E42E4AACE0008ECE45 /* SentrySDKSettings+Equality.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "SentrySDKSettings+Equality.m"; sourceTree = "<group>"; };
2356+
F4E1E9802E8C2B150007B080 /* SentryDateUtil.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryDateUtil.swift; sourceTree = "<group>"; };
23592357
F4E3DCCA2E1579240093CB80 /* SentryScopePersistentStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryScopePersistentStore.swift; sourceTree = "<group>"; };
23602358
F4FE9DBC2E621F100014FED5 /* SentryRandom.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryRandom.swift; sourceTree = "<group>"; };
23612359
F4FE9DFB2E622CD70014FED5 /* SentryDefaultObjCRuntimeWrapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryDefaultObjCRuntimeWrapper.swift; sourceTree = "<group>"; };
@@ -2592,6 +2590,7 @@
25922590
621D9F2D2B9B030E003D94DE /* Helper */ = {
25932591
isa = PBXGroup;
25942592
children = (
2593+
F4E1E9802E8C2B150007B080 /* SentryDateUtil.swift */,
25952594
FAE579872E7D9D4900B710F9 /* SentrySysctl.swift */,
25962595
FAE579BC2E7DDDE400B710F9 /* SentryThreadWrapper.swift */,
25972596
FAE5797E2E7CF21300B710F9 /* SentryMigrateSessionInit.swift */,
@@ -2906,8 +2905,6 @@
29062905
639889BA1EDED18400EA7442 /* SentrySwizzle.m */,
29072906
7BC63F0728081242009D9E37 /* SentrySwizzleWrapper.h */,
29082907
7BC63F0928081288009D9E37 /* SentrySwizzleWrapper.m */,
2909-
7BD729952463E83300EA3610 /* SentryDateUtil.h */,
2910-
7BD729972463E93500EA3610 /* SentryDateUtil.m */,
29112908
FAB7BBA82E2577A2007301E1 /* SentryModels+Serializable.h */,
29122909
7B8ECBF926498906005FE2EF /* SentryAppStateManager.h */,
29132910
7B8ECBFB26498958005FE2EF /* SentryAppStateManager.m */,
@@ -5191,7 +5188,6 @@
51915188
844EDD6C2949387000C86F34 /* SentryMetricProfiler.h in Headers */,
51925189
F452438A2DE65968003E8F50 /* ExceptionCatcher.h in Headers */,
51935190
636085131ED47BE600E8599E /* SentryFileManagerHelper.h in Headers */,
5194-
7BD729962463E83300EA3610 /* SentryDateUtil.h in Headers */,
51955191
63FE707B20DA4C1000CDBAE8 /* SentryDictionaryDeepSearch.h in Headers */,
51965192
6344DDB91EC3115C00D9160D /* SentryCrashReportConverter.h in Headers */,
51975193
0A2D8D9828997887008720F6 /* NSLocale+Sentry.h in Headers */,
@@ -5863,7 +5859,6 @@
58635859
D43A2A122DD47FCE00114724 /* SentryWeakMap.m in Sources */,
58645860
63FE712D20DA4C1100CDBAE8 /* SentryCrashJSONCodecObjC.m in Sources */,
58655861
7BBD18932449BEDD00427C76 /* SentryDefaultRateLimits.m in Sources */,
5866-
7BD729982463E93500EA3610 /* SentryDateUtil.m in Sources */,
58675862
639FCF9D1EBC7F9500778193 /* SentryThread.mm in Sources */,
58685863
D88B30A92D48D8C3008DE513 /* SentryMaskingPreviewView.swift in Sources */,
58695864
849B8F992C6E906900148E1F /* SentryUserFeedbackFormConfiguration.swift in Sources */,
@@ -5940,6 +5935,7 @@
59405935
8482FA9C2DD7C397000E9283 /* SentryFeedbackAPI.m in Sources */,
59415936
7BC9A20628F41781001E7C4C /* SentryMeasurementUnit.m in Sources */,
59425937
F429D3AA2E8562EF00DBF387 /* RateLimitParser.swift in Sources */,
5938+
F4E1E9812E8C2B150007B080 /* SentryDateUtil.swift in Sources */,
59435939
63FE71A020DA4C1100CDBAE8 /* SentryCrashInstallation.m in Sources */,
59445940
63FE713520DA4C1100CDBAE8 /* SentryCrashMemory.c in Sources */,
59455941
629194A92D51F976000F7C6B /* SentryDebugMetaCodable.swift in Sources */,

Sources/Sentry/SentryDateUtil.m

Lines changed: 0 additions & 58 deletions
This file was deleted.

Sources/Sentry/SentryDefaultRateLimits.m

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#import "SentryDefaultRateLimits.h"
22
#import "SentryConcurrentRateLimitsDictionary.h"
33
#import "SentryDataCategoryMapper.h"
4-
#import "SentryDateUtil.h"
54
#import "SentryInternalDefines.h"
65
#import "SentryLogC.h"
76
#import "SentrySwift.h"

Sources/Sentry/include/SentryDateUtil.h

Lines changed: 0 additions & 20 deletions
This file was deleted.

Sources/Sentry/include/SentryPrivate.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#import "SentryCrashDebug.h"
2828
#import "SentryCrashMonitor_AppState.h"
2929
#import "SentryCrashMonitor_System.h"
30-
#import "SentryDateUtil.h"
3130
#import "SentryDateUtils.h"
3231
#import "SentryDependencyContainerSwiftHelper.h"
3332
#import "SentryEvent+Serialize.h"
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import Foundation
2+
3+
@objc
4+
@_spi(Private) public class SentryDateUtil: NSObject {
5+
6+
private let currentDateProvider: SentryCurrentDateProvider
7+
8+
@objc(initWithCurrentDateProvider:)
9+
public init(currentDateProvider: SentryCurrentDateProvider) {
10+
self.currentDateProvider = currentDateProvider
11+
super.init()
12+
}
13+
14+
@objc
15+
public func isInFuture(_ date: Date?) -> Bool {
16+
guard let date = date else {
17+
return false
18+
}
19+
20+
let currentDate = currentDateProvider.date()
21+
return currentDate.compare(date) == .orderedAscending
22+
}
23+
24+
@objc(getMaximumDate:andOther:)
25+
public static func getMaximumDate(_ first: Date?, andOther second: Date?) -> Date? {
26+
guard let first = first else {
27+
return second
28+
}
29+
guard let second = second else {
30+
return first
31+
}
32+
33+
return first.compare(second) == .orderedDescending ? first : second
34+
}
35+
36+
@objc
37+
public static func millisecondsSince1970(_ date: Date) -> Int {
38+
return Int(date.timeIntervalSince1970 * 1_000)
39+
}
40+
}

Tests/SentryTests/Helper/SentryDateUtilTests.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
@_spi(Private) import Sentry
12
@_spi(Private) import SentryTestUtils
23
import XCTest
34

@@ -12,25 +13,25 @@ class SentryDateUtilTests: XCTestCase {
1213

1314
func testIsInFutureWithFutureDte() {
1415
let sut = SentryDateUtil(currentDateProvider: currentDateProvider)
15-
XCTAssertTrue(sut.is(inFuture: currentDateProvider.date().addingTimeInterval(1)))
16+
XCTAssertTrue(sut.isInFuture(currentDateProvider.date().addingTimeInterval(1)))
1617
}
1718

1819
func testIsInFutureWithPresentDate() {
1920
let sut = SentryDateUtil(currentDateProvider: currentDateProvider)
2021

21-
XCTAssertFalse(sut.is(inFuture: currentDateProvider.date()))
22+
XCTAssertFalse(sut.isInFuture(currentDateProvider.date()))
2223
}
2324

2425
func testIsInFutureWithPastDate() {
2526
let sut = SentryDateUtil(currentDateProvider: currentDateProvider)
2627

27-
XCTAssertFalse(sut.is(inFuture: currentDateProvider.date().addingTimeInterval(-1)))
28+
XCTAssertFalse(sut.isInFuture(currentDateProvider.date().addingTimeInterval(-1)))
2829
}
2930

3031
func testIsInFutureWithNil() {
3132
let sut = SentryDateUtil(currentDateProvider: currentDateProvider)
3233

33-
XCTAssertFalse(sut.is(inFuture: nil))
34+
XCTAssertFalse(sut.isInFuture(nil))
3435
}
3536

3637
func testGetMaximumFirstMaximum() {

Tests/SentryTests/SentryTests-Bridging-Header.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@
100100
#import "SentryCrashUUIDConversion.h"
101101
#import "SentryDataCategory.h"
102102
#import "SentryDataCategoryMapper.h"
103-
#import "SentryDateUtil.h"
104103
#import "SentryDateUtils.h"
105104
#import "SentryDebugImageProvider+HybridSDKs.h"
106105
#import "SentryDebugImageProvider+TestInit.h"

0 commit comments

Comments
 (0)