]>
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__) || \
47 defined(__SALFORDC__) || defined(__EMX__)
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(__EMX__) || defined(__xlC__) || defined(__AIX__) || defined(__SVR4__) || defined(__SYSV__) || \
77 (defined(__GNUWIN32__) && !defined(__MINGW32__)) // || defined(__AIXV3__)
79 #if defined(__EMX__) || defined(__SYSV__) || (defined (__GNUWIN32__) && !defined (__MINGW32__))
80 gettimeofday(&tp
, (struct timezone
*)NULL
);
84 wxStartTime
= 1000*tp
.tv_sec
+ tp
.tv_usec
/1000;
85 #elif (defined(__SC__) || defined(__SGI__) || defined(___BSDI__) || defined(__ALPHA__) || \
86 defined(__MINGW32__) || defined(__MWERKS__) || defined(__FreeBSD__) )
91 wxStartTime
= 1000*(60*(60*tp
->tm_hour
+tp
->tm_min
)+tp
->tm_sec
);
95 wxStartTime
= 1000*tp
.time
+ tp
.millitm
;
99 // Returns elapsed time in milliseconds
100 long wxGetElapsedTime(bool resetTimer
)
102 #if defined(__xlC__) || defined(__AIX__) || defined(__SVR4__) || defined(__SYSV__) || \
103 (defined(__GNUWIN32__) && !defined(__MINGW32__)) // || defined(__AIXV3__)
105 #if defined(__SYSV__) || (defined (__GNUWIN32__) && !defined (__MINGW32__))
106 gettimeofday(&tp
, (struct timezone
*)NULL
);
110 long oldTime
= wxStartTime
;
111 long newTime
= 1000*tp
.tv_sec
+ tp
.tv_usec
/ 1000;
113 wxStartTime
= newTime
;
114 #elif (defined(__SC__) || defined(__SGI__) || defined(___BSDI__) || defined(__ALPHA__) || \
115 defined(__MINGW32__)|| defined(__MWERKS__) || defined(__FreeBSD__))
120 long oldTime
= wxStartTime
;
121 long newTime
= 1000*(60*(60*tp
->tm_hour
+tp
->tm_min
)+tp
->tm_sec
);
123 wxStartTime
= newTime
;
127 long oldTime
= wxStartTime
;
128 long newTime
= 1000*tp
.time
+ tp
.millitm
;
130 wxStartTime
= newTime
;
132 return newTime
- oldTime
;
135 // EXPERIMENTAL: comment this out if it doesn't compile.
137 bool wxGetLocalTime(long *timeZone
, int *dstObserved
)
139 #if defined(__MINGW32__)
144 # if __GNUC__ == 2 && __GNUC_MINOR__ <= 8
145 // gcc 2.8.x or earlier
148 *timeZone
= tz
._timezone
;
151 *timeZone
= _timezone
; // tp->tm_gmtoff; // ???
153 *dstObserved
= tp
->tm_isdst
;
156 #if (((defined(__SYSV__) && !defined(__HPUX__)) || defined(__MSDOS__) || defined(__WXMSW__) || defined(__WXPM__)) \
157 && !defined(__GNUWIN32__) && !defined(__MWERKS__) )
158 # if defined(__BORLANDC__)
159 /* Borland uses underscores */
160 *timeZone
= _timezone
;
161 *dstObserved
= _daylight
;
162 # elif defined(__SALFORDC__)
163 *timeZone
= _timezone
;
164 *dstObserved
= daylight
;
165 # elif defined(__VISAGECPP__)
166 *timeZone
= _timezone
;
167 *dstObserved
= daylight
;
169 *timeZone
= timezone
;
170 *dstObserved
= daylight
;
172 #elif defined(__xlC__) || defined(__AIX__) || defined(__SVR4__) || defined(__SYSV__) || defined(__MWERKS__) || (defined(__GNUWIN32__) && !defined(__MINGW32__)) // || defined(__AIXV3__)
173 # ifndef __MWERKS__ // shouldn't this be one scope below ?
176 # if defined(__SYSV__) || (defined(__GNUWIN32__) && !defined(__MINGW32))
178 gettimeofday(&tp
, &tz
);
179 *timeZone
= 60*(tz
.tz_minuteswest
);
180 *dstObserved
= tz
.tz_dsttime
;
187 *timeZone
= tp
->tm_gmtoff
; // ???
191 *dstObserved
= tp
->tm_isdst
;
193 #elif defined(__WXSTUBS__)
196 // #error wxGetLocalTime not implemented.
199 gettimeofday(&tp
, &tz
);
200 *timeZone
= 60*(tz
.tz_minuteswest
);
201 *dstObserved
= tz
.tz_dsttime
;
209 // Get number of seconds since 00:00:00 GMT, Jan 1st 1970.
210 long wxGetCurrentTime(void)
212 #if defined(__xlC__) || defined(__AIX__) || defined(__SVR4__) || defined(__SYSV__) // || defined(__AIXV3__)
214 #if defined(__SYSV__) || (defined (__GNUWIN32__) && !defined (__MINGW32__) || defined(__FreeBSD__))
215 gettimeofday(&tp
, (struct timezone
*)NULL
);
220 #else // (defined(__SC__) || defined(__SGI__) || defined(___BSDI__) || defined(__ALPHA__))