Last active
December 24, 2015 23:29
-
-
Save LiLejia/6880178 to your computer and use it in GitHub Desktop.
Get star sign from NSDate
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
- (NSString *)starSign:(NSDate *)date{ | |
if(!date) | |
return nil; | |
NSString *info = @"Aquarius*0120*0219#Pisces*0220*0320#Aries*0321*0420#Taurus*0421*0521#Gemini*0522*0621#Cancer*0622*0722#Leo*0723*0823#Virgo*0824*0923#Libra*0924*1023#Scorpio*1024*1122#Sagittarius*1123*1222#Capricorn*1222*0119#"; | |
NSArray *array = [info componentsSeparatedByString:@"#"]; | |
NSString *starSignString = @"Capricorn"; | |
NSCalendar *calender = [NSCalendar currentCalendar]; | |
NSDateComponents *components = [calender components:(NSMonthCalendarUnit | NSDayCalendarUnit) fromDate:date]; | |
for(NSString *infoString in array){ | |
if(!infoString||infoString.length<=1) | |
continue; | |
NSArray *detaiArray = [infoString componentsSeparatedByString:@"*"]; | |
NSString *from = [detaiArray objectAtIndex:1]; | |
int fromMonth = [[from substringFromIndex:0 length:2] intValue]; | |
int fromDay = [[from substringFromIndex:2 length:2] intValue]; | |
NSString *to = [detaiArray objectAtIndex:2]; | |
int toMonth = [[to substringFromIndex:0 length:2] intValue]; | |
int toDay = [[to substringFromIndex:2 length:2] intValue]; | |
NSString *starSine = [detaiArray objectAtIndex:0]; | |
if(components.month>=fromMonth&&components.month<=toMonth){ | |
if(components.month==fromMonth){ | |
if(components.day>=fromDay) | |
starSignString = starSine; | |
return starSignString; | |
} | |
if(components.month==toMonth){ | |
if(components.day<=toDay) | |
starSignString = starSine; | |
return starSignString; | |
} | |
} | |
} | |
return starSignString; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment