Apr 00 Tips
Volume Number: 16 (2000)
Issue Number: 4
Column Tag: Tips and Tidbits
Tips and Tidbits
by Jeff Clites (online@mactech.com)
The Difference Between Unix and Mac OS Time Epochs
The Mac OS system clock returns a count which is an integer number of seconds since 00:00 1st January 1904, expressed in local time, while the UNIX system time is also an integer number of seconds, but measured from 00:00 1st January 1970, and expressed in GMT. The difference between these two epochs is 2,082,844,800 seconds plus your time zone offset. Thus, to convert a Mac OS system clock value to a UNIX system clock value, just subtract the sum of this number and your time zone offset in seconds, and to convert the other way, add this number and your time zone offset. For those who prefer to think in code:
enum { UNIXEpochOffset = 2082844800, };
MachineLocation Here;
SInt32 GMTOffset;
UInt64 MacOSTime, UNIXTime;
ReadLocation(&Here);
GMTOffset =
Here.delta & 0x00FFFFFF
|
((Here.delta & 0x00800000) != 0 ? 0xFF000000 : 0);
/* converting Mac OS time to UNIX time: */
UNIXTime = MacOSTime - UNIXEpochOffset - GMTOffset;
/* converting UNIX time to Mac OS time: */
MacOSTime = UNIXTime + UNIXEpochOffset + GMTOffset;
Note my use of UInt64 instead of UInt32 for the actual time values. This is to avoid any future year-2040 problems with the code. Of course, to be fully year-2040-compliant, you should use the UTCUtils routines present in Mac OS 9 and later. I'll leave the issue of getting a value for Mac OS Time out of those routines as an exercise for the reader. :)
Lawrence D'Oliveiro
ldo@geek-central.gen.nz
Standard File & Appearance
Navigation Services are nice, but your program may still need to run on a system version, like Mac OS 8.1, where it is not installed. In this case you have to fall back on Standard File. But, why not give the Standard File dialogs a more Appearance-compatible look? You can do this without writing any code: just add a 'dlgx' resource or two to your application, and the Appearance Manager will do the rest. Specifically, use the following Rez resource definition:
resource 'dlgx' (-6042, purgeable)
{
versionZero
{
kDialogFlagsUseThemeBackground
| kDialogFlagsUseThemeControls
}
};
This will add an Appearance look to StandardGetFile, while the same definition, with the ID changed to -6043, will add Appearance to StandardPutFile.
Of course, these resources will have no effect if the Appearance Manager is not present.
Lawrence D'Oliveiro
ldo@geek-central.gen.nz