]>
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"
36 #include <sys/types.h>
38 #if (!defined(__SC__) && !defined(__SGI__) && !defined(__GNUWIN32__)) || defined(__MINGW32__)
39 #include <sys/timeb.h>
42 #if defined(__linux__) || defined(__SVR4__) || defined(__SYSV__) || defined(__SGI__) || \
43 defined(__ALPHA__) || defined(__GNUWIN32__) || defined(__FreeBSD__) || defined(__NetBSD__)
51 #if defined(__SUN__) || defined(__OSF__)
52 // At least on Sun, ftime is undeclared.
53 // Need to be verified on other platforms.
54 extern "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.
59 extern "C" int gettimeofday(struct timeval
*tp
, void *);
69 void wxStartTimer(void)
71 #if defined(__xlC__) || defined(__AIX__) || defined(__SVR4__) || defined(__SYSV__) || (defined(__GNUWIN32__) && !defined(__MINGW32__)) // || defined(__AIXV3__)
74 gettimeofday(&tp
, (struct timezone
*)NULL
);
78 wxStartTime
= 1000*tp
.tv_sec
+ tp
.tv_usec
/1000;
79 #elif (defined(__SC__) || defined(__SGI__) || defined(___BSDI__) || defined(__ALPHA__) || defined(__MINGW32__))
84 wxStartTime
= 1000*(60*(60*tp
->tm_hour
+tp
->tm_min
)+tp
->tm_sec
);
88 wxStartTime
= 1000*tp
.time
+ tp
.millitm
;
92 // Returns elapsed time in milliseconds
93 long wxGetElapsedTime(bool resetTimer
)
95 #if defined(__xlC__) || defined(__AIX__) || defined(__SVR4__) || defined(__SYSV__) || (defined(__GNUWIN32__) && !defined(__MINGW32__)) // || defined(__AIXV3__)
98 gettimeofday(&tp
, (struct timezone
*)NULL
);
102 long oldTime
= wxStartTime
;
103 long newTime
= 1000*tp
.tv_sec
+ tp
.tv_usec
/ 1000;
105 wxStartTime
= newTime
;
106 #elif (defined(__SC__) || defined(__SGI__) || defined(___BSDI__) || defined(__ALPHA__) || defined(__MINGW32__))
111 long oldTime
= wxStartTime
;
112 long newTime
= 1000*(60*(60*tp
->tm_hour
+tp
->tm_min
)+tp
->tm_sec
);
114 wxStartTime
= newTime
;
118 long oldTime
= wxStartTime
;
119 long newTime
= 1000*tp
.time
+ tp
.millitm
;
121 wxStartTime
= newTime
;
123 return newTime
- oldTime
;
126 // EXPERIMENTAL: comment this out if it doesn't compile.
128 bool wxGetLocalTime(long *timeZone
, int *dstObserved
)
130 #if defined(__MINGW32__) && defined(__EGCS__)
135 *timeZone
= timezone
; // tp->tm_gmtoff; // ???
136 *dstObserved
= tp
->tm_isdst
;
137 #elif defined(__MINGW32__)
144 *timeZone
= tz
._timezone
;
145 *dstObserved
= tp
->tm_isdst
;
148 #if (((defined(__SYSV__) && !defined(__HPUX__)) || defined(__MSDOS__) || defined(__WXMSW__)) && !defined(__GNUWIN32__))
150 /* Borland uses underscores */
151 *timeZone
= _timezone
;
152 *dstObserved
= _daylight
;
154 *timeZone
= timezone
;
155 *dstObserved
= daylight
;
157 #elif defined(__xlC__) || defined(__AIX__) || defined(__SVR4__) || defined(__SYSV__) || (defined(__GNUWIN32__) && !defined(__MINGW32__)) // || defined(__AIXV3__)
159 #if defined(__SYSV__) || (defined(__GNUWIN32__) && !defined(__MINGW32))
161 gettimeofday(&tp
, &tz
);
162 *timeZone
= 60*(tz
.tz_minuteswest
);
163 *dstObserved
= tz
.tz_dsttime
;
169 *timeZone
= tp
->tm_gmtoff
; // ???
170 *dstObserved
= tp
->tm_isdst
;
172 #elif defined(__WXSTUBS__)
175 // #error wxGetLocalTime not implemented.
178 gettimeofday(&tp
, &tz
);
179 *timeZone
= 60*(tz
.tz_minuteswest
);
180 *dstObserved
= tz
.tz_dsttime
;
188 // Get number of seconds since 00:00:00 GMT, Jan 1st 1970.
189 long wxGetCurrentTime(void)
191 #if defined(__xlC__) || defined(__AIX__) || defined(__SVR4__) || defined(__SYSV__) // || defined(__AIXV3__)
194 gettimeofday(&tp
, (struct timezone
*)NULL
);
199 #else // (defined(__SC__) || defined(__SGI__) || defined(___BSDI__) || defined(__ALPHA__))