]> git.saurik.com Git - wxWidgets.git/blame - src/common/timercmn.cpp
Updated the Remstar ODBC files, got the db sample compiling; added Freq and SubString
[wxWidgets.git] / src / common / timercmn.cpp
CommitLineData
c801d85f
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: timercmn.cpp
3// Purpose: Common timer implementation
4// Author: Julian Smart
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart and Markus Holzem
9// Licence: wxWindows license
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13//#pragma implementation "timercmn.h"
14#pragma implementation
15#endif
16
17// For compilers that support precompilation, includes "wx.h".
18#include "wx/wxprec.h"
19
20#ifdef __BORLANDC__
21#pragma hdrstop
22#endif
23
24#ifndef WX_PRECOMP
25#include "wx/defs.h"
26#include "wx/list.h"
27#endif
28
29#include "wx/timer.h"
30
31#ifdef __SVR4__
32#define __SYSV__
33#endif
34
35#include <time.h>
36#include <sys/types.h>
37
469e1e5c 38#if (!defined(__SC__) && !defined(__SGI__) && !defined(__GNUWIN32__) && !defined(__MWERKS__)) || defined(__MINGW32__)
c801d85f
KB
39#include <sys/timeb.h>
40#endif
41
edaa81ae
RR
42#if defined(__linux__) || defined(__SVR4__) || defined(__SYSV__) || defined(__SGI__) || \
43 defined(__ALPHA__) || defined(__GNUWIN32__) || defined(__FreeBSD__) || defined(__NetBSD__)
c801d85f
KB
44#include <sys/time.h>
45#endif
46
47#ifdef __MINGW32__
48#include "windows.h"
49#endif
50
51#if defined(__SUN__) || defined(__OSF__)
52// At least on Sun, ftime is undeclared.
53// Need to be verified on other platforms.
54extern "C" int ftime(struct timeb *tp);
55// extern "C" time_t time(time_t);
56// #include <sys/timeb.h>
57#if defined(__SVR4__) && !defined(__ALPHA__)
58// ditto for gettimeofday on Solaris 2.x.
59extern "C" int gettimeofday(struct timeval *tp, void *);
60#endif
61#endif
62
63/*
64 * Timer functions
65 *
66 */
67
68long wxStartTime = 0;
69void wxStartTimer(void)
70{
71#if defined(__xlC__) || defined(__AIX__) || defined(__SVR4__) || defined(__SYSV__) || (defined(__GNUWIN32__) && !defined(__MINGW32__)) // || defined(__AIXV3__)
72 struct timeval tp;
f57fe24c 73#if defined(__SYSV__) || (defined (__GNUWIN32__) && !defined (__MINGW32__))
c801d85f
KB
74 gettimeofday(&tp, (struct timezone *)NULL);
75#else
76 gettimeofday(&tp);
77#endif
78 wxStartTime = 1000*tp.tv_sec + tp.tv_usec/1000;
469e1e5c 79#elif (defined(__SC__) || defined(__SGI__) || defined(___BSDI__) || defined(__ALPHA__) || defined(__MINGW32__) || defined(__MWERKS__))
c801d85f
KB
80 time_t t0;
81 struct tm *tp;
82 time(&t0);
83 tp = localtime(&t0);
84 wxStartTime = 1000*(60*(60*tp->tm_hour+tp->tm_min)+tp->tm_sec);
85#else
86 struct timeb tp;
87 ftime(&tp);
88 wxStartTime = 1000*tp.time + tp.millitm;
89#endif
90}
91
92// Returns elapsed time in milliseconds
93long wxGetElapsedTime(bool resetTimer)
94{
95#if defined(__xlC__) || defined(__AIX__) || defined(__SVR4__) || defined(__SYSV__) || (defined(__GNUWIN32__) && !defined(__MINGW32__)) // || defined(__AIXV3__)
96 struct timeval tp;
f57fe24c 97#if defined(__SYSV__) || (defined (__GNUWIN32__) && !defined (__MINGW32__))
c801d85f
KB
98 gettimeofday(&tp, (struct timezone *)NULL);
99#else
100 gettimeofday(&tp);
101#endif
102 long oldTime = wxStartTime;
103 long newTime = 1000*tp.tv_sec + tp.tv_usec / 1000;
104 if (resetTimer)
105 wxStartTime = newTime;
469e1e5c 106#elif (defined(__SC__) || defined(__SGI__) || defined(___BSDI__) || defined(__ALPHA__) || defined(__MINGW32__)|| defined(__MWERKS__))
c801d85f
KB
107 time_t t0;
108 struct tm *tp;
109 time(&t0);
110 tp = localtime(&t0);
111 long oldTime = wxStartTime;
112 long newTime = 1000*(60*(60*tp->tm_hour+tp->tm_min)+tp->tm_sec);
113 if (resetTimer)
114 wxStartTime = newTime;
115#else
116 struct timeb tp;
117 ftime(&tp);
118 long oldTime = wxStartTime;
119 long newTime = 1000*tp.time + tp.millitm;
120 if (resetTimer)
121 wxStartTime = newTime;
122#endif
123 return newTime - oldTime;
124}
125
126// EXPERIMENTAL: comment this out if it doesn't compile.
127#ifndef __VMS__
128bool wxGetLocalTime(long *timeZone, int *dstObserved)
129{
130#if defined(__MINGW32__) && defined(__EGCS__)
131 time_t t0;
132 struct tm *tp;
133 time(&t0);
134 tp = localtime(&t0);
135 *timeZone = timezone; // tp->tm_gmtoff; // ???
136 *dstObserved = tp->tm_isdst;
137#elif defined(__MINGW32__)
138 time_t t0;
139 struct tm *tp;
140 time(&t0);
141 tp = localtime(&t0);
142 timeb tz;
143 ftime(& tz);
144 *timeZone = tz._timezone;
145 *dstObserved = tp->tm_isdst;
146#else
147
469e1e5c 148#if (((defined(__SYSV__) && !defined(__HPUX__)) || defined(__MSDOS__) || defined(__WXMSW__)) && !defined(__GNUWIN32__) && !defined(__MWERKS__))
c801d85f
KB
149#ifdef __BORLANDC__
150 /* Borland uses underscores */
151 *timeZone = _timezone;
152 *dstObserved = _daylight;
153#else
154 *timeZone = timezone;
155 *dstObserved = daylight;
156#endif
469e1e5c
SC
157#elif defined(__xlC__) || defined(__AIX__) || defined(__SVR4__) || defined(__SYSV__) || defined(__MWERKS__) || (defined(__GNUWIN32__) && !defined(__MINGW32__)) // || defined(__AIXV3__)
158#ifndef __MWERKS__ // shouldn't this be one scope below ?
c801d85f 159 struct timeval tp;
469e1e5c 160#endif
c801d85f
KB
161#if defined(__SYSV__) || (defined(__GNUWIN32__) && !defined(__MINGW32))
162 struct timezone tz;
163 gettimeofday(&tp, &tz);
164 *timeZone = 60*(tz.tz_minuteswest);
165 *dstObserved = tz.tz_dsttime;
166#else
167 time_t t0;
168 struct tm *tp;
169 time(&t0);
170 tp = localtime(&t0);
469e1e5c 171#ifndef __MWERKS__
c801d85f 172 *timeZone = tp->tm_gmtoff; // ???
469e1e5c
SC
173#else
174 *timeZone = 0 ;
175#endif
c801d85f
KB
176 *dstObserved = tp->tm_isdst;
177#endif
34138703
JS
178#elif defined(__WXSTUBS__)
179 return FALSE;
c801d85f
KB
180#else
181// #error wxGetLocalTime not implemented.
182 struct timeval tp;
183 struct timezone tz;
184 gettimeofday(&tp, &tz);
185 *timeZone = 60*(tz.tz_minuteswest);
186 *dstObserved = tz.tz_dsttime;
187#endif
188#endif
189 // __MINGW32__
190 return TRUE;
191}
192#endif
193
194// Get number of seconds since 00:00:00 GMT, Jan 1st 1970.
195long wxGetCurrentTime(void)
196{
197#if defined(__xlC__) || defined(__AIX__) || defined(__SVR4__) || defined(__SYSV__) // || defined(__AIXV3__)
198 struct timeval tp;
f57fe24c 199#if defined(__SYSV__) || (defined (__GNUWIN32__) && !defined (__MINGW32__))
c801d85f
KB
200 gettimeofday(&tp, (struct timezone *)NULL);
201#else
202 gettimeofday(&tp);
203#endif
204 return tp.tv_sec;
205#else // (defined(__SC__) || defined(__SGI__) || defined(___BSDI__) || defined(__ALPHA__))
206 return time(0);
207#endif
208/*
209#else
210 struct timeb tp;
211 ftime(&tp);
212 return tp.time;
213#endif
214*/
215}
216