Skip to content

Instantly share code, notes, and snippets.

@mattyohe
Created October 26, 2015 15:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattyohe/9c8be0ff213c3929663e to your computer and use it in GitHub Desktop.
Save mattyohe/9c8be0ff213c3929663e to your computer and use it in GitHub Desktop.
func badDateFormatter(date: NSDate) -> String {
let formatter = NSDateFormatter()
formatter.dateFormat = "YYYY"
return formatter.stringFromDate(date)
}
func christmasUTCWithOffset(offset: Int) -> NSDate {
return NSDate(timeIntervalSince1970: 1451001600 + (Double(offset) * 86400.0))
}
(0...3).forEach {
let date = christmasUTCWithOffset($0)
let year = badDateFormatter(date)
print(date)
print(year)
}
@mattyohe
Copy link
Author

Prints:

2015-12-25 00:00:00 +0000
2015
2015-12-26 00:00:00 +0000
2015
2015-12-27 00:00:00 +0000
2015
2015-12-28 00:00:00 +0000
2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment