[comp.unix.wizards] quick and easy fix to DST problem

edwards@husc8.UUCP (04/03/87)

	There has  been  a lot of  discussion lately about how to deal
with   Daylight  Savings Time  coming on  the   first Sunday in April,
instead of the last Sunday.   The solutions suggested have boiled down
to the following:

	1.  fix ctime and recompile all the binaries which use it

	2.  set one's system clock an hour ahead for the three weeks
            involved

	3.  ignore the whole thing, and allow your system clocks to be
            wrong.

The disadvantage of #1 is that it is incredibly time-consuming, and, if you
are like me, you have put off dealing with this problem, and now have three
days in which to solve it (I'm posting this Thurs.  night--2 Apr.).  #2's
drawback is that the system clock will be WRONG for this three week period,
since UNIX time is kept internally in GMT.  #3 does not appeal to me, as I
look at the system clock a lot (esp.  in GNUemacs, X-windows etc.).  I would
consistently be an hour late for all my appointments for the whole three
weeks.

	Another possibility has occurred to me: why not fool the system into
thinking that you're in the time zone which is an hour ahead of you?  This
method does not skew your system clock vis a vis Greenwich, and at least
allows date(1) and ctime(3) to give you the correct time, even though their
notion of what time zone you're in will be wrong for a while.

	There are several ways of going about changing your time zone.  UNIX,
first of all, keeps its time zone setting in terms of the number of minutes
your machine is *behind* Greenwich.  Eastern Standard Time, the time zone in
which I find myself, is 300 minutes behind Greenwich.  To put myself a time
zone ahead, I would change this setting to 240 minutes.  One approach to doing
this is to use adb to patch the kernel.  Under 2.9 BSD, you want to patch an
int (short) which has the symbolic name 'timezone'.  Under 4.x BSD or Ultrix
the time zone setting is kept in a 'struct timezone' called 'tz', which has
two longs in it.  The first long has the minutes setting, and the second long
has a flag indicating whether DST is in effect.  CAVEAT:  I have not attempted
this patch.

	If you decide that you would rather remake your kernel from scratch
with your new time zone setting, 'timezone' or 'tz' are defined in the kernel
source file '/sys/<machine>/param.c', under both 2.9 and 4.x/Ultrix, where
<machine> is your machine's config directory.  If you're using config to
reconfigure your kernel, the time zone setting should be at the top of your
config file, e.g.:

	timezone	5 dst

	Lastly, under 4.x/Ultrix, you can use settimeofday(2) to reset your
time zone.  The following code fragment should demonstrate this:

/* sets your time zone an hour ahead of where it is */

...
{
  struct timeval tv;
  struct timezone tz;

  (void) gettimeofday (&tv, &tz); /* yes, I shd. check the return status */
  tz.tz_minuteswest -= 60;	  /* you are now a time zone closer to */
  				  /* Greenwich */
  (void) settimeofday (&tv, &tz); /* can only be done as root */
}

The disadvantage of this method is that your program to do this must
be run every time you reboot the machine it is done on.
	
	The only disadvantage of changing the time zone is that it
makes the output of date(1) confusing--for me, date would print out
'AST' instead of 'EDT', or 'EST' or whatever.  That to me is a minor
objection.
----------------------------------------------------------------------------
Bill Edwards				edwards@harvard.harvard.edu (ARPA)
UNIX Systems Programmer/Analyst		...!harvard!edwards         (UUCP)
Harvard Science Center			edwards@harvunxu            (BITNET)
1 Oxford Street				hucsc::edwards		    (DECNET)
Cambridge, MA 02138