Last active
March 16, 2016 11:23
-
-
Save patoroco/acfa59d184f9e6d12f0b to your computer and use it in GitHub Desktop.
Bug with NSDateComponents (execute this method in simulator and in physical device to see different results)
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
π‘ 2000 --> 1999-01 | |
π 2001 --> 2001-01 | |
π 2002 --> 2002-01 | |
π 2003 --> 2003-01 | |
π 2004 --> 2004-01 | |
π‘ 2005 --> 2004-01 | |
π‘ 2006 --> 2005-01 | |
π 2007 --> 2007-01 | |
π 2008 --> 2008-01 | |
π 2009 --> 2009-01 | |
π‘ 2010 --> 2009-01 | |
π‘ 2011 --> 2010-01 | |
π‘ 2012 --> 2011-01 | |
π 2013 --> 2013-01 | |
π 2014 --> 2014-01 | |
π 2015 --> 2015-01 | |
π‘ 2016 --> 2015-01 | |
π‘ 2017 --> 2016-01 | |
π 2018 --> 2018-01 | |
π 2019 --> 2019-01 | |
π 2020 --> 2020-01 | |
π‘ 2021 --> 2020-01 | |
π‘ 2022 --> 2021-01 | |
π‘ 2023 --> 2022-01 | |
π 2024 --> 2024-01 | |
π 2025 --> 2025-01 | |
π 2026 --> 2026-01 | |
π‘ 2027 --> 2026-01 | |
π‘ 2028 --> 2027-01 | |
π 2029 --> 2029-01 | |
π 2030 --> 2030-01 | |
π 2031 --> 2031-01 | |
π 2032 --> 2032-01 | |
π‘ 2033 --> 2032-01 | |
π‘ 2034 --> 2033-01 | |
π 2035 --> 2035-01 | |
π 2036 --> 2036-01 | |
π 2037 --> 2037-01 | |
π‘ 2038 --> 2037-01 | |
π‘ 2039 --> 2038-01 | |
π‘ 2040 --> 2039-01 | |
π 2041 --> 2041-01 | |
π 2042 --> 2042-01 | |
π 2043 --> 2043-01 | |
π‘ 2044 --> 2043-01 | |
π‘ 2045 --> 2044-01 | |
π 2046 --> 2046-01 | |
π 2047 --> 2047-01 | |
π 2048 --> 2048-01 | |
π‘ 2049 --> 2048-01 |
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
- (void)printDate { | |
NSCalendar *calendar = [NSCalendar currentCalendar]; | |
NSDateFormatter *f2 = [NSDateFormatter new]; | |
f2.dateFormat = @"YYYY-MM"; | |
for (int i = 2000; i < 2050; i++) { | |
NSDateComponents *monthComp = [NSDateComponents new]; | |
monthComp.year = i; | |
monthComp.month = 1; | |
NSDate *dateMonth = [calendar dateFromComponents:monthComp]; | |
NSString *generated = [f2 stringFromDate:dateMonth]; | |
NSString *expected = [NSString stringWithFormat:@"%d-01", i]; | |
NSString *icon = [generated isEqualToString:expected] ? @"π" : @"π‘"; | |
NSLog(@"%@ %d --> %@", icon, i, generated); | |
} | |
} |
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 printDate() { | |
let calendar = NSCalendar.currentCalendar() | |
let f2 = NSDateFormatter() | |
f2.dateFormat = "YYYY-MM" | |
for i in 2000...2050 { | |
let comp = NSDateComponents() | |
comp.year = i | |
comp.month = 1 | |
let date = calendar.dateFromComponents(comp)! | |
let gen = f2.stringFromDate(date) | |
let exp = "\(i)-01" | |
let icon = (gen == exp) ? "π" : "π‘" | |
print("\(icon) \(i) -> \(gen)") | |
} | |
} |
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
π 2000 --> 2000-01 | |
π 2001 --> 2001-01 | |
π 2002 --> 2002-01 | |
π 2003 --> 2003-01 | |
π 2004 --> 2004-01 | |
π 2005 --> 2005-01 | |
π 2006 --> 2006-01 | |
π 2007 --> 2007-01 | |
π 2008 --> 2008-01 | |
π 2009 --> 2009-01 | |
π 2010 --> 2010-01 | |
π 2011 --> 2011-01 | |
π 2012 --> 2012-01 | |
π 2013 --> 2013-01 | |
π 2014 --> 2014-01 | |
π 2015 --> 2015-01 | |
π 2016 --> 2016-01 | |
π 2017 --> 2017-01 | |
π 2018 --> 2018-01 | |
π 2019 --> 2019-01 | |
π 2020 --> 2020-01 | |
π 2021 --> 2021-01 | |
π 2022 --> 2022-01 | |
π 2023 --> 2023-01 | |
π 2024 --> 2024-01 | |
π 2025 --> 2025-01 | |
π 2026 --> 2026-01 | |
π 2027 --> 2027-01 | |
π 2028 --> 2028-01 | |
π 2029 --> 2029-01 | |
π 2030 --> 2030-01 | |
π 2031 --> 2031-01 | |
π 2032 --> 2032-01 | |
π 2033 --> 2033-01 | |
π 2034 --> 2034-01 | |
π 2035 --> 2035-01 | |
π 2036 --> 2036-01 | |
π 2037 --> 2037-01 | |
π 2038 --> 2038-01 | |
π 2039 --> 2039-01 | |
π 2040 --> 2040-01 | |
π 2041 --> 2041-01 | |
π 2042 --> 2042-01 | |
π 2043 --> 2043-01 | |
π 2044 --> 2044-01 | |
π 2045 --> 2045-01 | |
π 2046 --> 2046-01 | |
π 2047 --> 2047-01 | |
π 2048 --> 2048-01 | |
π 2049 --> 2049-01 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment