|
While you can set the Daylight Savings Time state from the Date & Time
Control Panel and determine what the state is by checking the checkbox in the
Control Panel, you can also figure out the state from within your program. This
Technote shows you how.
Inside Macintosh: Operating System Utilities, Chapter 4, does not directly
explain how you can find out if daylight savings time is in effect. With the
MachineLocation data structure dlsDelta field, you can find out how the time
would have changed, but the field does not tell you whether daylight savings
time is in effect.
This Technote is aimed at Macintosh developers who must deal with date and
time programming issues.
Updated: [Sep 01 1996]
|
Using the dlsDelta field
The Daylight Savings Time state is stored in the gmtDelta field of the
MachineLocation structure. The API to access this structure is the Script
Manager call ReadLocation . Unfortunately, there is not enough documentation on
the MachineLocation structure in general and no official standards on the use
of the gmtDelta field.
Back to top
Preserving the 3-Byte Value
Currently, the dlsDelta field is not being used by Macintosh system software,
nor is its meaning defined. It may be used in the future, so it's
important that you preserve its current value if you ever use WriteLocation to
set the value of gmtDelta .
The top byte of the gmtDelta should be masked off and preserved when writing:
it's reserved for future extension. The gmtDelta is really a 3-byte value, so
you must take care to get and set it properly, as in the following C code
examples:
#include <OSUtils.h>
long GetGmtDelta(MachineLocation myLocation)
{
long internalGMTDelta;
internalGMTDelta = myLocation.gmtDelta & 0x00ffffff;
if ( (internalGMTDelta >> 23) & 1 ) // need to sign extend
internalGmtDelta = internalGmtDelta | 0xff000000;
return (internalGmtDelta);
}
void SetGmtDelta(MachineLocation *myLocation, long myGmtDelta)
{
char tempSignedByte;
tempSignedByte = myLocation->dlsDelta; // save away high byte
myLocation->gmtDelta = myGmtDelta; // make sure not overwritten
myLocation->dlsDelta = tempSignedByte; // restore high byte
}
|
Back to top
A Routine That Checks the State
The following routine shows exactly what you need to do in order to determine
if the daylight savings time is on. It is important to note that the dlsDelta
field is declared to be signed char. If this is not declared, the if condition
will always return false, even if the daylight savings time is set to true.
#include <OSUtils.h>
int IsDaylightSavingsOn()
{
int retVal = 0;
MachineLocation theLocation;
ReadLocation(&theLocation);
if (theLocation.u.dlsDelta == (signed char) 0x80) {
retVal = 1;
}
return(retVal);
}
|
Versions of the Date & Time Control Panel greater than 7.1 set the high bit
of the high byte if Daylight Savings is checked "on" in the CDEV. The Map CDEF
has not yet been revised to use this field. Future versions of Map or Date
& Time may use the byte differently, so be sure to use it with caution.
References
Inside Macintosh: Operating System Utilities
Technote TE 510 - International Resource Q&As
Develop 14 : Q&As. Download this article's Acrobat version (344K).
Back to top
Downloadables
|
Acrobat version of this Note (68K).
|
Download
|
Back to top
|