]>
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 wxStartTime
=wxGetCurrentMTime();
79 // Returns elapsed time in milliseconds
80 long wxGetElapsedTime(bool resetTimer
)
82 long oldTime
= wxStartTime
;
83 long newTime
=wxGetCurrentMTime();
85 if (resetTimer
) wxStartTime
= newTime
;
86 return newTime
- oldTime
;
90 // Get number of seconds since 00:00:00 GMT, Jan 1st 1970.
91 long wxGetCurrentTime(void)
93 return wxGetCurrentMTime()/1000;
96 // return GMT time in millisecond
97 long wxGetCurrentMTime()
99 #if defined(__xlC__) || defined(__AIX__) || defined(__SVR4__) || defined(__SYSV__) || \
100 (defined(__GNUWIN32__) && !defined(__MINGW32__)) // || defined(__AIXV3__)
102 #if defined(__SYSV__) || (defined (__GNUWIN32__) && !defined (__MINGW32__))
103 gettimeofday(&tp
, (struct timezone
*)NULL
);
107 return (1000*tp
.tv_sec
+ tp
.tv_usec
/ 1000);
108 #elif (defined(__SC__) || defined(__SGI__) || defined(___BSDI__) || defined(__ALPHA__) || \
109 defined(__MINGW32__)|| defined(__MWERKS__) || defined(__FreeBSD__))
114 return 1000*(60*(60*tp
->tm_hour
+tp
->tm_min
)+tp
->tm_sec
);
118 return (1000*tp
.time
+ tp
.millitm
);
124 // This class encapsulates the above fonctions,
125 // such that several wxChrono can be created
133 void wxChrono::Start(long t
)
135 m_t0
=wxGetCurrentMTime()-t
;
139 void wxChrono::Pause()
141 m_pause
=wxGetCurrentMTime()-m_t0
;
144 void wxChrono::Resume()
146 m_t0
=wxGetCurrentMTime()-m_pause
;
150 long wxChrono::Time()
152 if (m_pause
) return m_pause
;
153 return wxGetCurrentMTime()-m_t0
;
158 // EXPERIMENTAL: comment this out if it doesn't compile.
160 bool wxGetLocalTime(long *timeZone
, int *dstObserved
)
162 #if defined(__MINGW32__)
167 # if __GNUC__ == 2 && __GNUC_MINOR__ <= 8
168 // gcc 2.8.x or earlier
171 *timeZone
= tz
._timezone
;
174 *timeZone
= _timezone
; // tp->tm_gmtoff; // ???
176 *dstObserved
= tp
->tm_isdst
;
179 #if (((defined(__SYSV__) && !defined(__HPUX__)) || defined(__MSDOS__) || defined(__WXMSW__) || defined(__WXPM__)) \
180 && !defined(__GNUWIN32__) && !defined(__MWERKS__) )
181 # if defined(__BORLANDC__)
182 /* Borland uses underscores */
183 *timeZone
= _timezone
;
184 *dstObserved
= _daylight
;
185 # elif defined(__SALFORDC__)
186 *timeZone
= _timezone
;
187 *dstObserved
= daylight
;
188 # elif defined(__VISAGECPP__)
189 *timeZone
= _timezone
;
190 *dstObserved
= daylight
;
192 *timeZone
= timezone
;
193 *dstObserved
= daylight
;
195 #elif defined(__xlC__) || defined(__AIX__) || defined(__SVR4__) || defined(__SYSV__) || defined(__MWERKS__) || (defined(__GNUWIN32__) && !defined(__MINGW32__)) // || defined(__AIXV3__)
196 # ifndef __MWERKS__ // shouldn't this be one scope below ?
199 # if defined(__SYSV__) || (defined(__GNUWIN32__) && !defined(__MINGW32))
201 gettimeofday(&tp
, &tz
);
202 *timeZone
= 60*(tz
.tz_minuteswest
);
203 *dstObserved
= tz
.tz_dsttime
;
210 *timeZone
= tp
->tm_gmtoff
; // ???
214 *dstObserved
= tp
->tm_isdst
;
216 #elif defined(__WXSTUBS__)
219 // #error wxGetLocalTime not implemented.
222 gettimeofday(&tp
, &tz
);
223 *timeZone
= 60*(tz
.tz_minuteswest
);
224 *dstObserved
= tz
.tz_dsttime
;