Is there an Objective-C (or C) library (that is compatible with core location) that can tell me the time of sunrise and sunset for any given calendar day?
Just a note.. if you use the Berkley one... well it doesn't work (in Australia as least). It does include the Paul Schlyter C code though, which is great.
If you want it to work anywhere, best to just calc the dates in UTC.
In SunriseAndSunset.m, replace the code from double rise; double set; as follows:
sun_rise_set(theYear, theMonth, theDay, lon, lat, &rise, &set);
int hours = HOURS(rise);
int mins = MINUTES(rise);
int sethrs = HOURS(set);
int setmins = MINUTES(set);
NSTimeInterval riseOffset = ((hours * 60) + mins) * 60;
NSTimeInterval setOffset = ((sethrs * 60) + setmins) * 60;
[formatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZ"];
NSString *dateStr = [NSString stringWithFormat:@"%i-%02d-%02dT00:00:00+0000", theYear, theMonth, theDay];
NSDate *utcMidnight = [formatter dateFromString:dateStr];
NSDate *utcSunrise = [utcMidnight dateByAddingTimeInterval:riseOffset];
NSDate *utcSunset = [utcMidnight dateByAddingTimeInterval:setOffset];
[formatter release];
[gregorian release];
return [NSDictionary dictionaryWithObjectsAndKeys:utcSunrise, @"sunrise", utcSunset, @"sunset", nil];