4 * Revision 1.1 2001/04/04 05:43:38 wang
5 * First commit: compiles on Linux, Amiga, Windows, Windows CE, generic gcc
7 * Revision 1.5 1999/11/26 12:52:25 bnv
8 * Added: Windows CE support
10 * Revision 1.4 1999/03/10 16:55:55 bnv
13 * Revision 1.3 1999/03/01 11:06:33 bnv
14 * Change in the format to long int for tv.tv_usec just to keep compiler happy
16 * Revision 1.2 1998/11/06 08:57:08 bnv
17 * Added: in the includes the time.h and sys/time.h
19 * Revision 1.1 1998/07/02 17:18:00 bnv
24 #if defined(MSDOS) && !defined(__WIN32__) && !defined(_MSC_VER) && !defined(WCE)
28 #elif defined(_MSC_VER)
30 # include <sys/types.h>
31 # include <sys/timeb.h>
33 /* Load both of them time.h and sys/time.h, you never now where the
37 # include <sys/time.h>
43 static double elapsed
=0.0;
45 /* ------------------ _Ltimeinit ----------------- */
49 #if defined(MSDOS) && !defined(__WIN32__) && !defined(_MSC_VER)
52 /* nothing to declare */
53 #elif defined(_MSC_VER)
61 elapsed
= (double)GetTickCount() / 1000.0;
62 #elif defined(MSDOS) && !defined(__WIN32__) && !defined(_MSC_VER)
64 elapsed
= (double)t
.ti_hour
*3600 + (double)t
.ti_min
*60 +
65 (double)t
.ti_sec
+ (double)t
.ti_hund
/100.0;
66 #elif defined(_MSC_VER)
68 elapsed
= (double)tb
.time
+ (double)tb
.millitm
/1000.0;
70 gettimeofday(&tv
,&tz
);
71 elapsed
= tv
.tv_sec
+ (double)tv
.tv_usec
/1000000.0;
75 /* -------------------- Ltime ---------------------- */
77 Ltime( const PLstr timestr
, char option
)
89 # if defined(MSDOS) && !defined(__WIN32__) && !defined(_MSC_VER)
91 # elif defined(_MSC_VER)
99 option
= l2u
[(byte
)option
];
100 Lfx(timestr
,30); LZEROSTR(*timestr
);
104 tmdata
= localtime(&now
) ;
112 hour
= tmdata
->tm_hour
;
113 ampm
= (hour
>11) ? "pm" : "am" ;
114 if ((hour
=hour
%12)==0) hour
= 12 ;
115 sprintf(LSTR(*timestr
),"%d:%02d%s",
116 hour
, tmdata
->tm_min
, ampm
) ;
119 ampm
= (hour
>11) ? TEXT("pm") : TEXT("am");
120 if ((hour
=hour
%12)==0) hour
= 12 ;
121 swprintf(buf
,TEXT("%d:%02d%s"),
122 hour
, time
.wMinute
, ampm
) ;
128 unow
= (double)GetTickCount() / 1000.0;
129 #elif defined(MSDOS) && !defined(__WIN32__) && !defined(_MSC_VER)
131 unow
= (double)t
.ti_hour
*3600 + (double)t
.ti_min
*60 +
132 (double)t
.ti_sec
+ (double)t
.ti_hund
/100.0;
133 #elif defined(_MSC_VER)
135 unow
= (double)tb
.time
+ (double)tb
.millitm
/1000.0;
137 gettimeofday(&tv
,&tz
);
138 unow
= (double)tv
.tv_sec
+ (double)tv
.tv_usec
/1000000.0;
140 LREAL(*timestr
) = unow
-elapsed
;
141 LTYPE(*timestr
) = LREAL_TY
;
142 LLEN(*timestr
) = sizeof(double);
147 sprintf(LSTR(*timestr
), "%d", tmdata
->tm_hour
) ;
149 swprintf(buf
, TEXT("%d"), time
.wHour
) ;
155 swprintf(buf
, TEXT("%02d:%02d:%02d.%03d"), time
.wHour
,
156 time
.wMinute
, time
.wSecond
, time
.wMilliseconds
) ;
157 #elif defined(MSDOS) && !defined(__WIN32__) && !defined(_MSC_VER)
159 sprintf(LSTR(*timestr
), "%02d:%02d:%02d.%02d",
160 t
.ti_hour
, t
.ti_min
, t
.ti_sec
, t
.ti_hund
);
161 #elif defined(_MSC_VER)
163 sprintf(LSTR(*timestr
), "%02d:%02d:%02d.%03ld",
164 tmdata
->tm_hour
, tmdata
->tm_min
,
165 tmdata
->tm_sec
, tb
.millitm
) ;
167 gettimeofday(&tv
,&tz
);
168 sprintf(LSTR(*timestr
), "%02d:%02d:%02d.%06ld",
169 tmdata
->tm_hour
, tmdata
->tm_min
,
170 tmdata
->tm_sec
, tv
.tv_usec
) ;
176 sprintf(LSTR(*timestr
), "%d",
177 tmdata
->tm_hour
*60 + tmdata
->tm_min
) ;
179 swprintf(buf
, TEXT("%d"),
180 time
.wHour
*60 + time
.wMinute
);
186 sprintf(LSTR(*timestr
), "%02d:%02d:%02d",
187 tmdata
->tm_hour
, tmdata
->tm_min
,
190 swprintf(buf
, TEXT("%02d:%02d:%02d"),
191 time
.wHour
, time
.wMinute
, time
.wSecond
);
197 unow
= (double)GetTickCount() / 1000.0;
198 #elif defined(MSDOS) && !defined(__WIN32__) && !defined(_MSC_VER)
200 unow
= (double)t
.ti_hour
*3600 + (double)t
.ti_min
*60 +
201 (double)t
.ti_sec
+ (double)t
.ti_hund
/100.0;
202 #elif defined(_MSC_VER)
204 unow
= (double)tb
.time
+ (double)tb
.millitm
/1000.0;
206 gettimeofday(&tv
,&tz
);
207 unow
= (double)tv
.tv_sec
+ (double)tv
.tv_usec
/1000000.0;
209 LREAL(*timestr
) = unow
-elapsed
;
211 LTYPE(*timestr
) = LREAL_TY
;
212 LLEN(*timestr
) = sizeof(double);
217 sprintf(LSTR(*timestr
), "%ld",
218 (long)((long)(tmdata
->tm_hour
*60L)+tmdata
->tm_min
)
219 *60L + (long)tmdata
->tm_sec
) ;
221 swprintf(buf
, TEXT("%ld"),
222 (long)((long)(time
.wHour
*60L)+time
.wMinute
)
223 *60L + (long)time
.wSecond
) ;
228 Lerror(ERR_INCORRECT_CALL
,0);
231 LLEN(*timestr
) = STRLEN(LSTR(*timestr
));
233 wcstombs(LSTR(*timestr
), buf
, LLEN(*timestr
)=wcslen(buf
));