]>
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__) || defined(__ALPHA__) || defined(__GNUWIN32__)
50 #if defined(__SUN__) || defined(__OSF__)
51 // At least on Sun, ftime is undeclared.
52 // Need to be verified on other platforms.
53 extern "C" int ftime(struct timeb
*tp
);
54 // extern "C" time_t time(time_t);
55 // #include <sys/timeb.h>
56 #if defined(__SVR4__) && !defined(__ALPHA__)
57 // ditto for gettimeofday on Solaris 2.x.
58 extern "C" int gettimeofday(struct timeval
*tp
, void *);
68 void wxStartTimer(void)
70 #if defined(__xlC__) || defined(__AIX__) || defined(__SVR4__) || defined(__SYSV__) || (defined(__GNUWIN32__) && !defined(__MINGW32__)) // || defined(__AIXV3__)
73 gettimeofday(&tp
, (struct timezone
*)NULL
);
77 wxStartTime
= 1000*tp
.tv_sec
+ tp
.tv_usec
/1000;
78 #elif (defined(__SC__) || defined(__SGI__) || defined(___BSDI__) || defined(__ALPHA__) || defined(__MINGW32__))
83 wxStartTime
= 1000*(60*(60*tp
->tm_hour
+tp
->tm_min
)+tp
->tm_sec
);
87 wxStartTime
= 1000*tp
.time
+ tp
.millitm
;
91 // Returns elapsed time in milliseconds
92 long wxGetElapsedTime(bool resetTimer
)
94 #if defined(__xlC__) || defined(__AIX__) || defined(__SVR4__) || defined(__SYSV__) || (defined(__GNUWIN32__) && !defined(__MINGW32__)) // || defined(__AIXV3__)
97 gettimeofday(&tp
, (struct timezone
*)NULL
);
101 long oldTime
= wxStartTime
;
102 long newTime
= 1000*tp
.tv_sec
+ tp
.tv_usec
/ 1000;
104 wxStartTime
= newTime
;
105 #elif (defined(__SC__) || defined(__SGI__) || defined(___BSDI__) || defined(__ALPHA__) || defined(__MINGW32__))
110 long oldTime
= wxStartTime
;
111 long newTime
= 1000*(60*(60*tp
->tm_hour
+tp
->tm_min
)+tp
->tm_sec
);
113 wxStartTime
= newTime
;
117 long oldTime
= wxStartTime
;
118 long newTime
= 1000*tp
.time
+ tp
.millitm
;
120 wxStartTime
= newTime
;
122 return newTime
- oldTime
;
125 // EXPERIMENTAL: comment this out if it doesn't compile.
127 bool wxGetLocalTime(long *timeZone
, int *dstObserved
)
129 #if defined(__MINGW32__) && defined(__EGCS__)
134 *timeZone
= timezone
; // tp->tm_gmtoff; // ???
135 *dstObserved
= tp
->tm_isdst
;
136 #elif defined(__MINGW32__)
143 *timeZone
= tz
._timezone
;
144 *dstObserved
= tp
->tm_isdst
;
147 #if (((defined(__SYSV__) && !defined(__HPUX__)) || defined(__MSDOS__) || defined(__WXMSW__)) && !defined(__GNUWIN32__))
149 /* Borland uses underscores */
150 *timeZone
= _timezone
;
151 *dstObserved
= _daylight
;
153 *timeZone
= timezone
;
154 *dstObserved
= daylight
;
156 #elif defined(__xlC__) || defined(__AIX__) || defined(__SVR4__) || defined(__SYSV__) || (defined(__GNUWIN32__) && !defined(__MINGW32__)) // || defined(__AIXV3__)
158 #if defined(__SYSV__) || (defined(__GNUWIN32__) && !defined(__MINGW32))
160 gettimeofday(&tp
, &tz
);
161 *timeZone
= 60*(tz
.tz_minuteswest
);
162 *dstObserved
= tz
.tz_dsttime
;
168 *timeZone
= tp
->tm_gmtoff
; // ???
169 *dstObserved
= tp
->tm_isdst
;
171 #elif defined(__WXSTUBS__)
174 // #error wxGetLocalTime not implemented.
177 gettimeofday(&tp
, &tz
);
178 *timeZone
= 60*(tz
.tz_minuteswest
);
179 *dstObserved
= tz
.tz_dsttime
;
187 // Get number of seconds since 00:00:00 GMT, Jan 1st 1970.
188 long wxGetCurrentTime(void)
190 #if defined(__xlC__) || defined(__AIX__) || defined(__SVR4__) || defined(__SYSV__) // || defined(__AIXV3__)
193 gettimeofday(&tp
, (struct timezone
*)NULL
);
198 #else // (defined(__SC__) || defined(__SGI__) || defined(___BSDI__) || defined(__ALPHA__))