Skip to content

Instantly share code, notes, and snippets.

@lexrus
Created April 27, 2013 15:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lexrus/5473547 to your computer and use it in GitHub Desktop.
Save lexrus/5473547 to your computer and use it in GitHub Desktop.
constellationByNSDate the hard way
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