189b56da7SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
389b56da7SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
489b56da7SAndrew Rist * or more contributor license agreements. See the NOTICE file
589b56da7SAndrew Rist * distributed with this work for additional information
689b56da7SAndrew Rist * regarding copyright ownership. The ASF licenses this file
789b56da7SAndrew Rist * to you under the Apache License, Version 2.0 (the
889b56da7SAndrew Rist * "License"); you may not use this file except in compliance
989b56da7SAndrew Rist * with the License. You may obtain a copy of the License at
1089b56da7SAndrew Rist *
1189b56da7SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
1289b56da7SAndrew Rist *
1389b56da7SAndrew Rist * Unless required by applicable law or agreed to in writing,
1489b56da7SAndrew Rist * software distributed under the License is distributed on an
1589b56da7SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1689b56da7SAndrew Rist * KIND, either express or implied. See the License for the
1789b56da7SAndrew Rist * specific language governing permissions and limitations
1889b56da7SAndrew Rist * under the License.
1989b56da7SAndrew Rist *
2089b56da7SAndrew Rist *************************************************************/
2189b56da7SAndrew Rist
2289b56da7SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_tools.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #define _TOOLS_TIME_CXX
28cdf0e10cSrcweir
29cdf0e10cSrcweir #if defined( OS2 )
30cdf0e10cSrcweir #define INCL_DOSMISC
31cdf0e10cSrcweir #define INCL_DOSDATETIME
32cdf0e10cSrcweir #include <svpm.h>
33cdf0e10cSrcweir #elif defined( WNT )
34cdf0e10cSrcweir #ifdef _MSC_VER
35cdf0e10cSrcweir #pragma warning (push,1)
36cdf0e10cSrcweir #endif
37cdf0e10cSrcweir #include <tools/svwin.h>
38cdf0e10cSrcweir #ifdef _MSC_VER
39cdf0e10cSrcweir #pragma warning (pop)
40cdf0e10cSrcweir #endif
41cdf0e10cSrcweir #elif defined UNX
42cdf0e10cSrcweir #include <unistd.h>
43cdf0e10cSrcweir #include <limits.h>
44cdf0e10cSrcweir #include <math.h>
45cdf0e10cSrcweir #include <sys/time.h>
46cdf0e10cSrcweir #endif
47cdf0e10cSrcweir
48cdf0e10cSrcweir #include <time.h>
49cdf0e10cSrcweir #include <tools/time.hxx>
50cdf0e10cSrcweir
51cdf0e10cSrcweir #if defined(SOLARIS) && defined(__GNUC__)
52cdf0e10cSrcweir extern long altzone;
53cdf0e10cSrcweir #endif
54cdf0e10cSrcweir
55cdf0e10cSrcweir // =======================================================================
56cdf0e10cSrcweir
TimeToSec100(const Time & rTime)57cdf0e10cSrcweir static sal_Int32 TimeToSec100( const Time& rTime )
58cdf0e10cSrcweir {
59cdf0e10cSrcweir short nSign = (rTime.GetTime() >= 0) ? +1 : -1;
60cdf0e10cSrcweir sal_Int32 nHour = rTime.GetHour();
61cdf0e10cSrcweir sal_Int32 nMin = rTime.GetMin();
62cdf0e10cSrcweir sal_Int32 nSec = rTime.GetSec();
63cdf0e10cSrcweir sal_Int32 n100Sec = rTime.Get100Sec();
64cdf0e10cSrcweir
65cdf0e10cSrcweir // Wegen Interal Compiler Error bei MSC, etwas komplizierter
66cdf0e10cSrcweir // return (n100Sec + (nSec*100) + (nMin*60*100) + (nHour*60*60*100) * nSign);
67cdf0e10cSrcweir
68cdf0e10cSrcweir sal_Int32 nRet = n100Sec;
69cdf0e10cSrcweir nRet += nSec*100;
70cdf0e10cSrcweir nRet += nMin*60*100;
71cdf0e10cSrcweir nRet += nHour*60*60*100;
72cdf0e10cSrcweir
73cdf0e10cSrcweir return (nRet * nSign);
74cdf0e10cSrcweir }
75cdf0e10cSrcweir
76cdf0e10cSrcweir // -----------------------------------------------------------------------
77cdf0e10cSrcweir
Sec100ToTime(sal_Int32 nSec100)78cdf0e10cSrcweir static Time Sec100ToTime( sal_Int32 nSec100 )
79cdf0e10cSrcweir {
80cdf0e10cSrcweir short nSign;
81cdf0e10cSrcweir if ( nSec100 < 0 )
82cdf0e10cSrcweir {
83cdf0e10cSrcweir nSec100 *= -1;
84cdf0e10cSrcweir nSign = -1;
85cdf0e10cSrcweir }
86cdf0e10cSrcweir else
87cdf0e10cSrcweir nSign = 1;
88cdf0e10cSrcweir
89cdf0e10cSrcweir Time aTime( 0, 0, 0, nSec100 );
90cdf0e10cSrcweir aTime.SetTime( aTime.GetTime() * nSign );
91cdf0e10cSrcweir return aTime;
92cdf0e10cSrcweir }
93cdf0e10cSrcweir
94cdf0e10cSrcweir // =======================================================================
95cdf0e10cSrcweir
Time()96cdf0e10cSrcweir Time::Time()
97cdf0e10cSrcweir {
98cdf0e10cSrcweir #if defined( OS2 )
99*27ead02aSPedro Giffuni PM_DATETIME aDateTime;
100cdf0e10cSrcweir DosGetDateTime( &aDateTime );
101cdf0e10cSrcweir
102cdf0e10cSrcweir // Zeit zusammenbauen
103cdf0e10cSrcweir nTime = (((sal_Int32)aDateTime.hours)*1000000) +
104cdf0e10cSrcweir (((sal_Int32)aDateTime.minutes)*10000) +
105cdf0e10cSrcweir (((sal_Int32)aDateTime.seconds)*100) +
106cdf0e10cSrcweir ((sal_Int32)aDateTime.hundredths);
107cdf0e10cSrcweir #elif defined( WNT )
108cdf0e10cSrcweir SYSTEMTIME aDateTime;
109cdf0e10cSrcweir GetLocalTime( &aDateTime );
110cdf0e10cSrcweir
111cdf0e10cSrcweir // Zeit zusammenbauen
112cdf0e10cSrcweir nTime = (((sal_Int32)aDateTime.wHour)*1000000) +
113cdf0e10cSrcweir (((sal_Int32)aDateTime.wMinute)*10000) +
114cdf0e10cSrcweir (((sal_Int32)aDateTime.wSecond)*100) +
115cdf0e10cSrcweir ((sal_Int32)aDateTime.wMilliseconds/10);
116cdf0e10cSrcweir #else
117cdf0e10cSrcweir time_t nTmpTime;
118cdf0e10cSrcweir struct tm aTime;
119cdf0e10cSrcweir
120cdf0e10cSrcweir // Zeit ermitteln
121cdf0e10cSrcweir nTmpTime = time( 0 );
122cdf0e10cSrcweir
123cdf0e10cSrcweir // Zeit zusammenbauen
124cdf0e10cSrcweir if ( localtime_r( &nTmpTime, &aTime ) )
125cdf0e10cSrcweir {
126cdf0e10cSrcweir nTime = (((sal_Int32)aTime.tm_hour)*1000000) +
127cdf0e10cSrcweir (((sal_Int32)aTime.tm_min)*10000) +
128cdf0e10cSrcweir (((sal_Int32)aTime.tm_sec)*100);
129cdf0e10cSrcweir }
130cdf0e10cSrcweir else
131cdf0e10cSrcweir nTime = 0;
132cdf0e10cSrcweir #endif
133cdf0e10cSrcweir }
134cdf0e10cSrcweir
135cdf0e10cSrcweir // -----------------------------------------------------------------------
136cdf0e10cSrcweir
Time(const Time & rTime)137cdf0e10cSrcweir Time::Time( const Time& rTime )
138cdf0e10cSrcweir {
139cdf0e10cSrcweir nTime = rTime.nTime;
140cdf0e10cSrcweir }
141cdf0e10cSrcweir
142cdf0e10cSrcweir // -----------------------------------------------------------------------
143cdf0e10cSrcweir
Time(sal_uIntPtr nHour,sal_uIntPtr nMin,sal_uIntPtr nSec,sal_uIntPtr n100Sec)144cdf0e10cSrcweir Time::Time( sal_uIntPtr nHour, sal_uIntPtr nMin, sal_uIntPtr nSec, sal_uIntPtr n100Sec )
145cdf0e10cSrcweir {
146cdf0e10cSrcweir // Zeit normalisieren
147cdf0e10cSrcweir nSec += n100Sec / 100;
148cdf0e10cSrcweir n100Sec = n100Sec % 100;
149cdf0e10cSrcweir nMin += nSec / 60;
150cdf0e10cSrcweir nSec = nSec % 60;
151cdf0e10cSrcweir nHour += nMin / 60;
152cdf0e10cSrcweir nMin = nMin % 60;
153cdf0e10cSrcweir
154cdf0e10cSrcweir // Zeit zusammenbauen
155cdf0e10cSrcweir nTime = (sal_Int32)(n100Sec + (nSec*100) + (nMin*10000) + (nHour*1000000));
156cdf0e10cSrcweir }
157cdf0e10cSrcweir
158cdf0e10cSrcweir // -----------------------------------------------------------------------
159cdf0e10cSrcweir
SetHour(sal_uInt16 nNewHour)160cdf0e10cSrcweir void Time::SetHour( sal_uInt16 nNewHour )
161cdf0e10cSrcweir {
162cdf0e10cSrcweir short nSign = (nTime >= 0) ? +1 : -1;
163cdf0e10cSrcweir sal_Int32 nMin = GetMin();
164cdf0e10cSrcweir sal_Int32 nSec = GetSec();
165cdf0e10cSrcweir sal_Int32 n100Sec = Get100Sec();
166cdf0e10cSrcweir
167cdf0e10cSrcweir nTime = (n100Sec + (nSec*100) + (nMin*10000) +
168cdf0e10cSrcweir (((sal_Int32)nNewHour)*1000000)) * nSign;
169cdf0e10cSrcweir }
170cdf0e10cSrcweir
171cdf0e10cSrcweir // -----------------------------------------------------------------------
172cdf0e10cSrcweir
SetMin(sal_uInt16 nNewMin)173cdf0e10cSrcweir void Time::SetMin( sal_uInt16 nNewMin )
174cdf0e10cSrcweir {
175cdf0e10cSrcweir short nSign = (nTime >= 0) ? +1 : -1;
176cdf0e10cSrcweir sal_Int32 nHour = GetHour();
177cdf0e10cSrcweir sal_Int32 nSec = GetSec();
178cdf0e10cSrcweir sal_Int32 n100Sec = Get100Sec();
179cdf0e10cSrcweir
180cdf0e10cSrcweir // kein Ueberlauf
181cdf0e10cSrcweir nNewMin = nNewMin % 60;
182cdf0e10cSrcweir
183cdf0e10cSrcweir nTime = (n100Sec + (nSec*100) + (((sal_Int32)nNewMin)*10000) +
184cdf0e10cSrcweir (nHour*1000000)) * nSign;
185cdf0e10cSrcweir }
186cdf0e10cSrcweir
187cdf0e10cSrcweir // -----------------------------------------------------------------------
188cdf0e10cSrcweir
SetSec(sal_uInt16 nNewSec)189cdf0e10cSrcweir void Time::SetSec( sal_uInt16 nNewSec )
190cdf0e10cSrcweir {
191cdf0e10cSrcweir short nSign = (nTime >= 0) ? +1 : -1;
192cdf0e10cSrcweir sal_Int32 nHour = GetHour();
193cdf0e10cSrcweir sal_Int32 nMin = GetMin();
194cdf0e10cSrcweir sal_Int32 n100Sec = Get100Sec();
195cdf0e10cSrcweir
196cdf0e10cSrcweir // kein Ueberlauf
197cdf0e10cSrcweir nNewSec = nNewSec % 60;
198cdf0e10cSrcweir
199cdf0e10cSrcweir nTime = (n100Sec + (((sal_Int32)nNewSec)*100) + (nMin*10000) +
200cdf0e10cSrcweir (nHour*1000000)) * nSign;
201cdf0e10cSrcweir }
202cdf0e10cSrcweir
203cdf0e10cSrcweir // -----------------------------------------------------------------------
204cdf0e10cSrcweir
Set100Sec(sal_uInt16 nNew100Sec)205cdf0e10cSrcweir void Time::Set100Sec( sal_uInt16 nNew100Sec )
206cdf0e10cSrcweir {
207cdf0e10cSrcweir short nSign = (nTime >= 0) ? +1 : -1;
208cdf0e10cSrcweir sal_Int32 nHour = GetHour();
209cdf0e10cSrcweir sal_Int32 nMin = GetMin();
210cdf0e10cSrcweir sal_Int32 nSec = GetSec();
211cdf0e10cSrcweir
212cdf0e10cSrcweir // kein Ueberlauf
213cdf0e10cSrcweir nNew100Sec = nNew100Sec % 100;
214cdf0e10cSrcweir
215cdf0e10cSrcweir nTime = (((sal_Int32)nNew100Sec) + (nSec*100) + (nMin*10000) +
216cdf0e10cSrcweir (nHour*1000000)) * nSign;
217cdf0e10cSrcweir }
218cdf0e10cSrcweir
219cdf0e10cSrcweir // -----------------------------------------------------------------------
220cdf0e10cSrcweir
GetMSFromTime() const221cdf0e10cSrcweir sal_Int32 Time::GetMSFromTime() const
222cdf0e10cSrcweir {
223cdf0e10cSrcweir short nSign = (nTime >= 0) ? +1 : -1;
224cdf0e10cSrcweir sal_Int32 nHour = GetHour();
225cdf0e10cSrcweir sal_Int32 nMin = GetMin();
226cdf0e10cSrcweir sal_Int32 nSec = GetSec();
227cdf0e10cSrcweir sal_Int32 n100Sec = Get100Sec();
228cdf0e10cSrcweir
229cdf0e10cSrcweir return (((nHour*3600000)+(nMin*60000)+(nSec*1000)+(n100Sec*10))*nSign);
230cdf0e10cSrcweir }
231cdf0e10cSrcweir
232cdf0e10cSrcweir // -----------------------------------------------------------------------
233cdf0e10cSrcweir
MakeTimeFromMS(sal_Int32 nMS)234cdf0e10cSrcweir void Time::MakeTimeFromMS( sal_Int32 nMS )
235cdf0e10cSrcweir {
236cdf0e10cSrcweir short nSign;
237cdf0e10cSrcweir if ( nMS < 0 )
238cdf0e10cSrcweir {
239cdf0e10cSrcweir nMS *= -1;
240cdf0e10cSrcweir nSign = -1;
241cdf0e10cSrcweir }
242cdf0e10cSrcweir else
243cdf0e10cSrcweir nSign = 1;
244cdf0e10cSrcweir
245cdf0e10cSrcweir Time aTime( 0, 0, 0, nMS/10 );
246cdf0e10cSrcweir SetTime( aTime.GetTime() * nSign );
247cdf0e10cSrcweir }
248cdf0e10cSrcweir
249cdf0e10cSrcweir // -----------------------------------------------------------------------
250cdf0e10cSrcweir
GetTimeInDays() const251cdf0e10cSrcweir double Time::GetTimeInDays() const
252cdf0e10cSrcweir {
253cdf0e10cSrcweir short nSign = (nTime >= 0) ? +1 : -1;
254cdf0e10cSrcweir double nHour = GetHour();
255cdf0e10cSrcweir double nMin = GetMin();
256cdf0e10cSrcweir double nSec = GetSec();
257cdf0e10cSrcweir double n100Sec = Get100Sec();
258cdf0e10cSrcweir
259cdf0e10cSrcweir return (nHour+(nMin/60)+(nSec/(60*60))+(n100Sec/(60*60*100))) / 24 * nSign;
260cdf0e10cSrcweir }
261cdf0e10cSrcweir
262cdf0e10cSrcweir // -----------------------------------------------------------------------
263cdf0e10cSrcweir
operator =(const Time & rTime)264cdf0e10cSrcweir Time& Time::operator =( const Time& rTime )
265cdf0e10cSrcweir {
266cdf0e10cSrcweir nTime = rTime.nTime;
267cdf0e10cSrcweir return *this;
268cdf0e10cSrcweir }
269cdf0e10cSrcweir
270cdf0e10cSrcweir // -----------------------------------------------------------------------
271cdf0e10cSrcweir
operator +=(const Time & rTime)272cdf0e10cSrcweir Time& Time::operator +=( const Time& rTime )
273cdf0e10cSrcweir {
274cdf0e10cSrcweir nTime = Sec100ToTime( TimeToSec100( *this ) +
275cdf0e10cSrcweir TimeToSec100( rTime ) ).GetTime();
276cdf0e10cSrcweir return *this;
277cdf0e10cSrcweir }
278cdf0e10cSrcweir
279cdf0e10cSrcweir // -----------------------------------------------------------------------
280cdf0e10cSrcweir
operator -=(const Time & rTime)281cdf0e10cSrcweir Time& Time::operator -=( const Time& rTime )
282cdf0e10cSrcweir {
283cdf0e10cSrcweir nTime = Sec100ToTime( TimeToSec100( *this ) -
284cdf0e10cSrcweir TimeToSec100( rTime ) ).GetTime();
285cdf0e10cSrcweir return *this;
286cdf0e10cSrcweir }
287cdf0e10cSrcweir
288cdf0e10cSrcweir // -----------------------------------------------------------------------
289cdf0e10cSrcweir
operator +(const Time & rTime1,const Time & rTime2)290cdf0e10cSrcweir Time operator +( const Time& rTime1, const Time& rTime2 )
291cdf0e10cSrcweir {
292cdf0e10cSrcweir return Sec100ToTime( TimeToSec100( rTime1 ) +
293cdf0e10cSrcweir TimeToSec100( rTime2 ) );
294cdf0e10cSrcweir }
295cdf0e10cSrcweir
296cdf0e10cSrcweir // -----------------------------------------------------------------------
297cdf0e10cSrcweir
operator -(const Time & rTime1,const Time & rTime2)298cdf0e10cSrcweir Time operator -( const Time& rTime1, const Time& rTime2 )
299cdf0e10cSrcweir {
300cdf0e10cSrcweir return Sec100ToTime( TimeToSec100( rTime1 ) -
301cdf0e10cSrcweir TimeToSec100( rTime2 ) );
302cdf0e10cSrcweir }
303cdf0e10cSrcweir
304cdf0e10cSrcweir // -----------------------------------------------------------------------
305cdf0e10cSrcweir
IsEqualIgnore100Sec(const Time & rTime) const306cdf0e10cSrcweir sal_Bool Time::IsEqualIgnore100Sec( const Time& rTime ) const
307cdf0e10cSrcweir {
308cdf0e10cSrcweir sal_Int32 n1 = (nTime < 0 ? -Get100Sec() : Get100Sec() );
309cdf0e10cSrcweir sal_Int32 n2 = (rTime.nTime < 0 ? -rTime.Get100Sec() : rTime.Get100Sec() );
310cdf0e10cSrcweir return (nTime - n1) == (rTime.nTime - n2);
311cdf0e10cSrcweir }
312cdf0e10cSrcweir
313cdf0e10cSrcweir // -----------------------------------------------------------------------
314cdf0e10cSrcweir
GetUTCOffset()315cdf0e10cSrcweir Time Time::GetUTCOffset()
316cdf0e10cSrcweir {
317cdf0e10cSrcweir #if defined( OS2 )
318cdf0e10cSrcweir #undef timezone
319*27ead02aSPedro Giffuni PM_DATETIME aDateTime;
320cdf0e10cSrcweir DosGetDateTime( &aDateTime );
321cdf0e10cSrcweir
322cdf0e10cSrcweir // Zeit zusammenbauen
323cdf0e10cSrcweir if ( aDateTime.timezone != -1 )
324cdf0e10cSrcweir {
325cdf0e10cSrcweir short nTempTime = (short)Abs( aDateTime.timezone );
326cdf0e10cSrcweir Time aTime( 0, (sal_uInt16)nTempTime );
327cdf0e10cSrcweir if ( aDateTime.timezone > 0 )
328cdf0e10cSrcweir aTime = -aTime;
329cdf0e10cSrcweir return aTime;
330cdf0e10cSrcweir }
331cdf0e10cSrcweir else
332cdf0e10cSrcweir return Time( 0 );
333cdf0e10cSrcweir #elif defined( WNT )
334cdf0e10cSrcweir TIME_ZONE_INFORMATION aTimeZone;
335cdf0e10cSrcweir aTimeZone.Bias = 0;
336cdf0e10cSrcweir DWORD nTimeZoneRet = GetTimeZoneInformation( &aTimeZone );
337cdf0e10cSrcweir sal_Int32 nTempTime = aTimeZone.Bias;
338cdf0e10cSrcweir if ( nTimeZoneRet == TIME_ZONE_ID_STANDARD )
339cdf0e10cSrcweir nTempTime += aTimeZone.StandardBias;
340cdf0e10cSrcweir else if ( nTimeZoneRet == TIME_ZONE_ID_DAYLIGHT )
341cdf0e10cSrcweir nTempTime += aTimeZone.DaylightBias;
342cdf0e10cSrcweir Time aTime( 0, (sal_uInt16)Abs( nTempTime ) );
343cdf0e10cSrcweir if ( nTempTime > 0 )
344cdf0e10cSrcweir aTime = -aTime;
345cdf0e10cSrcweir return aTime;
346cdf0e10cSrcweir #else
347cdf0e10cSrcweir static sal_uIntPtr nCacheTicks = 0;
348cdf0e10cSrcweir static sal_Int32 nCacheSecOffset = -1;
349cdf0e10cSrcweir sal_uIntPtr nTicks = Time::GetSystemTicks();
350cdf0e10cSrcweir time_t nTime;
351cdf0e10cSrcweir tm aTM;
352cdf0e10cSrcweir sal_Int32 nLocalTime;
353cdf0e10cSrcweir sal_Int32 nUTC;
354cdf0e10cSrcweir short nTempTime;
355cdf0e10cSrcweir
356cdf0e10cSrcweir // Evt. Wert neu ermitteln
357cdf0e10cSrcweir if ( (nCacheSecOffset == -1) ||
358cdf0e10cSrcweir ((nTicks - nCacheTicks) > 360000) ||
359cdf0e10cSrcweir ( nTicks < nCacheTicks ) // handle overflow
360cdf0e10cSrcweir )
361cdf0e10cSrcweir {
362cdf0e10cSrcweir nTime = time( 0 );
363cdf0e10cSrcweir localtime_r( &nTime, &aTM );
364cdf0e10cSrcweir nLocalTime = mktime( &aTM );
365cdf0e10cSrcweir #if defined( SOLARIS )
366cdf0e10cSrcweir // Solaris gmtime_r() seems not to handle daylight saving time
367cdf0e10cSrcweir // flags correctly
368cdf0e10cSrcweir nUTC = nLocalTime + ( aTM.tm_isdst == 0 ? timezone : altzone );
369cdf0e10cSrcweir #elif defined( LINUX )
370cdf0e10cSrcweir // Linux mktime() seems not to handle tm_isdst correctly
371cdf0e10cSrcweir nUTC = nLocalTime - aTM.tm_gmtoff;
372cdf0e10cSrcweir #else
373cdf0e10cSrcweir gmtime_r( &nTime, &aTM );
374cdf0e10cSrcweir nUTC = mktime( &aTM );
375cdf0e10cSrcweir #endif
376cdf0e10cSrcweir nCacheTicks = nTicks;
377cdf0e10cSrcweir nCacheSecOffset = (nLocalTime-nUTC) / 60;
378cdf0e10cSrcweir }
379cdf0e10cSrcweir
380cdf0e10cSrcweir nTempTime = (short)Abs( nCacheSecOffset );
381cdf0e10cSrcweir Time aTime( 0, (sal_uInt16)nTempTime );
382cdf0e10cSrcweir if ( nCacheSecOffset < 0 )
383cdf0e10cSrcweir aTime = -aTime;
384cdf0e10cSrcweir return aTime;
385cdf0e10cSrcweir #endif
386cdf0e10cSrcweir }
387cdf0e10cSrcweir
388cdf0e10cSrcweir
389cdf0e10cSrcweir // -----------------------------------------------------------------------
390cdf0e10cSrcweir
GetSystemTicks()391cdf0e10cSrcweir sal_uIntPtr Time::GetSystemTicks()
392cdf0e10cSrcweir {
393cdf0e10cSrcweir #if defined WNT
394cdf0e10cSrcweir return (sal_uIntPtr)GetTickCount();
395cdf0e10cSrcweir #elif defined( OS2 )
396cdf0e10cSrcweir sal_uIntPtr nClock;
397cdf0e10cSrcweir DosQuerySysInfo( QSV_MS_COUNT, QSV_MS_COUNT, &nClock, sizeof( nClock ) );
398cdf0e10cSrcweir return (sal_uIntPtr)nClock;
399cdf0e10cSrcweir #else
400cdf0e10cSrcweir timeval tv;
401cdf0e10cSrcweir gettimeofday (&tv, 0);
402cdf0e10cSrcweir
403cdf0e10cSrcweir double fTicks = tv.tv_sec;
404cdf0e10cSrcweir fTicks *= 1000;
405cdf0e10cSrcweir fTicks += ((tv.tv_usec + 500) / 1000);
406cdf0e10cSrcweir
407cdf0e10cSrcweir fTicks = fmod (fTicks, double(ULONG_MAX));
408cdf0e10cSrcweir return sal_uIntPtr(fTicks);
409cdf0e10cSrcweir #endif
410cdf0e10cSrcweir }
411cdf0e10cSrcweir
412cdf0e10cSrcweir // -----------------------------------------------------------------------
413cdf0e10cSrcweir
GetProcessTicks()414cdf0e10cSrcweir sal_uIntPtr Time::GetProcessTicks()
415cdf0e10cSrcweir {
416cdf0e10cSrcweir #if defined WNT
417cdf0e10cSrcweir return (sal_uIntPtr)GetTickCount();
418cdf0e10cSrcweir #elif defined( OS2 )
419cdf0e10cSrcweir sal_uIntPtr nClock;
420cdf0e10cSrcweir DosQuerySysInfo( QSV_MS_COUNT, QSV_MS_COUNT, &nClock, sizeof( nClock ) );
421cdf0e10cSrcweir return (sal_uIntPtr)nClock;
422cdf0e10cSrcweir #else
423cdf0e10cSrcweir static sal_uIntPtr nImplTicksPerSecond = 0;
424cdf0e10cSrcweir static double dImplTicksPerSecond;
425cdf0e10cSrcweir static double dImplTicksULONGMAX;
426cdf0e10cSrcweir sal_uIntPtr nTicks = (sal_uIntPtr)clock();
427cdf0e10cSrcweir
428cdf0e10cSrcweir if ( !nImplTicksPerSecond )
429cdf0e10cSrcweir {
430cdf0e10cSrcweir nImplTicksPerSecond = CLOCKS_PER_SEC;
431cdf0e10cSrcweir dImplTicksPerSecond = nImplTicksPerSecond;
432cdf0e10cSrcweir dImplTicksULONGMAX = (double)(sal_uIntPtr)ULONG_MAX;
433cdf0e10cSrcweir }
434cdf0e10cSrcweir
435cdf0e10cSrcweir double fTicks = nTicks;
436cdf0e10cSrcweir fTicks *= 1000;
437cdf0e10cSrcweir fTicks /= dImplTicksPerSecond;
438cdf0e10cSrcweir fTicks = fmod (fTicks, dImplTicksULONGMAX);
439cdf0e10cSrcweir return (sal_uIntPtr)fTicks;
440cdf0e10cSrcweir #endif
441cdf0e10cSrcweir }
442