1 /* Copyright (C) 1991 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with the GNU C Library; see the file COPYING.LIB. If
16 not, write to the Free Software Foundation, Inc., 675 Mass Ave,
17 Cambridge, MA 02139, USA. */
23 /* How many days are in each month. */
24 CONST unsigned short int __mon_lengths[2][12] =
27 { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
29 { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
32 #define SECS_PER_HOUR (60 * 60)
33 #define SECS_PER_DAY (SECS_PER_HOUR * 24)
35 /* Returns the `struct tm' representation of *T,
36 offset OFFSET seconds east of UCT. */
38 DEFUN(__offtime, (t, offset), CONST time_t *t AND long int offset)
40 static struct tm tbuf;
41 register long int days, rem;
43 register CONST unsigned short int *ip;
48 days = *t / SECS_PER_DAY;
49 rem = *t % SECS_PER_DAY;
56 while (rem >= SECS_PER_DAY)
61 tbuf.tm_hour = rem / SECS_PER_HOUR;
63 tbuf.tm_min = rem / 60;
64 tbuf.tm_sec = rem % 60;
65 /* January 1, 1970 was a Thursday. */
66 tbuf.tm_wday = (4 + days) % 7;
70 while (days >= (rem = __isleap(y) ? 366 : 365))
78 days += __isleap(y) ? 366 : 365;
80 tbuf.tm_year = y - 1900;
82 ip = __mon_lengths[__isleap(y)];
83 for (y = 0; days >= ip[y]; ++y)
86 tbuf.tm_mday = days + 1;