Screaming-Reminder/Screaming Reminder/Models/Extensions.swift

34 lines
843 B
Swift
Raw Normal View History

2024-07-11 10:38:11 +00:00
//
// Extensions.swift
// Screaming Reminder
//
// Created by Amine Bou on 23/07/2024.
//
import Foundation
extension Date {
func withSpecificHour(hour: Int) -> Date {
var dateComponents = Calendar.current.dateComponents(in: TimeZone.current, from: self)
dateComponents.hour = hour
dateComponents.minute = 0
return Calendar.current.date(from: dateComponents).unsafelyUnwrapped
}
func atZeroMinutes() -> Date {
var dateComponents = Calendar.current.dateComponents(in: TimeZone.current, from: self)
dateComponents.minute = 0
return Calendar.current.date(from: dateComponents).unsafelyUnwrapped
}
}
extension Set {
mutating func insertAll(_ newMembers: [Set.Element]) {
newMembers.forEach { (member) in
self.insert(member)
}
}
}