[comp.sys.mac.programmer] Where is the "Time Zone" field stored?

elliott@veronica.cs.wisc.edu (James Elliott) (06/16/91)

I'd like to be able to access this information in a program of mine,
and haven't been able to find any documentation that tells me where
I can read it. I suspect that it is in the parameter RAM, but it was
added after the relevant section of Inside Macintosh was printed. Can
anyone help me out here?

Also useful to me would be a definitive list of time zone names (and
their respective offsets from UTC), but I'm not even sure if such a
thing is possible.
--
Jim Elliott		      "Like a bridge he'll come between us, not a wall"
elliott@veronica.cs.wisc.edu

peirce@outpost.UUCP (Michael Peirce) (06/19/91)

In article <1991Jun16.054638.7152@spool.cs.wisc.edu>, elliott@veronica.cs.wisc.edu (James Elliott) writes:
> 
> I'd like to be able to access this information in a program of mine,
> and haven't been able to find any documentation that tells me where
> I can read it. I suspect that it is in the parameter RAM, but it was
> added after the relevant section of Inside Macintosh was printed. Can
> anyone help me out here?

I don't have a list of time zones (check an encyclopedia), but here
is a unit that does a couple of TimeZone related things, the trick
is to call ReadLocation or WriteLocation.  Note: I wrote this almost
a year ago and haven't really looked at it since, so caviat emptor.

{------------------------------------------------------------------------------
			)  M I C H E A L  P E I R C E  1 9 9 0
------------------------------------------------------------------------------}
{$R-}

UNIT UTimeZone;

INTERFACE

USES

	Script;

CONST
	{ The following *should* be put into a STR resource }
	kBeforeDirection	= 'before';
	kAfterDirection		= 'after';
	kNeitherDirection	= ' ';

PROCEDURE SetGMTDeltaSeconds(theSeconds : longint);
FUNCTION  GMTDeltaSeconds : longint;
PROCEDURE GMTDelta(var directionStr,hoursStr,minutesStr : str255);

IMPLEMENTATION

{-----------------------------------------------------------------------------------}
PROCEDURE SetGMTDeltaSeconds(theSeconds : longint);
VAR
	location		: MachineLocation;
	tSignedByte		: SignedByte;
BEGIN {GMTDeltaSeconds}
	ReadLocation(location);
	WITH location DO BEGIN
		tSignedByte := dlsDelta;
		gmtDelta := theSeconds;
		dlsDelta := tSignedByte;
	END;
	WriteLocation(location);
END; {GMTDeltaSeconds}

{-----------------------------------------------------------------------------------}
FUNCTION  GMTDeltaSeconds : longint;
VAR
	location		: MachineLocation;
	theGMTDelta		: longint;
BEGIN {GMTDeltaSeconds}
	ReadLocation(location);
	WITH location DO BEGIN
		theGMTDelta := BAND(gmtDelta,$00FFFFFF);
		IF BTST(theGMTDelta,23)
			THEN BEGIN
				theGMTDelta := BOR(theGMTDelta,$FF000000);
			END;
	END;
	GMTDeltaSeconds := theGMTDelta;
END; {GMTDeltaSeconds}

{-----------------------------------------------------------------------------------}
PROCEDURE GMTDelta(var directionStr,hoursStr,minutesStr : str255);
VAR
	hours,minutes,
	theGMTDelta		: longint;
BEGIN {GMTDelta}
	
	theGMTDelta := GMTDeltaSeconds;
	
	IF theGMTDelta = 0
		THEN BEGIN
			directionStr	:= kNeitherDirection;
			hoursStr		:= '0';
			minutesStr		:= '0';
		END
		ELSE BEGIN
			IF theGMTDelta > 0
				THEN BEGIN
					directionStr := kBeforeDirection;
				END
				ELSE BEGIN
					directionStr := kAfterDirection;
					theGMTDelta  := ABS(theGMTDelta);
				END;
			hours := theGMTDelta DIV 3600;
			minutes := (theGMTDelta - (hours * 3600)) DIV 60;
			NumToString(hours,hoursStr);
			NumToString(minutes,minutesStr);
		END;
	
END; {GMTDelta}

END.

--  Michael Peirce         --   outpost!peirce@claris.com
--  Peirce Software        --   Suite 301, 719 Hibiscus Place
--  Macintosh Programming  --   San Jose, California 95117
--           & Consulting  --   (408) 244-6554, AppleLink: PEIRCE