Last active
January 17, 2022 18:14
-
-
Save nitin-agam/16d76945c22798f3518ea884edf7f7df to your computer and use it in GitHub Desktop.
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
func isLeapYear(_ year: Int) -> Bool { | |
if year % 4 != 0 { | |
print("The year \(year) is not leap year because it is not evenly divisible by 4.") | |
return false | |
} else if year % 100 != 0 { | |
print("The year \(year) is a leap year because it is divisible by 4 and not by 100.") | |
return true | |
} else if year % 400 == 0 { | |
print("The year \(year) is a leap year because it is divisible by 400") | |
return true | |
} else { | |
print("Even though it is divisible by 4 and divisible by 100, but also not divisible by 400; so the year \(year) is not a leap year.") | |
return false | |
} | |
} | |
func isLeapYear(_ year: Int) -> Bool { | |
let formatter = DateFormatter() | |
formatter.dateFormat = "dd-MM-yyyy" | |
let dateString = "29-02-\(String(year))" | |
guard formatter.date(from: dateString) != nil else { | |
return false | |
} | |
return true | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment