[BWA-155] refactor: Pull Date extensions into BitwardenKit (#1459)

This commit is contained in:
Katherine Bertelsen 2025-03-25 16:31:41 -05:00 committed by GitHub
parent a5bd7cf465
commit 3fdefa84df
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 16 additions and 69 deletions

View File

@ -568,31 +568,4 @@ extension PasswordHistoryView {
)
}
}
extension Date {
init(
year: Int,
month: Int,
day: Int,
hour: Int = 0,
minute: Int = 0,
second: Int = 0,
nanosecond: Int = 0,
timeZone: TimeZone = TimeZone(secondsFromGMT: 0)!
) {
let calendar = Calendar(identifier: .gregorian)
let dateComponents = DateComponents(
calendar: calendar,
timeZone: timeZone,
year: year,
month: month,
day: day,
hour: hour,
minute: minute,
second: second,
nanosecond: nanosecond
)
self = dateComponents.date!
}
}
#endif

View File

@ -1,6 +1,7 @@
import Foundation
extension Date {
public extension Date {
/// A convenience initializer for `Date` to specify a specific point in time.
init(
year: Int,
month: Int,
@ -25,4 +26,15 @@ extension Date {
)
self = dateComponents.date!
}
// MARK: Methods
/// Returns a date that is set to midnight on the day that is seven days in the future.
///
static func midnightOneWeekFromToday() -> Date? {
let calendar = Calendar.current
guard let date = calendar.date(byAdding: .day, value: 7, to: Date()) else { return nil }
guard let date = calendar.date(bySettingHour: 0, minute: 0, second: 0, of: date) else { return nil }
return date
}
}

View File

@ -1,14 +0,0 @@
import Foundation
extension Date {
// MARK: Methods
/// Returns a date that is set to midnight on the day that is seven days in the future.
///
static func midnightOneWeekFromToday() -> Date? {
let calendar = Calendar.current
guard let date = calendar.date(byAdding: .day, value: 7, to: Date()) else { return nil }
guard let date = calendar.date(bySettingHour: 0, minute: 0, second: 0, of: date) else { return nil }
return date
}
}

View File

@ -1,3 +1,4 @@
import BitwardenKit
import Foundation
#if DEBUG

View File

@ -1,3 +1,4 @@
import BitwardenKit
import BitwardenSdk
import Foundation

View File

@ -1,3 +1,4 @@
import BitwardenKit
@preconcurrency import BitwardenSdk
import Foundation

View File

@ -568,31 +568,4 @@ extension PasswordHistoryView {
)
}
}
extension Date {
init(
year: Int,
month: Int,
day: Int,
hour: Int = 0,
minute: Int = 0,
second: Int = 0,
nanosecond: Int = 0,
timeZone: TimeZone = TimeZone(secondsFromGMT: 0)!
) {
let calendar = Calendar(identifier: .gregorian)
let dateComponents = DateComponents(
calendar: calendar,
timeZone: timeZone,
year: year,
month: month,
day: day,
hour: hour,
minute: minute,
second: second,
nanosecond: nanosecond
)
self = dateComponents.date!
}
}
#endif