Last active
January 27, 2016 01:37
-
-
Save jollyjoester/4f6648eace88f0de9d7a to your computer and use it in GitHub Desktop.
実行した日が誕生日だったらHappy Birthdayとprintするだけのスクリプト ref: http://qiita.com/jollyjoester/items/06b2d375e19cff3a8c27
This file contains hidden or 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
| let name = "俺様" | |
| let birthdayComponents = NSDateComponents() | |
| birthdayComponents.year = 1982 | |
| birthdayComponents.month = 1 | |
| birthdayComponents.day = 18 | |
| if let calendar = NSCalendar(calendarIdentifier: NSCalendarIdentifierGregorian) { | |
| if let birthday = calendar.dateFromComponents(birthdayComponents) { | |
| let now = NSDate() | |
| let elapsed = calendar.components(([.Year, .Month, .Day]), fromDate: birthday, toDate: now, options: []) | |
| let year = elapsed.year | |
| let month = elapsed.month | |
| let day = elapsed.day | |
| switch (month, day) { | |
| case (0, 0): | |
| print("A Happy \(year)th birthday to \(name)🎉") | |
| default: | |
| print("A very mery unbirthday to you!") | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment