1 |
adcroft |
1.1 |
/* |
2 |
|
|
$Id: date_time.c,v 1.3 2001/06/22 22:49:16 meier Exp $ |
3 |
|
|
** |
4 |
|
|
** This program and library is free software; you can redistribute it and/or |
5 |
|
|
** modify it under the terms of the GNU (Library) General Public License |
6 |
|
|
** as published by the Free Software Foundation; either version 2 |
7 |
|
|
** of the License, or any later version. |
8 |
|
|
** |
9 |
|
|
** This program 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 |
12 |
|
|
** GNU (Library) General Public License for more details. |
13 |
|
|
** |
14 |
|
|
** You should have received a copy of the GNU (Library) General Public License |
15 |
|
|
** along with this program; if not, write to the Free Software |
16 |
|
|
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
17 |
|
|
** |
18 |
|
|
** |
19 |
|
|
** |
20 |
|
|
** 2001-03-20 rasc own module for this routine (from swish.c) |
21 |
|
|
** |
22 |
|
|
*/ |
23 |
|
|
|
24 |
|
|
|
25 |
|
|
#include <time.h> |
26 |
|
|
#include "swish.h" |
27 |
|
|
#include "mem.h" |
28 |
|
|
#include "date_time.h" |
29 |
|
|
|
30 |
|
|
|
31 |
|
|
|
32 |
|
|
|
33 |
|
|
/* |
34 |
|
|
-- TimeHiRes returns a ClockTick value (double) |
35 |
|
|
-- in seconds.fractions |
36 |
|
|
*/ |
37 |
|
|
|
38 |
|
|
#ifdef HAVE_BSDGETTIMEOFDAY |
39 |
|
|
#define gettimeofday BSDgettimeofday |
40 |
|
|
#endif |
41 |
|
|
|
42 |
|
|
#ifdef NO_GETTOD |
43 |
|
|
|
44 |
|
|
double TimeElapsed(void) |
45 |
|
|
{ |
46 |
|
|
#ifdef WIN32 |
47 |
|
|
#include <sys/timeb.h> |
48 |
|
|
|
49 |
|
|
struct _timeb ftimebuf; |
50 |
|
|
|
51 |
|
|
_ftime(&ftimebuf); |
52 |
|
|
return (double)ftimebuf.time + (double)ftimebuf.millitm/1000.0; |
53 |
|
|
|
54 |
|
|
#else |
55 |
|
|
|
56 |
|
|
return ((double) clock()) / CLOCKS_PER_SEC; |
57 |
|
|
|
58 |
|
|
#endif |
59 |
|
|
} |
60 |
|
|
|
61 |
|
|
#else |
62 |
|
|
|
63 |
|
|
#include <sys/time.h> |
64 |
|
|
|
65 |
|
|
double TimeElapsed(void) |
66 |
|
|
{ |
67 |
|
|
struct timeval t; |
68 |
|
|
int i; |
69 |
|
|
|
70 |
|
|
i = gettimeofday( &t, NULL ); |
71 |
|
|
if ( i ) return 0; |
72 |
|
|
|
73 |
|
|
return (double)( t.tv_sec + t.tv_usec / 1000000.0 ); |
74 |
|
|
} |
75 |
|
|
#endif |
76 |
|
|
|
77 |
|
|
/* return CPU time used */ |
78 |
|
|
double TimeCPU(void) |
79 |
|
|
{ |
80 |
|
|
return ((double) clock()) / CLOCKS_PER_SEC; |
81 |
|
|
} |
82 |
|
|
|
83 |
|
|
|
84 |
|
|
|
85 |
|
|
|
86 |
|
|
|
87 |
|
|
/* |
88 |
|
|
Returns the nicely formatted date. |
89 |
|
|
Returns ISO like char |
90 |
|
|
*/ |
91 |
|
|
|
92 |
|
|
char *getTheDateISO() |
93 |
|
|
{ |
94 |
|
|
char *date; |
95 |
|
|
time_t now; |
96 |
|
|
|
97 |
|
|
date=emalloc(MAXSTRLEN); |
98 |
|
|
|
99 |
|
|
now = time(NULL); |
100 |
|
|
/* 2/22/00 - switched to 4-digit year (%Y vs. %y) */ |
101 |
|
|
strftime(date, MAXSTRLEN, "%Y-%m-%d %H:%M:%S %Z", (struct tm *) localtime(&now)); |
102 |
|
|
|
103 |
|
|
return date; |
104 |
|
|
} |