]> sourceware.org Git - glibc.git/blame - time/offtime.c
Regenerated: autoconf configure.in
[glibc.git] / time / offtime.c
CommitLineData
28f540f4
RM
1/* Copyright (C) 1991, 1993 Free Software Foundation, Inc.
2This file is part of the GNU C Library.
3
4The GNU C Library is free software; you can redistribute it and/or
5modify it under the terms of the GNU Library General Public License as
6published by the Free Software Foundation; either version 2 of the
7License, or (at your option) any later version.
8
9The GNU C Library is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12Library General Public License for more details.
13
14You should have received a copy of the GNU Library General Public
15License along with the GNU C Library; see the file COPYING.LIB. If
16not, write to the Free Software Foundation, Inc., 675 Mass Ave,
17Cambridge, MA 02139, USA. */
18
19#include <ansidecl.h>
20#include <time.h>
21
28f540f4 22/* Defined in mktime.c. */
80fd7387 23extern CONST unsigned short int __mon_yday[2][13];
28f540f4
RM
24
25#define SECS_PER_HOUR (60 * 60)
26#define SECS_PER_DAY (SECS_PER_HOUR * 24)
27
c2216480
RM
28/* Compute the `struct tm' representation of *T,
29 offset OFFSET seconds east of UTC,
30 and store year, yday, mon, mday, wday, hour, min, sec into *TP. */
31void
32DEFUN(__offtime, (t, offset, tp),
33 CONST time_t *t AND long int offset AND struct tm *tp)
28f540f4 34{
b20e47cb 35 register long int days, rem, y;
28f540f4
RM
36 register CONST unsigned short int *ip;
37
28f540f4
RM
38 days = *t / SECS_PER_DAY;
39 rem = *t % SECS_PER_DAY;
40 rem += offset;
41 while (rem < 0)
42 {
43 rem += SECS_PER_DAY;
44 --days;
45 }
46 while (rem >= SECS_PER_DAY)
47 {
48 rem -= SECS_PER_DAY;
49 ++days;
50 }
c2216480 51 tp->tm_hour = rem / SECS_PER_HOUR;
28f540f4 52 rem %= SECS_PER_HOUR;
c2216480
RM
53 tp->tm_min = rem / 60;
54 tp->tm_sec = rem % 60;
28f540f4 55 /* January 1, 1970 was a Thursday. */
c2216480
RM
56 tp->tm_wday = (4 + days) % 7;
57 if (tp->tm_wday < 0)
58 tp->tm_wday += 7;
28f540f4 59 y = 1970;
b20e47cb
RM
60
61# define LEAPS_THRU_END_OF(y) ((y) / 4 - (y) / 100 + (y) / 400)
62
63 while (days < 0 || days >= (__isleap (y) ? 366 : 365))
28f540f4 64 {
b20e47cb
RM
65 /* Guess a corrected year, assuming 365 days per year. */
66 int yg = y + days / 365 - (days % 365 < 0);
67
68 /* Adjust DAYS and Y to match the guessed year. */
69 days -= ((yg - y) * 365
70 + LEAPS_THRU_END_OF (yg - 1)
71 - LEAPS_THRU_END_OF (y - 1));
72 y = yg;
28f540f4 73 }
c2216480
RM
74 tp->tm_year = y - 1900;
75 tp->tm_yday = days;
80fd7387
RM
76 ip = __mon_yday[__isleap(y)];
77 for (y = 11; days < ip[y]; --y)
78 continue;
79 days -= ip[y];
c2216480
RM
80 tp->tm_mon = y;
81 tp->tm_mday = days + 1;
28f540f4 82}
This page took 0.062587 seconds and 5 git commands to generate.