]>
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"
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__)
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" time_t time(time_t);
60 // #include <sys/timeb.h>
61 #if defined(__SVR4__) && !defined(__ALPHA__)
62 // ditto for gettimeofday on Solaris 2.x.
63 extern "C" int gettimeofday(struct timeval
*tp
, void *);
73 void wxStartTimer(void)
75 #if defined(__xlC__) || defined(__AIX__) || defined(__SVR4__) || defined(__SYSV__) || (defined(__GNUWIN32__) && !defined(__MINGW32__)) // || defined(__AIXV3__)
77 #if defined(__SYSV__) || (defined (__GNUWIN32__) && !defined (__MINGW32__))
78 gettimeofday(&tp
, (struct timezone
*)NULL
);
82 wxStartTime
= 1000*tp
.tv_sec
+ tp
.tv_usec
/1000;
83 #elif (defined(__SC__) || defined(__SGI__) || defined(___BSDI__) || defined(__ALPHA__) || defined(__MINGW32__) || defined(__MWERKS__))
88 wxStartTime
= 1000*(60*(60*tp
->tm_hour
+tp
->tm_min
)+tp
->tm_sec
);
92 wxStartTime
= 1000*tp
.time
+ tp
.millitm
;
96 // Returns elapsed time in milliseconds
97 long wxGetElapsedTime(bool resetTimer
)
99 #if defined(__xlC__) || defined(__AIX__) || defined(__SVR4__) || defined(__SYSV__) || (defined(__GNUWIN32__) && !defined(__MINGW32__)) // || defined(__AIXV3__)
101 #if defined(__SYSV__) || (defined (__GNUWIN32__) && !defined (__MINGW32__))
102 gettimeofday(&tp
, (struct timezone
*)NULL
);
106 long oldTime
= wxStartTime
;
107 long newTime
= 1000*tp
.tv_sec
+ tp
.tv_usec
/ 1000;
109 wxStartTime
= newTime
;
110 #elif (defined(__SC__) || defined(__SGI__) || defined(___BSDI__) || defined(__ALPHA__) || defined(__MINGW32__)|| defined(__MWERKS__))
115 long oldTime
= wxStartTime
;
116 long newTime
= 1000*(60*(60*tp
->tm_hour
+tp
->tm_min
)+tp
->tm_sec
);
118 wxStartTime
= newTime
;
122 long oldTime
= wxStartTime
;
123 long newTime
= 1000*tp
.time
+ tp
.millitm
;
125 wxStartTime
= newTime
;
127 return newTime
- oldTime
;
130 // EXPERIMENTAL: comment this out if it doesn't compile.
132 bool wxGetLocalTime(long *timeZone
, int *dstObserved
)
134 #if defined(__MINGW32__) && defined(__EGCS__)
139 *timeZone
= timezone
; // tp->tm_gmtoff; // ???
140 *dstObserved
= tp
->tm_isdst
;
141 #elif defined(__MINGW32__)
148 *timeZone
= tz
._timezone
;
149 *dstObserved
= tp
->tm_isdst
;
152 #if (((defined(__SYSV__) && !defined(__HPUX__)) || defined(__MSDOS__) || defined(__WXMSW__))\
153 && !defined(__GNUWIN32__) && !defined(__MWERKS__) )
154 #if defined(__BORLANDC__)
155 /* Borland uses underscores */
156 *timeZone
= _timezone
;
157 *dstObserved
= _daylight
;
158 #elif defined(__SALFORDC__)
159 *timeZone
= _timezone
;
160 *dstObserved
= daylight
;
162 *timeZone
= timezone
;
163 *dstObserved
= daylight
;
165 #elif defined(__xlC__) || defined(__AIX__) || defined(__SVR4__) || defined(__SYSV__) || defined(__MWERKS__) || (defined(__GNUWIN32__) && !defined(__MINGW32__)) // || defined(__AIXV3__)
166 #ifndef __MWERKS__ // shouldn't this be one scope below ?
169 #if defined(__SYSV__) || (defined(__GNUWIN32__) && !defined(__MINGW32))
171 gettimeofday(&tp
, &tz
);
172 *timeZone
= 60*(tz
.tz_minuteswest
);
173 *dstObserved
= tz
.tz_dsttime
;
180 *timeZone
= tp
->tm_gmtoff
; // ???
184 *dstObserved
= tp
->tm_isdst
;
186 #elif defined(__WXSTUBS__)
189 // #error wxGetLocalTime not implemented.
192 gettimeofday(&tp
, &tz
);
193 *timeZone
= 60*(tz
.tz_minuteswest
);
194 *dstObserved
= tz
.tz_dsttime
;
202 // Get number of seconds since 00:00:00 GMT, Jan 1st 1970.
203 long wxGetCurrentTime(void)
205 #if defined(__xlC__) || defined(__AIX__) || defined(__SVR4__) || defined(__SYSV__) // || defined(__AIXV3__)
207 #if defined(__SYSV__) || (defined (__GNUWIN32__) && !defined (__MINGW32__))
208 gettimeofday(&tp
, (struct timezone
*)NULL
);
213 #else // (defined(__SC__) || defined(__SGI__) || defined(___BSDI__) || defined(__ALPHA__))