projects
/
kopensolaris-gnu
/
glibc.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Sat Apr 20 17:07:17 1996 Ulrich Drepper <drepper@cygnus.com>
[kopensolaris-gnu/glibc.git]
/
time
/
offtime.c
diff --git
a/time/offtime.c
b/time/offtime.c
index
13bc880
..
4e062df
100644
(file)
--- a/
time/offtime.c
+++ b/
time/offtime.c
@@
-1,4
+1,4
@@
-/* Copyright (C) 1991 Free Software Foundation, Inc.
+/* Copyright (C) 1991
, 1993
Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@
-19,32
+19,22
@@
Cambridge, MA 02139, USA. */
#include <ansidecl.h>
#include <time.h>
#include <ansidecl.h>
#include <time.h>
-
-/* How many days are in each month. */
-CONST unsigned short int __mon_lengths[2][12] =
- {
- /* Normal years. */
- { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
- /* Leap years. */
- { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
- };
+/* Defined in mktime.c. */
+extern CONST unsigned short int __mon_yday[2][13];
#define SECS_PER_HOUR (60 * 60)
#define SECS_PER_DAY (SECS_PER_HOUR * 24)
#define SECS_PER_HOUR (60 * 60)
#define SECS_PER_DAY (SECS_PER_HOUR * 24)
-/* Returns the `struct tm' representation of *T,
- offset OFFSET seconds east of UCT. */
-struct tm *
-DEFUN(__offtime, (t, offset), CONST time_t *t AND long int offset)
+/* Compute the `struct tm' representation of *T,
+ offset OFFSET seconds east of UTC,
+ and store year, yday, mon, mday, wday, hour, min, sec into *TP. */
+void
+DEFUN(__offtime, (t, offset, tp),
+ CONST time_t *t AND long int offset AND struct tm *tp)
{
{
- static struct tm tbuf;
- register long int days, rem;
- register int y;
+ register long int days, rem, y;
register CONST unsigned short int *ip;
register CONST unsigned short int *ip;
- if (t == NULL)
- return NULL;
-
days = *t / SECS_PER_DAY;
rem = *t % SECS_PER_DAY;
rem += offset;
days = *t / SECS_PER_DAY;
rem = *t % SECS_PER_DAY;
rem += offset;
@@
-58,33
+48,35
@@
DEFUN(__offtime, (t, offset), CONST time_t *t AND long int offset)
rem -= SECS_PER_DAY;
++days;
}
rem -= SECS_PER_DAY;
++days;
}
- t
buf.
tm_hour = rem / SECS_PER_HOUR;
+ t
p->
tm_hour = rem / SECS_PER_HOUR;
rem %= SECS_PER_HOUR;
rem %= SECS_PER_HOUR;
- t
buf.
tm_min = rem / 60;
- t
buf.
tm_sec = rem % 60;
+ t
p->
tm_min = rem / 60;
+ t
p->
tm_sec = rem % 60;
/* January 1, 1970 was a Thursday. */
/* January 1, 1970 was a Thursday. */
- t
buf.
tm_wday = (4 + days) % 7;
- if (t
buf.
tm_wday < 0)
- t
buf.
tm_wday += 7;
+ t
p->
tm_wday = (4 + days) % 7;
+ if (t
p->
tm_wday < 0)
+ t
p->
tm_wday += 7;
y = 1970;
y = 1970;
- while (days >= (rem = __isleap(y) ? 366 : 365))
- {
- ++y;
- days -= rem;
- }
- while (days < 0)
+
+# define LEAPS_THRU_END_OF(y) ((y) / 4 - (y) / 100 + (y) / 400)
+
+ while (days < 0 || days >= (__isleap (y) ? 366 : 365))
{
{
- --y;
- days += __isleap(y) ? 366 : 365;
- }
- tbuf.tm_year = y - 1900;
- tbuf.tm_yday = days;
- ip = __mon_lengths[__isleap(y)];
- for (y = 0; days >= ip[y]; ++y)
- days -= ip[y];
- tbuf.tm_mon = y;
- tbuf.tm_mday = days + 1;
- tbuf.tm_isdst = -1;
+ /* Guess a corrected year, assuming 365 days per year. */
+ int yg = y + days / 365 - (days % 365 < 0);
- return &tbuf;
+ /* Adjust DAYS and Y to match the guessed year. */
+ days -= ((yg - y) * 365
+ + LEAPS_THRU_END_OF (yg - 1)
+ - LEAPS_THRU_END_OF (y - 1));
+ y = yg;
+ }
+ tp->tm_year = y - 1900;
+ tp->tm_yday = days;
+ ip = __mon_yday[__isleap(y)];
+ for (y = 11; days < ip[y]; --y)
+ continue;
+ days -= ip[y];
+ tp->tm_mon = y;
+ tp->tm_mday = days + 1;
}
}