093803.faq DOCUMENT ID: 0938-03 SYNOPSIS: Time Setting on Interactive Unix System OS: Interactive PLATFORM: Intel OS VERSION: 3.0, 3.0.1, 4.0, 4.1 TECH AREA: OS PRODUCT: Kernel, Other KEYWORDS: system time clock PC hardware calendar DESCRIPTION: TIME - The HOW, WHERE and WHEN, under INTERACTIVE UNIX ====================================================== Or, to put it another way: What is the relationship between the PC hardware calendar clock chip and the time of day as measured by INTERACTIVE UNIX, and who adjusts the clock for Daylight Saving Time. SOLUTION: THE 'CMOS' CLOCK ----------------- The PC/AT and PS/2 have a real-time clock that keeps track of the current date and time. In the PC/AT, the real time clock is part of the Motorola MC146818 chip that supports the PC/AT's non-volatile CMOS RAM. In the PC/2 the real-time clock is in the custom silicon. The real-time clock runs off a battery so that the date and time are not lost when the system is turned off. COMPATIBILITY ------------- Consider the following: 1) many INTERACTIVE UNIX users will run DOS on the same machine. 2) DOS has no concept of timezones. 3) The UNIX System V 3.2 kernel always runs in GMT. To be compatible with DOS , INTERACTIVE UNIX has to leave the CMOS clock running in the local time. HOW INTERACTIVE UNIX FINDS THE TIME WHEN BOOTING ------------------------------------------------ When INTERACTIVE UNIX boots, the "init" program finds out what timezone the system is to run in by reading the file /etc/TIMEZONE. It sets the "TZ" environment variable to be the value found in this file. This variable can then be used by init and all subsequent process (environments are passed to child processes during fork). Init later starts processing the /etc/inittab file. The first line in this file runs the program /etc/setclk - this is the program that sets the system time. The setclk program reads the CMOS clock to discover what the local time is, then, using the TZ variable (more specifically, the localtime() function), it calculates the difference between local time and GMT, then sets the system clock to be GMT. The system time from this point always runs GMT, and under normal circumstances is not changed - even for daylight saving time. PRINTING THE DATE AND TIME -------------------------- The place that your TZ variable is actually used is in the localtime() library call. Given a time_t value in GMT, the localtime function will calculate the local time, taking notice of your timezone and the effect of daylight saving time. This is the function that the "date" program uses. POTENTIAL PROBLEM ----------------- Some people notice that on the day of the year that they switch from normal to daylight saving time (or visa versa) their clock jumps two hours. Or, their clock jumps one hour twice, on two different days. This effect is produced because some PC Calendar Clock chips have now been made aware of Daylight Saving Time. This means there are two people adjusting the time to account for daylight saving time, with obvious results. To counter this problem, just disable either one, or the others, use of daylight saving time. Your PC Setup program may provide a way to disable the CMOS clock daylight saving time feature. If it does not, set your timezone variable so it does not use daylight saving. DATE APPROVED: 08/07/97 Copyright (c) 1999 Sun Microsystems, Inc.