Last active
July 19, 2016 10:59
-
-
Save giulio92/67b8b4b8c64726c321d4562989b74a9b to your computer and use it in GitHub Desktop.
Calculate Easter day in Swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
func easterDay(Y : Int) -> NSDate { | |
let a: Int = Y % 19 | |
let b: Int = Int(floor(Double(Y) / 100)) | |
let c: Int = Y % 100 | |
let d: Int = (19 * a + b - Int(floor(Double(b) / 4)) - Int(floor(Double(b - Int(floor(Double(b + 8) / 25)) + 1) / 3)) + 15) % 30 | |
let e: Int = (32 + 2 * (b % 4) + 2 * Int(floor(Double(c) / 4)) - d - (c % 4)) % 7 | |
let f: Int = Int(floor(Double(a + 11 * d + 22 * e) / 451)) | |
let components = NSDateComponents() | |
components.year = Y | |
components.month = Int(floor(Double(d + e - 7 * f + 114) / 31)) | |
components.day = ((d + e - 7 * f + 114) % 31) + 1 | |
components.timeZone = NSTimeZone(forSecondsFromGMT: 0) | |
let cal = NSCalendar(calendarIdentifier: NSCalendarIdentifierGregorian) | |
return cal!.dateFromComponents(components)! | |
} | |
print(easterDay(2016)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment