Date.roundedHoursFromNow(hours)

๐Ÿ“— ๅƒ่€ƒ๏ผšSwift Playgrounds (Date Planner - Event Data)

extension Date {
    // Date.roundedHoursFromNow(hours)
    static func roundedHoursFromNow(_ hours: Double) -> Date {
        let exactDate = Date(timeIntervalSinceNow: hours)
        guard let hourRange = Calendar.current.dateInterval(of: .hour, for: exactDate) else {
            return exactDate
        }
        return hourRange.end
    }
}

Last updated