1 /* Copyright (C) 1997, 1998, 1999 Free Software Foundation, Inc.
2 This file is part of GNU Fortran libU77 library.
4 This library is free software; you can redistribute it and/or modify it
5 under the terms of the GNU Library General Public License as published
6 by the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 GNU Fortran 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 GNU Fortran; see the file COPYING.LIB. If
16 not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA. */
23 #if TIME_WITH_SYS_TIME
24 # include <sys/time.h>
28 # include <sys/time.h>
38 void s_copy(register char *a, register char *b, ftnlen la, ftnlen lb);
41 int G77_date_and_time_0 (char *date, char *fftime, char *zone,
42 integer *values, ftnlen date_len,
43 ftnlen fftime_len, ftnlen zone_len)
46 struct tm ltime = *localtime(<), gtime = *gmtime(<);
47 char dat[9], zon[6], ftim[11];
50 vals[0] = 1900 + ltime.tm_year;
51 vals[1] = 1 + ltime.tm_mon;
52 vals[2] = ltime.tm_mday;
53 /* fixme: year boundaries */
54 vals[3] = (ltime.tm_min - gtime.tm_min +
55 60*(ltime.tm_hour - gtime.tm_hour +
56 24*(ltime.tm_yday -gtime.tm_yday)));
57 vals[4] = ltime.tm_hour;
58 vals[5] = ltime.tm_min;
59 vals[6] = ltime.tm_sec;
60 vals[7] = 0; /* no STDC way to get this */
61 /* GNUish way; maybe use `ftime' on other systems. */
65 #if HAVE_STRUCT_TIMEZONE
67 /* This is still not strictly correct on some systems such as HPUX,
68 which does have struct timezone, but gettimeofday takes void* as
69 the 2nd arg. However, the effect of passing anything other than a null
70 pointer is unspecified on HPUX. */
71 if (! gettimeofday (&tp, &tzp))
73 if (! gettimeofday (&tp, (void *) 0))
75 vals[7] = tp.tv_usec/1000;
78 if (values) /* null pointer for missing optional */
81 sprintf (dat, "%04d%02d%02d", vals[0], vals[1], vals[2]);
82 s_copy(date, dat, date_len, 8);
84 sprintf(zon, "%+03d%02d", vals[3] / 60, abs(vals[3] % 60));
85 s_copy(zone, zon, zone_len, 5);
88 sprintf (ftim, "%02d%02d%02d.%03d", vals[4], vals[5], vals[6], vals[7]);
89 s_copy(fftime, ftim, fftime_len, 10);