Created
April 27, 2013 15:44
-
-
Save lexrus/5473547 to your computer and use it in GitHub Desktop.
constellationByNSDate the hard way
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
char *constellationByNSDate(NSDate *date) { | |
static char *constellations[13] = {"Capricorn","Aquarius","Pisces","Aries","Taurus","Gemini","Cancer","Leo","Virgo","Libra","Scorpio","Sagittarius","Capricorn"}; | |
static unsigned short constellationSeperates[12] = {20,19,21,21,21,22,23,23,23,24,22,22}; | |
unsigned short dateStr[5]; | |
NSLocale *CNLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"zh_Hans_CN"]; | |
[[date descriptionWithLocale:CNLocale] getCharacters:(unichar*)dateStr range:(NSRange){5, 5}]; | |
unsigned short month = (dateStr[0] - '0') * 10 + (dateStr[1] - '0') - 1; | |
unsigned short day = (dateStr[3] - '0') * 10 + (dateStr[4] - '0'); | |
return constellations[month + (day < constellationSeperates[month] ? 0 : 1)]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment