]>
git.saurik.com Git - wxWidgets.git/blob - src/common/timercmn.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Common timer implementation
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 //#pragma implementation "timercmn.h"
14 #pragma implementation
17 // For compilers that support precompilation, includes "wx.h".
18 #include "wx/wxprec.h"
31 #if defined(__SVR4__) && !defined(__SYSV__)
38 #include <sys/types.h>
41 #if (!defined(__SC__) && !defined(__SGI__) && !defined(__GNUWIN32__) && !defined(__MWERKS__)) || defined(__MINGW32__)
42 #include <sys/timeb.h>
45 #if defined(__linux__) || defined(__SVR4__) || defined(__SYSV__) || defined(__SGI__) || \
46 defined(__ALPHA__) || defined(__GNUWIN32__) || defined(__FreeBSD__) || defined(__NetBSD__) || \
55 #if defined(__SUN__) || defined(__OSF__) || defined(__FreeBSD__)
56 // At least on Sun, ftime is undeclared.
57 // Need to be verified on other platforms.
58 extern "C" int ftime(struct timeb
*tp
);
59 //extern "C" int gettimeofday(struct timeval *tp, void *);
60 // extern "C" time_t time(time_t);
61 // #include <sys/timeb.h>
62 #if defined(__SVR4__) && !defined(__ALPHA__)
63 // ditto for gettimeofday on Solaris 2.x.
64 extern "C" int gettimeofday(struct timeval
*tp
, void *);
74 void wxStartTimer(void)
76 #if defined(__xlC__) || defined(__AIX__) || defined(__SVR4__) || defined(__SYSV__) || (defined(__GNUWIN32__) && !defined(__MINGW32__)) // || defined(__AIXV3__)
78 #if defined(__SYSV__) || (defined (__GNUWIN32__) && !defined (__MINGW32__))
79 gettimeofday(&tp
, (struct timezone
*)NULL
);
83 wxStartTime
= 1000*tp
.tv_sec
+ tp
.tv_usec
/1000;
84 #elif (defined(__SC__) || defined(__SGI__) || defined(___BSDI__) || defined(__ALPHA__) || defined(__MINGW32__) || defined(__MWERKS__) || defined(__FreeBSD__) )
89 wxStartTime
= 1000*(60*(60*tp
->tm_hour
+tp
->tm_min
)+tp
->tm_sec
);
93 wxStartTime
= 1000*tp
.time
+ tp
.millitm
;
97 // Returns elapsed time in milliseconds
98 long wxGetElapsedTime(bool resetTimer
)
100 #if defined(__xlC__) || defined(__AIX__) || defined(__SVR4__) || defined(__SYSV__) || (defined(__GNUWIN32__) && !defined(__MINGW32__)) // || defined(__AIXV3__)
102 #if defined(__SYSV__) || (defined (__GNUWIN32__) && !defined (__MINGW32__))
103 gettimeofday(&tp
, (struct timezone
*)NULL
);
107 long oldTime
= wxStartTime
;
108 long newTime
= 1000*tp
.tv_sec
+ tp
.tv_usec
/ 1000;
110 wxStartTime
= newTime
;
111 #elif (defined(__SC__) || defined(__SGI__) || defined(___BSDI__) || defined(__ALPHA__) || defined(__MINGW32__)|| defined(__MWERKS__) || defined(__FreeBSD__))
116 long oldTime
= wxStartTime
;
117 long newTime
= 1000*(60*(60*tp
->tm_hour
+tp
->tm_min
)+tp
->tm_sec
);
119 wxStartTime
= newTime
;
123 long oldTime
= wxStartTime
;
124 long newTime
= 1000*tp
.time
+ tp
.millitm
;
126 wxStartTime
= newTime
;
128 return newTime
- oldTime
;
131 // EXPERIMENTAL: comment this out if it doesn't compile.
133 bool wxGetLocalTime(long *timeZone
, int *dstObserved
)
135 #if defined(__MINGW32__) && defined(__EGCS__)
140 *timeZone
= _timezone
; // tp->tm_gmtoff; // ???
141 *dstObserved
= tp
->tm_isdst
;
142 #elif defined(__MINGW32__)
149 *timeZone
= tz
._timezone
;
150 *dstObserved
= tp
->tm_isdst
;
153 #if (((defined(__SYSV__) && !defined(__HPUX__)) || defined(__MSDOS__) || defined(__WXMSW__))\
154 && !defined(__GNUWIN32__) && !defined(__MWERKS__) )
155 #if defined(__BORLANDC__)
156 /* Borland uses underscores */
157 *timeZone
= _timezone
;
158 *dstObserved
= _daylight
;
159 #elif defined(__SALFORDC__)
160 *timeZone
= _timezone
;
161 *dstObserved
= daylight
;
163 *timeZone
= timezone
;
164 *dstObserved
= daylight
;
166 #elif defined(__xlC__) || defined(__AIX__) || defined(__SVR4__) || defined(__SYSV__) || defined(__MWERKS__) || (defined(__GNUWIN32__) && !defined(__MINGW32__)) // || defined(__AIXV3__)
167 #ifndef __MWERKS__ // shouldn't this be one scope below ?
170 #if defined(__SYSV__) || (defined(__GNUWIN32__) && !defined(__MINGW32))
172 gettimeofday(&tp
, &tz
);
173 *timeZone
= 60*(tz
.tz_minuteswest
);
174 *dstObserved
= tz
.tz_dsttime
;
181 *timeZone
= tp
->tm_gmtoff
; // ???
185 *dstObserved
= tp
->tm_isdst
;
187 #elif defined(__WXSTUBS__)
190 // #error wxGetLocalTime not implemented.
193 gettimeofday(&tp
, &tz
);
194 *timeZone
= 60*(tz
.tz_minuteswest
);
195 *dstObserved
= tz
.tz_dsttime
;
203 // Get number of seconds since 00:00:00 GMT, Jan 1st 1970.
204 long wxGetCurrentTime(void)
206 #if defined(__xlC__) || defined(__AIX__) || defined(__SVR4__) || defined(__SYSV__) // || defined(__AIXV3__)
208 #if defined(__SYSV__) || (defined (__GNUWIN32__) && !defined (__MINGW32__) || defined(__FreeBSD__))
209 gettimeofday(&tp
, (struct timezone
*)NULL
);
214 #else // (defined(__SC__) || defined(__SGI__) || defined(___BSDI__) || defined(__ALPHA__))