Mac: Set Time was not respecting the timezone (fixes #2459894)
parent
3c71abc625
commit
6ceb3e28ff
|
@ -3,11 +3,10 @@
|
|||
// celestia
|
||||
//
|
||||
// Created by Bob Ippolito on Fri Jun 07 2002.
|
||||
// Copyright (c) 2002 Chris Laurel. All rights reserved.
|
||||
// Copyright (C) 2001-9, the Celestia Development Team
|
||||
//
|
||||
|
||||
#import "Astro.h"
|
||||
#import "Astro_PrivateAPI.h"
|
||||
#import "Observer.h"
|
||||
#import "CelestiaUniversalCoord_PrivateAPI.h"
|
||||
#import "CelestiaVector_PrivateAPI.h"
|
||||
|
@ -52,8 +51,6 @@ NSDictionary* coordinateDict;
|
|||
}
|
||||
@end
|
||||
|
||||
@implementation Astro(PrivateAPI)
|
||||
@end
|
||||
|
||||
@implementation Astro
|
||||
+(NSString*)stringWithCoordinateSystem:(NSNumber*)n
|
||||
|
@ -69,7 +66,15 @@ NSDictionary* coordinateDict;
|
|||
+(void)initialize
|
||||
{
|
||||
// compiler macro would be prettier I guess
|
||||
coordinateDict = [[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:ObserverFrame::Universal],@"Universal",[NSNumber numberWithInt:ObserverFrame::Ecliptical],@"Ecliptical",[NSNumber numberWithInt:ObserverFrame::Equatorial],@"Equatorial",[NSNumber numberWithInt:ObserverFrame::BodyFixed],@"Geographic",[NSNumber numberWithInt:ObserverFrame::ObserverLocal],@"ObserverLocal",[NSNumber numberWithInt:ObserverFrame::PhaseLock],@"PhaseLock",[NSNumber numberWithInt:ObserverFrame::Chase],@"Chase",nil,nil] retain];
|
||||
coordinateDict = [[NSDictionary alloc] initWithObjectsAndKeys:
|
||||
[NSNumber numberWithInt:ObserverFrame::Universal], @"Universal",
|
||||
[NSNumber numberWithInt:ObserverFrame::Ecliptical], @"Ecliptical",
|
||||
[NSNumber numberWithInt:ObserverFrame::Equatorial], @"Equatorial",
|
||||
[NSNumber numberWithInt:ObserverFrame::BodyFixed], @"Geographic",
|
||||
[NSNumber numberWithInt:ObserverFrame::ObserverLocal], @"ObserverLocal",
|
||||
[NSNumber numberWithInt:ObserverFrame::PhaseLock], @"PhaseLock",
|
||||
[NSNumber numberWithInt:ObserverFrame::Chase], @"Chase",
|
||||
nil];
|
||||
}
|
||||
+(NSNumber*)sphereIlluminationFraction:(CelestiaVector*)spherePos viewerPosition:(CelestiaVector*)viewerPos
|
||||
{
|
||||
|
@ -96,9 +101,13 @@ NSDictionary* coordinateDict;
|
|||
|
||||
+(NSNumber*)julianDate:(NSDate *)date
|
||||
{
|
||||
NSTimeZone *prevTimeZone = [NSTimeZone defaultTimeZone];
|
||||
// UTCtoTDB() expects GMT
|
||||
[NSTimeZone setDefaultTimeZone: [NSTimeZone timeZoneWithAbbreviation: @"GMT"]];
|
||||
NSDate *roundedDate = nil;
|
||||
|
||||
#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_4
|
||||
NSCalendar *currentCalendar = [NSCalendar currentCalendar];
|
||||
[currentCalendar setTimeZone: [NSTimeZone timeZoneWithAbbreviation:@"GMT"]];
|
||||
NSCalendar *currentCalendar = [[NSCalendar alloc] initWithCalendarIdentifier: NSGregorianCalendar];
|
||||
NSDateComponents *comps = [currentCalendar components:
|
||||
NSEraCalendarUnit |
|
||||
NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit |
|
||||
|
@ -111,18 +120,26 @@ NSDictionary* coordinateDict;
|
|||
astroDate.hour = [comps hour];
|
||||
astroDate.minute = [comps minute];
|
||||
astroDate.seconds = [comps second];
|
||||
// -[NSDateComponents second] is rounded to an integer,
|
||||
// so have to calculate and add decimal part
|
||||
roundedDate = [currentCalendar dateFromComponents: comps];
|
||||
[currentCalendar release];
|
||||
#else
|
||||
NSCalendarDate *cd = [date dateWithCalendarFormat: nil timeZone: [NSTimeZone timeZoneWithAbbreviation:@"GMT"]];
|
||||
// astro::Date requires GMT (UTC) times
|
||||
NSCalendarDate *cd = [date dateWithCalendarFormat: nil timeZone: nil];
|
||||
astro::Date astroDate([cd yearOfCommonEra],
|
||||
[cd monthOfYear],
|
||||
[cd dayOfMonth]);
|
||||
astroDate.hour = [cd hourOfDay]; // takes DST in to account
|
||||
astroDate.minute = [cd minuteOfHour];
|
||||
astroDate.seconds = [cd secondOfMinute];
|
||||
roundedDate = cd;
|
||||
#endif
|
||||
|
||||
double jd = (double)astroDate;
|
||||
NSTimeInterval extraSeconds = [date timeIntervalSinceDate: roundedDate];
|
||||
astroDate.seconds += extraSeconds;
|
||||
|
||||
[NSTimeZone setDefaultTimeZone: prevTimeZone];
|
||||
double jd = astro::UTCtoTDB(astroDate);
|
||||
return [NSNumber numberWithDouble: jd];
|
||||
}
|
||||
|
||||
|
|
|
@ -377,13 +377,14 @@ NSString* fatalErrorMessage;
|
|||
[ appCore setStartURL: pendingUrl ];
|
||||
}
|
||||
|
||||
// Settings used to be loaded after starting simulation due to
|
||||
// timezone setting requiring simulation time, but this dependency
|
||||
// has been removed. In fact timezone needs to be set in order to
|
||||
// correctly set the simulation time so settings loaded before starting.
|
||||
[settings loadUserDefaults];
|
||||
|
||||
[appCore start:[NSDate date]];
|
||||
|
||||
// load settings
|
||||
// Delay applying settings until after setting simulation time
|
||||
// This allows the timezone to be set correctly
|
||||
[settings loadUserDefaults];
|
||||
|
||||
ready = YES;
|
||||
timer = [[NSTimer timerWithTimeInterval: 0.01 target: self selector:@selector(timeDisplay) userInfo:nil repeats:YES] retain];
|
||||
[[NSRunLoop currentRunLoop] addTimer:timer forMode:NSDefaultRunLoopMode];
|
||||
|
|
|
@ -39,6 +39,8 @@
|
|||
|
||||
-(double) time ;
|
||||
-(void) setTime: (double) value ;
|
||||
-(int) timeZone ;
|
||||
-(void) setTimeZone: (int) value ;
|
||||
|
||||
-(double) timeScale ;
|
||||
-(void) setTimeScale: (double) value ;
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
// celestia
|
||||
//
|
||||
// Created by Hank Ramsey on Fri Oct 29 2004.
|
||||
// Copyright (C) 2007, Celestia Development Team
|
||||
// Copyright (C) 2001-9, the Celestia Development Team
|
||||
//
|
||||
|
||||
#import "CelestiaSettings.h"
|
||||
|
@ -642,20 +642,11 @@ FEATUREMETHODS(Other)
|
|||
|
||||
// Time settings
|
||||
|
||||
// Timezone values are inverted to maintain backward compatibility
|
||||
-(int) timeZone { return appCore->getTimeZoneBias()==0 ? 1 : 0; }
|
||||
-(void) setTimeZone: (int) value
|
||||
{
|
||||
NSTimeZone *tz;
|
||||
NSDate *date = [NSDate dateWithJulian: [NSNumber numberWithDouble: [self time]]];
|
||||
if (0 == value)
|
||||
{
|
||||
tz = [NSTimeZone defaultTimeZone];
|
||||
}
|
||||
else
|
||||
{
|
||||
tz = [NSTimeZone timeZoneWithAbbreviation: @"GMT"];
|
||||
}
|
||||
[[CelestiaAppCore sharedAppCore] setTimeZone: tz withDate: date];
|
||||
appCore->setTimeZoneBias(0==value ? 1 : 0);
|
||||
}
|
||||
|
||||
-(int) dateFormat { return appCore->getDateFormat(); }
|
||||
|
|
|
@ -91,6 +91,7 @@
|
|||
NSString *errorString = nil;
|
||||
NSString* dateString = [dateField stringValue];
|
||||
NSString* timeString = [timeField stringValue];
|
||||
BOOL useUTC = (0 != [[CelestiaSettings shared] timeZone]);
|
||||
|
||||
if ( [timeString isEqualToString: @""] )
|
||||
{
|
||||
|
@ -126,6 +127,17 @@
|
|||
inputString = [ [ dateString stringByAppendingString: @" " ]
|
||||
stringByAppendingString: timeString ];
|
||||
|
||||
#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_4
|
||||
if (useUTC)
|
||||
{
|
||||
[dateTimeFormat setTimeZone: [NSTimeZone timeZoneWithAbbreviation: @"GMT"]];
|
||||
}
|
||||
else
|
||||
{
|
||||
[NSTimeZone resetSystemTimeZone];
|
||||
[dateTimeFormat setTimeZone: [NSTimeZone systemTimeZone]];
|
||||
}
|
||||
#endif
|
||||
dateValid = [ dateTimeFormat getObjectValue: &date
|
||||
forString: inputString
|
||||
errorDescription: &errorString ];
|
||||
|
@ -157,13 +169,23 @@
|
|||
if (dtParts && tmParts &&
|
||||
[dtParts count] > 0 && [tmParts count] > 0)
|
||||
{
|
||||
NSTimeZone *tz = nil;
|
||||
if (useUTC)
|
||||
{
|
||||
tz = [NSTimeZone timeZoneWithAbbreviation: @"GMT"];
|
||||
}
|
||||
else
|
||||
{
|
||||
[NSTimeZone resetSystemTimeZone];
|
||||
tz = [NSTimeZone systemTimeZone];
|
||||
}
|
||||
date = [NSCalendarDate dateWithYear: [[dtParts objectAtIndex: 2] intValue]
|
||||
month: [[dtParts objectAtIndex: 0] intValue]
|
||||
day: [[dtParts objectAtIndex: 1] intValue]
|
||||
hour: [[tmParts objectAtIndex: 0] intValue]
|
||||
minute: [[tmParts objectAtIndex: 1] intValue]
|
||||
second: [[tmParts objectAtIndex: 2] intValue]
|
||||
timeZone: [NSTimeZone defaultTimeZone]];
|
||||
timeZone: tz];
|
||||
}
|
||||
#endif
|
||||
jd = [ Astro julianDate: date];
|
||||
|
|
Loading…
Reference in New Issue