1987-03-31 10:45:53 +00:00
|
|
|
/* $Header$ */
|
1987-01-27 15:57:55 +00:00
|
|
|
#include <time.h>
|
|
|
|
|
1989-06-19 09:50:38 +00:00
|
|
|
#define LEAPYEAR(year) (!((year) % 4) && (((year) % 100) || !((year) % 400)))
|
|
|
|
#define YEARSIZE(year) (LEAPYEAR(year) ? 366 : 365)
|
1987-01-27 15:57:55 +00:00
|
|
|
#define FIRSTSUNDAY(t) (((t)->tm_yday - (t)->tm_wday + 420) % 7)
|
1989-06-19 09:50:38 +00:00
|
|
|
|
1987-01-27 15:57:55 +00:00
|
|
|
static int
|
|
|
|
last_sunday(d, t)
|
|
|
|
register int d;
|
|
|
|
register struct tm *t;
|
|
|
|
{
|
|
|
|
int first = FIRSTSUNDAY(t);
|
|
|
|
|
1989-06-19 09:50:38 +00:00
|
|
|
if (d >= 58 && LEAPYEAR(t->tm_year+1900)) d++;
|
1987-01-27 15:57:55 +00:00
|
|
|
if (d < first) return first;
|
|
|
|
return d - (d - first) % 7;
|
|
|
|
}
|
|
|
|
|
1987-03-10 15:07:26 +00:00
|
|
|
dysize(y)
|
|
|
|
{
|
|
|
|
/* compatibility */
|
|
|
|
return YEARSIZE(y);
|
|
|
|
}
|
|
|
|
|
1987-01-28 17:02:56 +00:00
|
|
|
extern struct tm *gmtime();
|
|
|
|
|
1987-01-27 15:57:55 +00:00
|
|
|
struct tm *
|
|
|
|
localtime(clock)
|
|
|
|
long *clock;
|
|
|
|
{
|
|
|
|
register struct tm *gmt;
|
|
|
|
long cl;
|
|
|
|
int begindst, enddst;
|
1987-02-05 21:04:40 +00:00
|
|
|
extern int __daylight;
|
|
|
|
extern long __timezone;
|
1987-01-27 15:57:55 +00:00
|
|
|
|
|
|
|
tzset();
|
1987-02-05 21:04:40 +00:00
|
|
|
cl = *clock - __timezone;
|
1987-01-27 15:57:55 +00:00
|
|
|
gmt = gmtime(&cl);
|
1987-02-05 21:04:40 +00:00
|
|
|
if (__daylight) {
|
1987-01-27 15:57:55 +00:00
|
|
|
/* daylight saving time.
|
|
|
|
Unfortunately, rules differ for different countries.
|
|
|
|
Implemented here are heuristics that got it right
|
|
|
|
in Holland, over the last couple of years.
|
|
|
|
Of course, there is no algorithm. It is all
|
|
|
|
politics ...
|
|
|
|
*/
|
|
|
|
begindst = last_sunday(89, gmt); /* last Sun before Apr */
|
|
|
|
enddst = last_sunday(272, gmt); /* last Sun in Sep */
|
|
|
|
if ((gmt->tm_yday>begindst ||
|
|
|
|
(gmt->tm_yday==begindst && gmt->tm_hour>=2)) &&
|
|
|
|
(gmt->tm_yday<enddst ||
|
|
|
|
(gmt->tm_yday==enddst && gmt->tm_hour<3))) {
|
1987-02-05 21:04:40 +00:00
|
|
|
/* it all happens between 2 and 3 */
|
1987-01-27 15:57:55 +00:00
|
|
|
cl += 1*60*60;
|
|
|
|
gmt = gmtime(&cl);
|
|
|
|
gmt->tm_isdst++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return gmt;
|
|
|
|
}
|