]>
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"
37 #include <sys/types.h>
40 #if (!defined(__SC__) && !defined(__SGI__) && !defined(__GNUWIN32__) && !defined(__MWERKS__)) || defined(__MINGW32__)
41 #include <sys/timeb.h>
44 #if defined(__linux__) || defined(__SVR4__) || defined(__SYSV__) || defined(__SGI__) || \
45 defined(__ALPHA__) || defined(__GNUWIN32__) || defined(__FreeBSD__) || defined(__NetBSD__)
53 #if defined(__SUN__) || defined(__OSF__)
54 // At least on Sun, ftime is undeclared.
55 // Need to be verified on other platforms.
56 extern "C" int ftime(struct timeb
*tp
);
57 // extern "C" time_t time(time_t);
58 // #include <sys/timeb.h>
59 #if defined(__SVR4__) && !defined(__ALPHA__)
60 // ditto for gettimeofday on Solaris 2.x.
61 extern "C" int gettimeofday(struct timeval
*tp
, void *);
71 void wxStartTimer(void)
73 #if defined(__xlC__) || defined(__AIX__) || defined(__SVR4__) || defined(__SYSV__) || (defined(__GNUWIN32__) && !defined(__MINGW32__)) // || defined(__AIXV3__)
75 #if defined(__SYSV__) || (defined (__GNUWIN32__) && !defined (__MINGW32__))
76 gettimeofday(&tp
, (struct timezone
*)NULL
);
80 wxStartTime
= 1000*tp
.tv_sec
+ tp
.tv_usec
/1000;
81 #elif (defined(__SC__) || defined(__SGI__) || defined(___BSDI__) || defined(__ALPHA__) || defined(__MINGW32__) || defined(__MWERKS__))
86 wxStartTime
= 1000*(60*(60*tp
->tm_hour
+tp
->tm_min
)+tp
->tm_sec
);
90 wxStartTime
= 1000*tp
.time
+ tp
.millitm
;
94 // Returns elapsed time in milliseconds
95 long wxGetElapsedTime(bool resetTimer
)
97 #if defined(__xlC__) || defined(__AIX__) || defined(__SVR4__) || defined(__SYSV__) || (defined(__GNUWIN32__) && !defined(__MINGW32__)) // || defined(__AIXV3__)
99 #if defined(__SYSV__) || (defined (__GNUWIN32__) && !defined (__MINGW32__))
100 gettimeofday(&tp
, (struct timezone
*)NULL
);
104 long oldTime
= wxStartTime
;
105 long newTime
= 1000*tp
.tv_sec
+ tp
.tv_usec
/ 1000;
107 wxStartTime
= newTime
;
108 #elif (defined(__SC__) || defined(__SGI__) || defined(___BSDI__) || defined(__ALPHA__) || defined(__MINGW32__)|| defined(__MWERKS__))
113 long oldTime
= wxStartTime
;
114 long newTime
= 1000*(60*(60*tp
->tm_hour
+tp
->tm_min
)+tp
->tm_sec
);
116 wxStartTime
= newTime
;
120 long oldTime
= wxStartTime
;
121 long newTime
= 1000*tp
.time
+ tp
.millitm
;
123 wxStartTime
= newTime
;
125 return newTime
- oldTime
;
128 // EXPERIMENTAL: comment this out if it doesn't compile.
130 bool wxGetLocalTime(long *timeZone
, int *dstObserved
)
132 #if defined(__MINGW32__) && defined(__EGCS__)
137 *timeZone
= timezone
; // tp->tm_gmtoff; // ???
138 *dstObserved
= tp
->tm_isdst
;
139 #elif defined(__MINGW32__)
146 *timeZone
= tz
._timezone
;
147 *dstObserved
= tp
->tm_isdst
;
150 #if (((defined(__SYSV__) && !defined(__HPUX__)) || defined(__MSDOS__) || defined(__WXMSW__)) && !defined(__GNUWIN32__) && !defined(__MWERKS__))
152 /* Borland uses underscores */
153 *timeZone
= _timezone
;
154 *dstObserved
= _daylight
;
156 *timeZone
= timezone
;
157 *dstObserved
= daylight
;
159 #elif defined(__xlC__) || defined(__AIX__) || defined(__SVR4__) || defined(__SYSV__) || defined(__MWERKS__) || (defined(__GNUWIN32__) && !defined(__MINGW32__)) // || defined(__AIXV3__)
160 #ifndef __MWERKS__ // shouldn't this be one scope below ?
163 #if defined(__SYSV__) || (defined(__GNUWIN32__) && !defined(__MINGW32))
165 gettimeofday(&tp
, &tz
);
166 *timeZone
= 60*(tz
.tz_minuteswest
);
167 *dstObserved
= tz
.tz_dsttime
;
174 *timeZone
= tp
->tm_gmtoff
; // ???
178 *dstObserved
= tp
->tm_isdst
;
180 #elif defined(__WXSTUBS__)
183 // #error wxGetLocalTime not implemented.
186 gettimeofday(&tp
, &tz
);
187 *timeZone
= 60*(tz
.tz_minuteswest
);
188 *dstObserved
= tz
.tz_dsttime
;
196 // Get number of seconds since 00:00:00 GMT, Jan 1st 1970.
197 long wxGetCurrentTime(void)
199 #if defined(__xlC__) || defined(__AIX__) || defined(__SVR4__) || defined(__SYSV__) // || defined(__AIXV3__)
201 #if defined(__SYSV__) || (defined (__GNUWIN32__) && !defined (__MINGW32__))
202 gettimeofday(&tp
, (struct timezone
*)NULL
);
207 #else // (defined(__SC__) || defined(__SGI__) || defined(___BSDI__) || defined(__ALPHA__))