do not change app time zone when transforming date and remove deprecations
parent
4b08077896
commit
38a72e4bea
|
@ -19,8 +19,8 @@ NSDictionary* coordinateDict;
|
||||||
NSDate *date = nil;
|
NSDate *date = nil;
|
||||||
astro::Date astroDate([jd doubleValue]);
|
astro::Date astroDate([jd doubleValue]);
|
||||||
int year = astroDate.year;
|
int year = astroDate.year;
|
||||||
NSCalendar *currentCalendar = [NSCalendar currentCalendar];
|
NSCalendar *currentCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
|
||||||
[currentCalendar setTimeZone: [NSTimeZone timeZoneWithAbbreviation:@"GMT"]];
|
[currentCalendar setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"GMT"]];
|
||||||
NSDateComponents *comps = [[NSDateComponents alloc] init];
|
NSDateComponents *comps = [[NSDateComponents alloc] init];
|
||||||
int era = 1;
|
int era = 1;
|
||||||
if (year < 1)
|
if (year < 1)
|
||||||
|
@ -91,17 +91,16 @@ NSDictionary* coordinateDict;
|
||||||
|
|
||||||
+(NSNumber*)julianDate:(NSDate *)date
|
+(NSNumber*)julianDate:(NSDate *)date
|
||||||
{
|
{
|
||||||
NSTimeZone *prevTimeZone = [NSTimeZone defaultTimeZone];
|
|
||||||
// UTCtoTDB() expects GMT
|
|
||||||
[NSTimeZone setDefaultTimeZone: [NSTimeZone timeZoneWithAbbreviation: @"GMT"]];
|
|
||||||
NSDate *roundedDate = nil;
|
NSDate *roundedDate = nil;
|
||||||
|
|
||||||
NSCalendar *currentCalendar = [[NSCalendar alloc] initWithCalendarIdentifier: NSGregorianCalendar];
|
NSCalendar *currentCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
|
||||||
|
// UTCtoTDB() expects GMT
|
||||||
|
[currentCalendar setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"GMT"]];
|
||||||
NSDateComponents *comps = [currentCalendar components:
|
NSDateComponents *comps = [currentCalendar components:
|
||||||
NSEraCalendarUnit |
|
NSCalendarUnitEra |
|
||||||
NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit |
|
NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay |
|
||||||
NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit
|
NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond
|
||||||
fromDate: date];
|
fromDate:date];
|
||||||
NSInteger era = [comps era];
|
NSInteger era = [comps era];
|
||||||
NSInteger year = [comps year];
|
NSInteger year = [comps year];
|
||||||
if (era < 1) year = 1 - year;
|
if (era < 1) year = 1 - year;
|
||||||
|
@ -111,14 +110,13 @@ NSDictionary* coordinateDict;
|
||||||
astroDate.seconds = (int)[comps second];
|
astroDate.seconds = (int)[comps second];
|
||||||
// -[NSDateComponents second] is rounded to an integer,
|
// -[NSDateComponents second] is rounded to an integer,
|
||||||
// so have to calculate and add decimal part
|
// so have to calculate and add decimal part
|
||||||
roundedDate = [currentCalendar dateFromComponents: comps];
|
roundedDate = [currentCalendar dateFromComponents:comps];
|
||||||
|
|
||||||
NSTimeInterval extraSeconds = [date timeIntervalSinceDate: roundedDate];
|
NSTimeInterval extraSeconds = [date timeIntervalSinceDate:roundedDate];
|
||||||
astroDate.seconds += extraSeconds;
|
astroDate.seconds += extraSeconds;
|
||||||
|
|
||||||
[NSTimeZone setDefaultTimeZone: prevTimeZone];
|
|
||||||
double jd = astro::UTCtoTDB(astroDate);
|
double jd = astro::UTCtoTDB(astroDate);
|
||||||
return [NSNumber numberWithDouble: jd];
|
return [NSNumber numberWithDouble:jd];
|
||||||
}
|
}
|
||||||
|
|
||||||
+(NSNumber*)speedOfLight
|
+(NSNumber*)speedOfLight
|
||||||
|
|
Loading…
Reference in New Issue