summaryrefslogtreecommitdiff
path: root/qmake/tools/qdatetime.cpp
Side-by-side diff
Diffstat (limited to 'qmake/tools/qdatetime.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--qmake/tools/qdatetime.cpp70
1 files changed, 58 insertions, 12 deletions
diff --git a/qmake/tools/qdatetime.cpp b/qmake/tools/qdatetime.cpp
index 93e40a8..3137877 100644
--- a/qmake/tools/qdatetime.cpp
+++ b/qmake/tools/qdatetime.cpp
@@ -7,3 +7,3 @@
**
-** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
+** Copyright (C) 1992-2002 Trolltech AS. All rights reserved.
**
@@ -37,3 +37,2 @@
-// Get the system specific includes and defines
#include "qplatformdefs.h"
@@ -897,2 +896,8 @@ QDate QDate::addYears( int nyears ) const
y += nyears;
+
+ QDate tmp(y,m,1);
+
+ if( d > tmp.daysInMonth() )
+ d = tmp.daysInMonth();
+
QDate date(y, m, d);
@@ -992,2 +997,3 @@ QDate QDate::currentDate( Qt::TimeSpec ts )
#else
+ // posix compliant system
time_t ltime;
@@ -995,6 +1001,17 @@ QDate QDate::currentDate( Qt::TimeSpec ts )
tm *t;
+
+# if defined(QT_THREAD_SUPPORT) && defined(_POSIX_THREAD_SAFE_FUNCTIONS)
+ // use the reentrant versions of localtime() and gmtime() where available
+ tm res;
+ if ( ts == Qt::LocalTime )
+ t = localtime_r( &ltime, &res );
+ else
+ t = gmtime_r( &ltime, &res );
+# else
if ( ts == Qt::LocalTime )
t = localtime( &ltime );
- else
+ else
t = gmtime( &ltime );
+# endif // QT_THREAD_SUPPORT && _POSIX_THREAD_SAFE_FUNCTIONS
+
d.jd = gregorianToJulian( t->tm_year + 1900, t->tm_mon + 1, t->tm_mday );
@@ -1557,3 +1574,3 @@ int QTime::msecsTo( const QTime &t ) const
-/*!
+/*!
\overload
@@ -1655,2 +1672,3 @@ bool QTime::currentTime( QTime *ct, Qt::TimeSpec ts )
#elif defined(Q_OS_UNIX)
+ // posix compliant system
struct timeval tv;
@@ -1659,7 +1677,17 @@ bool QTime::currentTime( QTime *ct, Qt::TimeSpec ts )
tm *t;
- if ( ts == Qt::LocalTime ) {
+
+# if defined(QT_THREAD_SUPPORT) && defined(_POSIX_THREAD_SAFE_FUNCTIONS)
+ // use the reentrant versions of localtime() and gmtime() where available
+ tm res;
+ if ( ts == Qt::LocalTime )
+ t = localtime_r( &ltime, &res );
+ else
+ t = gmtime_r( &ltime, &res );
+# else
+ if ( ts == Qt::LocalTime )
t = localtime( &ltime );
- } else {
+ else
t = gmtime( &ltime );
- }
+# endif // QT_THREAD_SUPPORT && _POSIX_THREAD_SAFE_FUNCTIONS
+
ct->ds = (uint)( MSECS_PER_HOUR * t->tm_hour + MSECS_PER_MIN * t->tm_min +
@@ -1670,3 +1698,3 @@ bool QTime::currentTime( QTime *ct, Qt::TimeSpec ts )
tm *t;
- if ( ts == Qt::LocalTime )
+ if ( ts == Qt::LocalTime )
localtime( &ltime );
@@ -1708,5 +1736,5 @@ bool QTime::isValid( int h, int m, int s, int ms )
QTime t;
- t.start(); // start clock
- ... // some lengthy task
- qDebug( "%d\n", t.elapsed() ); // prints the number of msecs elapsed
+ t.start();
+ some_lengthy_task();
+ qDebug( "Time elapsed: %d ms", t.elapsed() );
\endcode
@@ -1962,2 +1990,18 @@ void QDateTime::setTime_t( uint secsSince1Jan1970UTC, Qt::TimeSpec ts )
tm *brokenDown = 0;
+
+#if defined(Q_OS_UNIX) && defined(QT_THREAD_SUPPORT) && defined(_POSIX_THREAD_SAFE_FUNCTIONS)
+ // posix compliant system
+ // use the reentrant versions of localtime() and gmtime() where available
+ tm res;
+ if ( ts == Qt::LocalTime )
+ brokenDown = localtime_r( &tmp, &res );
+ if ( !brokenDown ) {
+ brokenDown = gmtime_r( &tmp, &res );
+ if ( !brokenDown ) {
+ d.jd = QDate::gregorianToJulian( 1970, 1, 1 );
+ t.ds = 0;
+ return;
+ }
+ }
+#else
if ( ts == Qt::LocalTime )
@@ -1972,2 +2016,4 @@ void QDateTime::setTime_t( uint secsSince1Jan1970UTC, Qt::TimeSpec ts )
}
+#endif
+
d.jd = QDate::gregorianToJulian( brokenDown->tm_year + 1900,
@@ -2302,3 +2348,3 @@ bool QDateTime::operator>=( const QDateTime &dt ) const
\overload
-
+
Returns the current datetime, as reported by the system clock.