Solstice dates on iOS -
i'm in process of putting app makes use of suns position @ both summer , winter solstice. while there plenty of tables of data out there, i'm wondering if there standard ios components can used calculate or retrieve solstice dates without having embed , lookup data.
taking advice comments, following implemented gregorian date hours , minutes julian date.
- (nsdate *) datefromjuliandate:(double)juliandate { nscalendar *gregoriancalendar = [[nscalendar alloc] initwithcalendaridentifier:nsgregoriancalendar]; nsdate *gregoriandate; double datepart = floor(juliandate); double timepart = juliandate - datepart + 0.5; // next calendar day? if (timepart >= 1.0) { timepart = timepart - 1.0; datepart = datepart + 1; } double l = datepart + 68569; double n = floor (4 * l / 146097); l = floor(l) - floor((146097 * n + 3) / 4); int year = floor(4000 * (l + 1) / 1461001); l = l - (floor(1461 * year / 4)) + 31; int month = floor(80 * l / 2447); int day = l - floor(2447 * month / 80); l = floor(month / 11); month = floor(month + 2 - 12 * l); year = floor(100 * (n - 49) + year + l); double hour = timepart * 24.0; double minutepart = hour - floor(hour); hour = floor(hour); double minute = minutepart * 60; nsdatecomponents *datecomponents = [[nsdatecomponents alloc] init]; [datecomponents setyear:year]; [datecomponents setmonth:month]; [datecomponents setday:day]; [datecomponents sethour:hour]; [datecomponents setminute:minute]; [datecomponents settimezone:[nstimezone timezonewithname:@"gmt"]]; gregoriandate = [gregoriancalendar datefromcomponents:datecomponents]; return [gregoriandate copy]; }
Comments
Post a Comment