remove Date.isBefore(_) and Date.isAfter(_) extensions
This commit is contained in:
parent
ea4eedb654
commit
189edf63cf
@ -348,8 +348,7 @@ extension ConversationViewController: InputAccessoryViewPlaceholderDelegate {
|
||||
// how long they will be blocked for.
|
||||
let animationCompletionDate = Date().addingTimeInterval(duration)
|
||||
let lastKeyboardAnimationDate = Date().addingTimeInterval(-1.0)
|
||||
if viewState.lastKeyboardAnimationDate == nil ||
|
||||
viewState.lastKeyboardAnimationDate?.isBefore(lastKeyboardAnimationDate) == true {
|
||||
if viewState.lastKeyboardAnimationDate == nil || viewState.lastKeyboardAnimationDate! < lastKeyboardAnimationDate {
|
||||
viewState.lastKeyboardAnimationDate = animationCompletionDate
|
||||
}
|
||||
}
|
||||
|
||||
@ -683,7 +683,7 @@ extension CLVTableDataSource: UITableViewDataSource {
|
||||
extension CLVTableDataSource {
|
||||
func updateAndSetRefreshTimer(for cell: ChatListCell?) {
|
||||
if let cell = cell, let timestamp = cell.nextUpdateTimestamp {
|
||||
if nextUpdateAt == nil || timestamp.isBefore(nextUpdateAt!) {
|
||||
if nextUpdateAt == nil || timestamp < nextUpdateAt! {
|
||||
nextUpdateAt = timestamp
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,9 +4,28 @@
|
||||
//
|
||||
|
||||
import XCTest
|
||||
import Testing
|
||||
|
||||
import SignalServiceKit
|
||||
|
||||
@Test func testDateComparison() {
|
||||
let firstDate = Date()
|
||||
let sameDate = Date(timeIntervalSinceReferenceDate: firstDate.timeIntervalSinceReferenceDate)
|
||||
let laterDate = Date(timeIntervalSinceReferenceDate: firstDate.timeIntervalSinceReferenceDate + 1)
|
||||
|
||||
#expect(firstDate.timeIntervalSinceReferenceDate == sameDate.timeIntervalSinceReferenceDate)
|
||||
#expect(firstDate.timeIntervalSinceReferenceDate != laterDate.timeIntervalSinceReferenceDate)
|
||||
#expect(firstDate == sameDate)
|
||||
#expect(firstDate != laterDate)
|
||||
#expect(firstDate.timeIntervalSinceReferenceDate < laterDate.timeIntervalSinceReferenceDate)
|
||||
#expect(!(firstDate < sameDate))
|
||||
#expect(firstDate < laterDate)
|
||||
#expect(!(laterDate < firstDate))
|
||||
#expect(!(firstDate > sameDate))
|
||||
#expect(!(firstDate > laterDate))
|
||||
#expect(laterDate > firstDate)
|
||||
}
|
||||
|
||||
class DateUtilTest: XCTestCase {
|
||||
func buildDate(year: Int = 0,
|
||||
month: Int = 0,
|
||||
@ -27,24 +46,6 @@ class DateUtilTest: XCTestCase {
|
||||
return calendar.date(from: dateComponents)!
|
||||
}
|
||||
|
||||
func testDateComparison() {
|
||||
let firstDate = Date()
|
||||
let sameDate = Date(timeIntervalSinceReferenceDate: firstDate.timeIntervalSinceReferenceDate)
|
||||
let laterDate = Date(timeIntervalSinceReferenceDate: firstDate.timeIntervalSinceReferenceDate + 1)
|
||||
|
||||
XCTAssertEqual(firstDate.timeIntervalSinceReferenceDate, sameDate.timeIntervalSinceReferenceDate)
|
||||
XCTAssertNotEqual(firstDate.timeIntervalSinceReferenceDate, laterDate.timeIntervalSinceReferenceDate)
|
||||
XCTAssertEqual(firstDate, sameDate)
|
||||
XCTAssertNotEqual(firstDate, laterDate)
|
||||
XCTAssertTrue(firstDate.timeIntervalSinceReferenceDate < laterDate.timeIntervalSinceReferenceDate)
|
||||
XCTAssertFalse(firstDate.isBefore(sameDate))
|
||||
XCTAssertTrue(firstDate.isBefore(laterDate))
|
||||
XCTAssertFalse(laterDate.isBefore(firstDate))
|
||||
XCTAssertFalse(firstDate.isAfter(sameDate))
|
||||
XCTAssertFalse(firstDate.isAfter(laterDate))
|
||||
XCTAssertTrue(laterDate.isAfter(firstDate))
|
||||
}
|
||||
|
||||
func testDateComparators() {
|
||||
// Use a specific reference date to make this test deterministic,
|
||||
// and to avoid failing around midnight, new year's, etc.
|
||||
|
||||
@ -35,7 +35,7 @@ private final class DebugLogFileManager: DDLogFileManagerDefault {
|
||||
// retrieving last modification date didn't throw but didn't return NSDate type
|
||||
continue
|
||||
}
|
||||
if lastModified.isAfter(cutoffDate) {
|
||||
if lastModified > cutoffDate {
|
||||
// Still within the window.
|
||||
continue
|
||||
}
|
||||
|
||||
@ -821,11 +821,11 @@ public class BackupAttachmentDownloadManagerImpl: BackupAttachmentDownloadManage
|
||||
let shouldStoreAllMediaLocally = backupAttachmentDownloadStore
|
||||
.getShouldStoreAllMediaLocally(tx: tx)
|
||||
|
||||
let now = dateProvider()
|
||||
let isRecent: Bool
|
||||
if let attachmentTimestamp {
|
||||
// We're "recent" if our newest owning message wouldn't have expired off the queue.
|
||||
isRecent = dateProvider().ows_millisecondsSince1970 - attachmentTimestamp
|
||||
<= remoteConfigProvider.currentConfig().messageQueueTimeMs
|
||||
isRecent = now.ows_millisecondsSince1970 - attachmentTimestamp <= remoteConfigProvider.currentConfig().messageQueueTimeMs
|
||||
} else {
|
||||
// If we don't have a timestamp, its a wallpaper and we should always pass
|
||||
// the recency check.
|
||||
@ -843,9 +843,7 @@ public class BackupAttachmentDownloadManagerImpl: BackupAttachmentDownloadManage
|
||||
// Download if the upload was < 45 days old,
|
||||
// otherwise don't bother trying automatically.
|
||||
// (The user could still try a manual download later).
|
||||
canDownloadTransitTierFullsize = Date(millisecondsSince1970: timestampForComparison)
|
||||
.addingTimeInterval(45 * .day)
|
||||
.isAfter(dateProvider())
|
||||
canDownloadTransitTierFullsize = Date(millisecondsSince1970: timestampForComparison).addingTimeInterval(45 * .day) > now
|
||||
} else {
|
||||
canDownloadTransitTierFullsize = false
|
||||
}
|
||||
|
||||
@ -122,7 +122,7 @@ public class MentionFinder {
|
||||
return false
|
||||
}
|
||||
|
||||
guard !mention.creationDate.isAfter(thresholdDate) else {
|
||||
guard mention.creationDate <= thresholdDate else {
|
||||
Logger.info("Skipping orphan mention due to age: \(mention.creationDate.timeIntervalSinceNow)")
|
||||
return false
|
||||
}
|
||||
|
||||
@ -701,7 +701,7 @@ public class OWSMessageDecrypter {
|
||||
// about 5 seconds of leeway sufficient.
|
||||
let latestAcceptableFireDate = expirationDate.addingTimeInterval(5)
|
||||
|
||||
if latestAcceptableFireDate.isBefore(fireDate) {
|
||||
if latestAcceptableFireDate < fireDate {
|
||||
placeholderCleanupTimer = Timer.scheduledTimer(
|
||||
withTimeInterval: expirationDate.timeIntervalSinceNow,
|
||||
repeats: false,
|
||||
|
||||
@ -271,7 +271,7 @@ public class ReactionManager: NSObject {
|
||||
}
|
||||
|
||||
let creationDate = Date(millisecondsSince1970: reaction.sentAtTimestamp)
|
||||
guard !creationDate.isAfter(thresholdDate) else {
|
||||
guard creationDate <= thresholdDate else {
|
||||
Logger.info("Skipping orphan reaction due to age: \(creationDate.timeIntervalSinceNow)")
|
||||
return false
|
||||
}
|
||||
|
||||
@ -84,18 +84,10 @@ public extension Date {
|
||||
return result
|
||||
}
|
||||
|
||||
func isBefore(_ date: Date) -> Bool {
|
||||
self < date
|
||||
}
|
||||
|
||||
var isBeforeNow: Bool {
|
||||
self < Date()
|
||||
}
|
||||
|
||||
func isAfter(_ date: Date) -> Bool {
|
||||
self > date
|
||||
}
|
||||
|
||||
var isAfterNow: Bool {
|
||||
self > Date()
|
||||
}
|
||||
|
||||
@ -66,7 +66,7 @@ private func ClearOldTemporaryDirectoriesSync() {
|
||||
Logger.error("failed to get a modification date for file or directory at: \(filePath)")
|
||||
continue
|
||||
}
|
||||
if mtime.isAfter(thresholdDate) {
|
||||
if mtime > thresholdDate {
|
||||
continue
|
||||
}
|
||||
} catch {
|
||||
|
||||
@ -317,8 +317,8 @@ public struct StoryConversationItem {
|
||||
if (lhs.0 as? TSPrivateStoryThread)?.isMyStory == true { return true }
|
||||
if (rhs.0 as? TSPrivateStoryThread)?.isMyStory == true { return false }
|
||||
if let priorityDateThreshold = prioritizeThreadsCreatedAfter {
|
||||
let lhsCreatedAfterThreshold = lhs.0.creationDate?.isAfter(priorityDateThreshold) ?? false
|
||||
let rhsCreatedAfterThreshold = rhs.0.creationDate?.isAfter(priorityDateThreshold) ?? false
|
||||
let lhsCreatedAfterThreshold = lhs.0.creationDate != nil && lhs.0.creationDate! > priorityDateThreshold
|
||||
let rhsCreatedAfterThreshold = rhs.0.creationDate != nil && rhs.0.creationDate! > priorityDateThreshold
|
||||
if lhsCreatedAfterThreshold != rhsCreatedAfterThreshold {
|
||||
return lhsCreatedAfterThreshold
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user