-rw-r--r-- | qmake/tools/qdatetime.cpp | 70 |
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 | |||
@@ -1,86 +1,85 @@ | |||
1 | /**************************************************************************** | 1 | /**************************************************************************** |
2 | ** $Id$ | 2 | ** $Id$ |
3 | ** | 3 | ** |
4 | ** Implementation of date and time classes | 4 | ** Implementation of date and time classes |
5 | ** | 5 | ** |
6 | ** Created : 940124 | 6 | ** Created : 940124 |
7 | ** | 7 | ** |
8 | ** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. | 8 | ** Copyright (C) 1992-2002 Trolltech AS. All rights reserved. |
9 | ** | 9 | ** |
10 | ** This file is part of the tools module of the Qt GUI Toolkit. | 10 | ** This file is part of the tools module of the Qt GUI Toolkit. |
11 | ** | 11 | ** |
12 | ** This file may be distributed under the terms of the Q Public License | 12 | ** This file may be distributed under the terms of the Q Public License |
13 | ** as defined by Trolltech AS of Norway and appearing in the file | 13 | ** as defined by Trolltech AS of Norway and appearing in the file |
14 | ** LICENSE.QPL included in the packaging of this file. | 14 | ** LICENSE.QPL included in the packaging of this file. |
15 | ** | 15 | ** |
16 | ** This file may be distributed and/or modified under the terms of the | 16 | ** This file may be distributed and/or modified under the terms of the |
17 | ** GNU General Public License version 2 as published by the Free Software | 17 | ** GNU General Public License version 2 as published by the Free Software |
18 | ** Foundation and appearing in the file LICENSE.GPL included in the | 18 | ** Foundation and appearing in the file LICENSE.GPL included in the |
19 | ** packaging of this file. | 19 | ** packaging of this file. |
20 | ** | 20 | ** |
21 | ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition | 21 | ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition |
22 | ** licenses may use this file in accordance with the Qt Commercial License | 22 | ** licenses may use this file in accordance with the Qt Commercial License |
23 | ** Agreement provided with the Software. | 23 | ** Agreement provided with the Software. |
24 | ** | 24 | ** |
25 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 25 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
26 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 26 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
27 | ** | 27 | ** |
28 | ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for | 28 | ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for |
29 | ** information about Qt Commercial License Agreements. | 29 | ** information about Qt Commercial License Agreements. |
30 | ** See http://www.trolltech.com/qpl/ for QPL licensing information. | 30 | ** See http://www.trolltech.com/qpl/ for QPL licensing information. |
31 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 31 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
32 | ** | 32 | ** |
33 | ** Contact info@trolltech.com if any conditions of this licensing are | 33 | ** Contact info@trolltech.com if any conditions of this licensing are |
34 | ** not clear to you. | 34 | ** not clear to you. |
35 | ** | 35 | ** |
36 | **********************************************************************/ | 36 | **********************************************************************/ |
37 | 37 | ||
38 | // Get the system specific includes and defines | ||
39 | #include "qplatformdefs.h" | 38 | #include "qplatformdefs.h" |
40 | 39 | ||
41 | #include "qdatetime.h" | 40 | #include "qdatetime.h" |
42 | #include "qdatastream.h" | 41 | #include "qdatastream.h" |
43 | #include "qregexp.h" | 42 | #include "qregexp.h" |
44 | 43 | ||
45 | #include <stdio.h> | 44 | #include <stdio.h> |
46 | #ifndef Q_OS_TEMP | 45 | #ifndef Q_OS_TEMP |
47 | #include <time.h> | 46 | #include <time.h> |
48 | #endif | 47 | #endif |
49 | 48 | ||
50 | #if defined(Q_OS_WIN32) | 49 | #if defined(Q_OS_WIN32) |
51 | #include <windows.h> | 50 | #include <windows.h> |
52 | #endif | 51 | #endif |
53 | 52 | ||
54 | static const uint FIRST_DAY = 2361222;// Julian day for 1752-09-14 | 53 | static const uint FIRST_DAY = 2361222;// Julian day for 1752-09-14 |
55 | static const int FIRST_YEAR = 1752; // ### wrong for many countries | 54 | static const int FIRST_YEAR = 1752; // ### wrong for many countries |
56 | static const uint SECS_PER_DAY= 86400; | 55 | static const uint SECS_PER_DAY= 86400; |
57 | static const uint MSECS_PER_DAY = 86400000; | 56 | static const uint MSECS_PER_DAY = 86400000; |
58 | static const uint SECS_PER_HOUR = 3600; | 57 | static const uint SECS_PER_HOUR = 3600; |
59 | static const uint MSECS_PER_HOUR= 3600000; | 58 | static const uint MSECS_PER_HOUR= 3600000; |
60 | static const uint SECS_PER_MIN= 60; | 59 | static const uint SECS_PER_MIN= 60; |
61 | static const uint MSECS_PER_MIN = 60000; | 60 | static const uint MSECS_PER_MIN = 60000; |
62 | 61 | ||
63 | static const short monthDays[] = { | 62 | static const short monthDays[] = { |
64 | 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; | 63 | 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; |
65 | 64 | ||
66 | static const char * const qt_shortMonthNames[] = { | 65 | static const char * const qt_shortMonthNames[] = { |
67 | "Jan", "Feb", "Mar", "Apr", "May", "Jun", | 66 | "Jan", "Feb", "Mar", "Apr", "May", "Jun", |
68 | "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; | 67 | "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; |
69 | 68 | ||
70 | #ifndef QT_NO_DATESTRING | 69 | #ifndef QT_NO_DATESTRING |
71 | /***************************************************************************** | 70 | /***************************************************************************** |
72 | Some static function used by QDate, QTime and QDateTime | 71 | Some static function used by QDate, QTime and QDateTime |
73 | *****************************************************************************/ | 72 | *****************************************************************************/ |
74 | 73 | ||
75 | // Replaces tokens by their value. See QDateTime::toString() for a list of valid tokens | 74 | // Replaces tokens by their value. See QDateTime::toString() for a list of valid tokens |
76 | static QString getFmtString( const QString& f, const QTime* dt = 0, const QDate* dd = 0, bool am_pm = FALSE ) | 75 | static QString getFmtString( const QString& f, const QTime* dt = 0, const QDate* dd = 0, bool am_pm = FALSE ) |
77 | { | 76 | { |
78 | if ( f.isEmpty() ) | 77 | if ( f.isEmpty() ) |
79 | return QString::null; | 78 | return QString::null; |
80 | 79 | ||
81 | QString buf = f; | 80 | QString buf = f; |
82 | 81 | ||
83 | if ( dt ) { | 82 | if ( dt ) { |
84 | if ( f == "h" ) { | 83 | if ( f == "h" ) { |
85 | if ( ( am_pm ) && ( dt->hour() > 12 ) ) | 84 | if ( ( am_pm ) && ( dt->hour() > 12 ) ) |
86 | buf = QString::number( dt->hour() - 12 ); | 85 | buf = QString::number( dt->hour() - 12 ); |
@@ -850,198 +849,216 @@ QDate QDate::addMonths( int nmonths ) const | |||
850 | if ( nmonths < 0 && nmonths + 12 <= 0 ) { | 849 | if ( nmonths < 0 && nmonths + 12 <= 0 ) { |
851 | y--; | 850 | y--; |
852 | nmonths+=12; | 851 | nmonths+=12; |
853 | } else if ( nmonths < 0 ) { | 852 | } else if ( nmonths < 0 ) { |
854 | m+= nmonths; | 853 | m+= nmonths; |
855 | nmonths = 0; | 854 | nmonths = 0; |
856 | if ( m <= 0 ) { | 855 | if ( m <= 0 ) { |
857 | --y; | 856 | --y; |
858 | m+=12; | 857 | m+=12; |
859 | } | 858 | } |
860 | } else if ( nmonths - 12 >= 0 ) { | 859 | } else if ( nmonths - 12 >= 0 ) { |
861 | y++; | 860 | y++; |
862 | nmonths-=12; | 861 | nmonths-=12; |
863 | } else if ( m == 12 ) { | 862 | } else if ( m == 12 ) { |
864 | y++; | 863 | y++; |
865 | m = 0; | 864 | m = 0; |
866 | } else { | 865 | } else { |
867 | m+= nmonths; | 866 | m+= nmonths; |
868 | nmonths = 0; | 867 | nmonths = 0; |
869 | if ( m > 12 ) { | 868 | if ( m > 12 ) { |
870 | ++y; | 869 | ++y; |
871 | m -= 12; | 870 | m -= 12; |
872 | } | 871 | } |
873 | } | 872 | } |
874 | } | 873 | } |
875 | 874 | ||
876 | QDate tmp(y,m,1); | 875 | QDate tmp(y,m,1); |
877 | 876 | ||
878 | if( d > tmp.daysInMonth() ) | 877 | if( d > tmp.daysInMonth() ) |
879 | d = tmp.daysInMonth(); | 878 | d = tmp.daysInMonth(); |
880 | 879 | ||
881 | QDate date(y, m, d); | 880 | QDate date(y, m, d); |
882 | return date; | 881 | return date; |
883 | 882 | ||
884 | } | 883 | } |
885 | 884 | ||
886 | /*! | 885 | /*! |
887 | Returns a QDate object containing a date \a nyears later than the | 886 | Returns a QDate object containing a date \a nyears later than the |
888 | date of this object (or earlier if \a nyears is negative). | 887 | date of this object (or earlier if \a nyears is negative). |
889 | 888 | ||
890 | \sa addDays(), addMonths() | 889 | \sa addDays(), addMonths() |
891 | */ | 890 | */ |
892 | 891 | ||
893 | QDate QDate::addYears( int nyears ) const | 892 | QDate QDate::addYears( int nyears ) const |
894 | { | 893 | { |
895 | int y, m, d; | 894 | int y, m, d; |
896 | julianToGregorian( jd, y, m, d ); | 895 | julianToGregorian( jd, y, m, d ); |
897 | y += nyears; | 896 | y += nyears; |
897 | |||
898 | QDate tmp(y,m,1); | ||
899 | |||
900 | if( d > tmp.daysInMonth() ) | ||
901 | d = tmp.daysInMonth(); | ||
902 | |||
898 | QDate date(y, m, d); | 903 | QDate date(y, m, d); |
899 | return date; | 904 | return date; |
900 | } | 905 | } |
901 | 906 | ||
902 | 907 | ||
903 | 908 | ||
904 | /*! | 909 | /*! |
905 | Returns the number of days from this date to \a d (which is | 910 | Returns the number of days from this date to \a d (which is |
906 | negative if \a d is earlier than this date). | 911 | negative if \a d is earlier than this date). |
907 | 912 | ||
908 | Example: | 913 | Example: |
909 | \code | 914 | \code |
910 | QDate d1( 1995, 5, 17 ); // May 17th 1995 | 915 | QDate d1( 1995, 5, 17 ); // May 17th 1995 |
911 | QDate d2( 1995, 5, 20 ); // May 20th 1995 | 916 | QDate d2( 1995, 5, 20 ); // May 20th 1995 |
912 | d1.daysTo( d2 ); // returns 3 | 917 | d1.daysTo( d2 ); // returns 3 |
913 | d2.daysTo( d1 ); // returns -3 | 918 | d2.daysTo( d1 ); // returns -3 |
914 | \endcode | 919 | \endcode |
915 | 920 | ||
916 | \sa addDays() | 921 | \sa addDays() |
917 | */ | 922 | */ |
918 | 923 | ||
919 | int QDate::daysTo( const QDate &d ) const | 924 | int QDate::daysTo( const QDate &d ) const |
920 | { | 925 | { |
921 | return d.jd - jd; | 926 | return d.jd - jd; |
922 | } | 927 | } |
923 | 928 | ||
924 | 929 | ||
925 | /*! | 930 | /*! |
926 | \fn bool QDate::operator==( const QDate &d ) const | 931 | \fn bool QDate::operator==( const QDate &d ) const |
927 | 932 | ||
928 | Returns TRUE if this date is equal to \a d; otherwise returns FALSE. | 933 | Returns TRUE if this date is equal to \a d; otherwise returns FALSE. |
929 | */ | 934 | */ |
930 | 935 | ||
931 | /*! | 936 | /*! |
932 | \fn bool QDate::operator!=( const QDate &d ) const | 937 | \fn bool QDate::operator!=( const QDate &d ) const |
933 | 938 | ||
934 | Returns TRUE if this date is different from \a d; otherwise returns FALSE. | 939 | Returns TRUE if this date is different from \a d; otherwise returns FALSE. |
935 | */ | 940 | */ |
936 | 941 | ||
937 | /*! | 942 | /*! |
938 | \fn bool QDate::operator<( const QDate &d ) const | 943 | \fn bool QDate::operator<( const QDate &d ) const |
939 | 944 | ||
940 | Returns TRUE if this date is earlier than \a d, otherwise returns FALSE. | 945 | Returns TRUE if this date is earlier than \a d, otherwise returns FALSE. |
941 | */ | 946 | */ |
942 | 947 | ||
943 | /*! | 948 | /*! |
944 | \fn bool QDate::operator<=( const QDate &d ) const | 949 | \fn bool QDate::operator<=( const QDate &d ) const |
945 | 950 | ||
946 | Returns TRUE if this date is earlier than or equal to \a d, | 951 | Returns TRUE if this date is earlier than or equal to \a d, |
947 | otherwise returns FALSE. | 952 | otherwise returns FALSE. |
948 | */ | 953 | */ |
949 | 954 | ||
950 | /*! | 955 | /*! |
951 | \fn bool QDate::operator>( const QDate &d ) const | 956 | \fn bool QDate::operator>( const QDate &d ) const |
952 | 957 | ||
953 | Returns TRUE if this date is later than \a d, otherwise returns FALSE. | 958 | Returns TRUE if this date is later than \a d, otherwise returns FALSE. |
954 | */ | 959 | */ |
955 | 960 | ||
956 | /*! | 961 | /*! |
957 | \fn bool QDate::operator>=( const QDate &d ) const | 962 | \fn bool QDate::operator>=( const QDate &d ) const |
958 | 963 | ||
959 | Returns TRUE if this date is later than or equal to \a d, | 964 | Returns TRUE if this date is later than or equal to \a d, |
960 | otherwise returns FALSE. | 965 | otherwise returns FALSE. |
961 | */ | 966 | */ |
962 | 967 | ||
963 | /*! | 968 | /*! |
964 | \overload | 969 | \overload |
965 | Returns the current date, as reported by the system clock. | 970 | Returns the current date, as reported by the system clock. |
966 | 971 | ||
967 | \sa QTime::currentTime(), QDateTime::currentDateTime() | 972 | \sa QTime::currentTime(), QDateTime::currentDateTime() |
968 | */ | 973 | */ |
969 | 974 | ||
970 | QDate QDate::currentDate() | 975 | QDate QDate::currentDate() |
971 | { | 976 | { |
972 | return currentDate( Qt::LocalTime ); | 977 | return currentDate( Qt::LocalTime ); |
973 | } | 978 | } |
974 | 979 | ||
975 | /*! | 980 | /*! |
976 | Returns the current date, as reported by the system clock, for the | 981 | Returns the current date, as reported by the system clock, for the |
977 | TimeSpec \a ts. The default TimeSpec is LocalTime. | 982 | TimeSpec \a ts. The default TimeSpec is LocalTime. |
978 | 983 | ||
979 | \sa QTime::currentTime(), QDateTime::currentDateTime(), Qt::TimeSpec | 984 | \sa QTime::currentTime(), QDateTime::currentDateTime(), Qt::TimeSpec |
980 | */ | 985 | */ |
981 | QDate QDate::currentDate( Qt::TimeSpec ts ) | 986 | QDate QDate::currentDate( Qt::TimeSpec ts ) |
982 | { | 987 | { |
983 | QDate d; | 988 | QDate d; |
984 | #if defined(Q_OS_WIN32) | 989 | #if defined(Q_OS_WIN32) |
985 | SYSTEMTIME t; | 990 | SYSTEMTIME t; |
986 | memset( &t, 0, sizeof(SYSTEMTIME) ); | 991 | memset( &t, 0, sizeof(SYSTEMTIME) ); |
987 | if ( ts == Qt::LocalTime ) | 992 | if ( ts == Qt::LocalTime ) |
988 | GetLocalTime( &t ); | 993 | GetLocalTime( &t ); |
989 | else | 994 | else |
990 | GetSystemTime( &t ); | 995 | GetSystemTime( &t ); |
991 | d.jd = gregorianToJulian( t.wYear, t.wMonth, t.wDay ); | 996 | d.jd = gregorianToJulian( t.wYear, t.wMonth, t.wDay ); |
992 | #else | 997 | #else |
998 | // posix compliant system | ||
993 | time_t ltime; | 999 | time_t ltime; |
994 | time( <ime ); | 1000 | time( <ime ); |
995 | tm *t; | 1001 | tm *t; |
1002 | |||
1003 | # if defined(QT_THREAD_SUPPORT) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) | ||
1004 | // use the reentrant versions of localtime() and gmtime() where available | ||
1005 | tm res; | ||
1006 | if ( ts == Qt::LocalTime ) | ||
1007 | t = localtime_r( <ime, &res ); | ||
1008 | else | ||
1009 | t = gmtime_r( <ime, &res ); | ||
1010 | # else | ||
996 | if ( ts == Qt::LocalTime ) | 1011 | if ( ts == Qt::LocalTime ) |
997 | t = localtime( <ime ); | 1012 | t = localtime( <ime ); |
998 | else | 1013 | else |
999 | t = gmtime( <ime ); | 1014 | t = gmtime( <ime ); |
1015 | # endif // QT_THREAD_SUPPORT && _POSIX_THREAD_SAFE_FUNCTIONS | ||
1016 | |||
1000 | d.jd = gregorianToJulian( t->tm_year + 1900, t->tm_mon + 1, t->tm_mday ); | 1017 | d.jd = gregorianToJulian( t->tm_year + 1900, t->tm_mon + 1, t->tm_mday ); |
1001 | #endif | 1018 | #endif |
1002 | return d; | 1019 | return d; |
1003 | } | 1020 | } |
1004 | 1021 | ||
1005 | #ifndef QT_NO_DATESTRING | 1022 | #ifndef QT_NO_DATESTRING |
1006 | /*! | 1023 | /*! |
1007 | Returns the QDate represented by the string \a s, using the format | 1024 | Returns the QDate represented by the string \a s, using the format |
1008 | \a f, or an invalid date if the string cannot be parsed. | 1025 | \a f, or an invalid date if the string cannot be parsed. |
1009 | 1026 | ||
1010 | Note for \c Qt::TextDate: It is recommended that you use the | 1027 | Note for \c Qt::TextDate: It is recommended that you use the |
1011 | English short month names (e.g. "Jan"). Although localized month | 1028 | English short month names (e.g. "Jan"). Although localized month |
1012 | names can also be used, they depend on the user's locale settings. | 1029 | names can also be used, they depend on the user's locale settings. |
1013 | 1030 | ||
1014 | \warning \c Qt::LocalDate cannot be used here. | 1031 | \warning \c Qt::LocalDate cannot be used here. |
1015 | */ | 1032 | */ |
1016 | QDate QDate::fromString( const QString& s, Qt::DateFormat f ) | 1033 | QDate QDate::fromString( const QString& s, Qt::DateFormat f ) |
1017 | { | 1034 | { |
1018 | if ( ( s.isEmpty() ) || ( f == Qt::LocalDate ) ) { | 1035 | if ( ( s.isEmpty() ) || ( f == Qt::LocalDate ) ) { |
1019 | #if defined(QT_CHECK_RANGE) | 1036 | #if defined(QT_CHECK_RANGE) |
1020 | qWarning( "QDate::fromString: Parameter out of range." ); | 1037 | qWarning( "QDate::fromString: Parameter out of range." ); |
1021 | #endif | 1038 | #endif |
1022 | return QDate(); | 1039 | return QDate(); |
1023 | } | 1040 | } |
1024 | switch ( f ) { | 1041 | switch ( f ) { |
1025 | case Qt::ISODate: | 1042 | case Qt::ISODate: |
1026 | { | 1043 | { |
1027 | int year( s.mid( 0, 4 ).toInt() ); | 1044 | int year( s.mid( 0, 4 ).toInt() ); |
1028 | int month( s.mid( 5, 2 ).toInt() ); | 1045 | int month( s.mid( 5, 2 ).toInt() ); |
1029 | int day( s.mid( 8, 2 ).toInt() ); | 1046 | int day( s.mid( 8, 2 ).toInt() ); |
1030 | if ( year && month && day ) | 1047 | if ( year && month && day ) |
1031 | return QDate( year, month, day ); | 1048 | return QDate( year, month, day ); |
1032 | } | 1049 | } |
1033 | break; | 1050 | break; |
1034 | default: | 1051 | default: |
1035 | #ifndef QT_NO_TEXTDATE | 1052 | #ifndef QT_NO_TEXTDATE |
1036 | case Qt::TextDate: | 1053 | case Qt::TextDate: |
1037 | { | 1054 | { |
1038 | /* | 1055 | /* |
1039 | This will fail gracefully if the input string doesn't | 1056 | This will fail gracefully if the input string doesn't |
1040 | contain any space. | 1057 | contain any space. |
1041 | */ | 1058 | */ |
1042 | int monthPos = s.find( ' ' ) + 1; | 1059 | int monthPos = s.find( ' ' ) + 1; |
1043 | int dayPos = s.find( ' ', monthPos ) + 1; | 1060 | int dayPos = s.find( ' ', monthPos ) + 1; |
1044 | 1061 | ||
1045 | QString monthName( s.mid(monthPos, dayPos - monthPos - 1) ); | 1062 | QString monthName( s.mid(monthPos, dayPos - monthPos - 1) ); |
1046 | int month = -1; | 1063 | int month = -1; |
1047 | 1064 | ||
@@ -1510,97 +1527,97 @@ QTime QTime::addMSecs( int ms ) const | |||
1510 | */ | 1527 | */ |
1511 | 1528 | ||
1512 | int QTime::msecsTo( const QTime &t ) const | 1529 | int QTime::msecsTo( const QTime &t ) const |
1513 | { | 1530 | { |
1514 | return (int)t.ds - (int)ds; | 1531 | return (int)t.ds - (int)ds; |
1515 | } | 1532 | } |
1516 | 1533 | ||
1517 | 1534 | ||
1518 | /*! | 1535 | /*! |
1519 | \fn bool QTime::operator==( const QTime &t ) const | 1536 | \fn bool QTime::operator==( const QTime &t ) const |
1520 | 1537 | ||
1521 | Returns TRUE if this time is equal to \a t; otherwise returns FALSE. | 1538 | Returns TRUE if this time is equal to \a t; otherwise returns FALSE. |
1522 | */ | 1539 | */ |
1523 | 1540 | ||
1524 | /*! | 1541 | /*! |
1525 | \fn bool QTime::operator!=( const QTime &t ) const | 1542 | \fn bool QTime::operator!=( const QTime &t ) const |
1526 | 1543 | ||
1527 | Returns TRUE if this time is different from \a t; otherwise returns FALSE. | 1544 | Returns TRUE if this time is different from \a t; otherwise returns FALSE. |
1528 | */ | 1545 | */ |
1529 | 1546 | ||
1530 | /*! | 1547 | /*! |
1531 | \fn bool QTime::operator<( const QTime &t ) const | 1548 | \fn bool QTime::operator<( const QTime &t ) const |
1532 | 1549 | ||
1533 | Returns TRUE if this time is earlier than \a t; otherwise returns FALSE. | 1550 | Returns TRUE if this time is earlier than \a t; otherwise returns FALSE. |
1534 | */ | 1551 | */ |
1535 | 1552 | ||
1536 | /*! | 1553 | /*! |
1537 | \fn bool QTime::operator<=( const QTime &t ) const | 1554 | \fn bool QTime::operator<=( const QTime &t ) const |
1538 | 1555 | ||
1539 | Returns TRUE if this time is earlier than or equal to \a t; | 1556 | Returns TRUE if this time is earlier than or equal to \a t; |
1540 | otherwise returns FALSE. | 1557 | otherwise returns FALSE. |
1541 | */ | 1558 | */ |
1542 | 1559 | ||
1543 | /*! | 1560 | /*! |
1544 | \fn bool QTime::operator>( const QTime &t ) const | 1561 | \fn bool QTime::operator>( const QTime &t ) const |
1545 | 1562 | ||
1546 | Returns TRUE if this time is later than \a t; otherwise returns FALSE. | 1563 | Returns TRUE if this time is later than \a t; otherwise returns FALSE. |
1547 | */ | 1564 | */ |
1548 | 1565 | ||
1549 | /*! | 1566 | /*! |
1550 | \fn bool QTime::operator>=( const QTime &t ) const | 1567 | \fn bool QTime::operator>=( const QTime &t ) const |
1551 | 1568 | ||
1552 | Returns TRUE if this time is later than or equal to \a t; | 1569 | Returns TRUE if this time is later than or equal to \a t; |
1553 | otherwise returns FALSE. | 1570 | otherwise returns FALSE. |
1554 | */ | 1571 | */ |
1555 | 1572 | ||
1556 | 1573 | ||
1557 | 1574 | ||
1558 | /*! | 1575 | /*! |
1559 | \overload | 1576 | \overload |
1560 | 1577 | ||
1561 | Returns the current time as reported by the system clock. | 1578 | Returns the current time as reported by the system clock. |
1562 | 1579 | ||
1563 | Note that the accuracy depends on the accuracy of the underlying | 1580 | Note that the accuracy depends on the accuracy of the underlying |
1564 | operating system; not all systems provide 1-millisecond accuracy. | 1581 | operating system; not all systems provide 1-millisecond accuracy. |
1565 | */ | 1582 | */ |
1566 | 1583 | ||
1567 | QTime QTime::currentTime() | 1584 | QTime QTime::currentTime() |
1568 | { | 1585 | { |
1569 | return currentTime( Qt::LocalTime ); | 1586 | return currentTime( Qt::LocalTime ); |
1570 | } | 1587 | } |
1571 | 1588 | ||
1572 | /*! | 1589 | /*! |
1573 | Returns the current time as reported by the system clock, for the | 1590 | Returns the current time as reported by the system clock, for the |
1574 | TimeSpec \a ts. The default TimeSpec is LocalTime. | 1591 | TimeSpec \a ts. The default TimeSpec is LocalTime. |
1575 | 1592 | ||
1576 | Note that the accuracy depends on the accuracy of the underlying | 1593 | Note that the accuracy depends on the accuracy of the underlying |
1577 | operating system; not all systems provide 1-millisecond accuracy. | 1594 | operating system; not all systems provide 1-millisecond accuracy. |
1578 | 1595 | ||
1579 | \sa Qt::TimeSpec | 1596 | \sa Qt::TimeSpec |
1580 | */ | 1597 | */ |
1581 | QTime QTime::currentTime( Qt::TimeSpec ts ) | 1598 | QTime QTime::currentTime( Qt::TimeSpec ts ) |
1582 | { | 1599 | { |
1583 | QTime t; | 1600 | QTime t; |
1584 | currentTime( &t, ts ); | 1601 | currentTime( &t, ts ); |
1585 | return t; | 1602 | return t; |
1586 | } | 1603 | } |
1587 | 1604 | ||
1588 | #ifndef QT_NO_DATESTRING | 1605 | #ifndef QT_NO_DATESTRING |
1589 | /*! | 1606 | /*! |
1590 | Returns the representation \a s as a QTime using the format \a f, | 1607 | Returns the representation \a s as a QTime using the format \a f, |
1591 | or an invalid time if this is not possible. | 1608 | or an invalid time if this is not possible. |
1592 | 1609 | ||
1593 | \warning Note that \c Qt::LocalDate cannot be used here. | 1610 | \warning Note that \c Qt::LocalDate cannot be used here. |
1594 | */ | 1611 | */ |
1595 | QTime QTime::fromString( const QString& s, Qt::DateFormat f ) | 1612 | QTime QTime::fromString( const QString& s, Qt::DateFormat f ) |
1596 | { | 1613 | { |
1597 | if ( ( s.isEmpty() ) || ( f == Qt::LocalDate ) ) { | 1614 | if ( ( s.isEmpty() ) || ( f == Qt::LocalDate ) ) { |
1598 | #if defined(QT_CHECK_RANGE) | 1615 | #if defined(QT_CHECK_RANGE) |
1599 | qWarning( "QTime::fromString: Parameter out of range." ); | 1616 | qWarning( "QTime::fromString: Parameter out of range." ); |
1600 | #endif | 1617 | #endif |
1601 | return QTime(); | 1618 | return QTime(); |
1602 | } | 1619 | } |
1603 | 1620 | ||
1604 | int hour( s.mid( 0, 2 ).toInt() ); | 1621 | int hour( s.mid( 0, 2 ).toInt() ); |
1605 | int minute( s.mid( 3, 2 ).toInt() ); | 1622 | int minute( s.mid( 3, 2 ).toInt() ); |
1606 | int second( s.mid( 6, 2 ).toInt() ); | 1623 | int second( s.mid( 6, 2 ).toInt() ); |
@@ -1608,152 +1625,163 @@ QTime QTime::fromString( const QString& s, Qt::DateFormat f ) | |||
1608 | return QTime( hour, minute, second, msec ); | 1625 | return QTime( hour, minute, second, msec ); |
1609 | } | 1626 | } |
1610 | #endif | 1627 | #endif |
1611 | 1628 | ||
1612 | /*! | 1629 | /*! |
1613 | \internal | 1630 | \internal |
1614 | \obsolete | 1631 | \obsolete |
1615 | 1632 | ||
1616 | Fetches the current time and returns TRUE if the time is within one | 1633 | Fetches the current time and returns TRUE if the time is within one |
1617 | minute after midnight, otherwise FALSE. The return value is used by | 1634 | minute after midnight, otherwise FALSE. The return value is used by |
1618 | QDateTime::currentDateTime() to ensure that the date there is correct. | 1635 | QDateTime::currentDateTime() to ensure that the date there is correct. |
1619 | */ | 1636 | */ |
1620 | 1637 | ||
1621 | bool QTime::currentTime( QTime *ct ) | 1638 | bool QTime::currentTime( QTime *ct ) |
1622 | { | 1639 | { |
1623 | return currentTime( ct, Qt::LocalTime ); | 1640 | return currentTime( ct, Qt::LocalTime ); |
1624 | } | 1641 | } |
1625 | 1642 | ||
1626 | 1643 | ||
1627 | /*! | 1644 | /*! |
1628 | \internal | 1645 | \internal |
1629 | 1646 | ||
1630 | Fetches the current time, for the TimeSpec \a ts, and returns TRUE | 1647 | Fetches the current time, for the TimeSpec \a ts, and returns TRUE |
1631 | if the time is within one minute after midnight, otherwise FALSE. The | 1648 | if the time is within one minute after midnight, otherwise FALSE. The |
1632 | return value is used by QDateTime::currentDateTime() to ensure that | 1649 | return value is used by QDateTime::currentDateTime() to ensure that |
1633 | the date there is correct. The default TimeSpec is LocalTime. | 1650 | the date there is correct. The default TimeSpec is LocalTime. |
1634 | 1651 | ||
1635 | \sa Qt::TimeSpec | 1652 | \sa Qt::TimeSpec |
1636 | */ | 1653 | */ |
1637 | bool QTime::currentTime( QTime *ct, Qt::TimeSpec ts ) | 1654 | bool QTime::currentTime( QTime *ct, Qt::TimeSpec ts ) |
1638 | { | 1655 | { |
1639 | if ( !ct ) { | 1656 | if ( !ct ) { |
1640 | #if defined(QT_CHECK_NULL) | 1657 | #if defined(QT_CHECK_NULL) |
1641 | qWarning( "QTime::currentTime(QTime *): Null pointer not allowed" ); | 1658 | qWarning( "QTime::currentTime(QTime *): Null pointer not allowed" ); |
1642 | #endif | 1659 | #endif |
1643 | return FALSE; | 1660 | return FALSE; |
1644 | } | 1661 | } |
1645 | 1662 | ||
1646 | #if defined(Q_OS_WIN32) | 1663 | #if defined(Q_OS_WIN32) |
1647 | SYSTEMTIME t; | 1664 | SYSTEMTIME t; |
1648 | if ( ts == Qt::LocalTime ) { | 1665 | if ( ts == Qt::LocalTime ) { |
1649 | GetLocalTime( &t ); | 1666 | GetLocalTime( &t ); |
1650 | } else { | 1667 | } else { |
1651 | GetSystemTime( &t ); | 1668 | GetSystemTime( &t ); |
1652 | } | 1669 | } |
1653 | ct->ds = (uint)( MSECS_PER_HOUR*t.wHour + MSECS_PER_MIN*t.wMinute + | 1670 | ct->ds = (uint)( MSECS_PER_HOUR*t.wHour + MSECS_PER_MIN*t.wMinute + |
1654 | 1000*t.wSecond + t.wMilliseconds ); | 1671 | 1000*t.wSecond + t.wMilliseconds ); |
1655 | #elif defined(Q_OS_UNIX) | 1672 | #elif defined(Q_OS_UNIX) |
1673 | // posix compliant system | ||
1656 | struct timeval tv; | 1674 | struct timeval tv; |
1657 | gettimeofday( &tv, 0 ); | 1675 | gettimeofday( &tv, 0 ); |
1658 | time_t ltime = tv.tv_sec; | 1676 | time_t ltime = tv.tv_sec; |
1659 | tm *t; | 1677 | tm *t; |
1660 | if ( ts == Qt::LocalTime ) { | 1678 | |
1679 | # if defined(QT_THREAD_SUPPORT) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) | ||
1680 | // use the reentrant versions of localtime() and gmtime() where available | ||
1681 | tm res; | ||
1682 | if ( ts == Qt::LocalTime ) | ||
1683 | t = localtime_r( <ime, &res ); | ||
1684 | else | ||
1685 | t = gmtime_r( <ime, &res ); | ||
1686 | # else | ||
1687 | if ( ts == Qt::LocalTime ) | ||
1661 | t = localtime( <ime ); | 1688 | t = localtime( <ime ); |
1662 | } else { | 1689 | else |
1663 | t = gmtime( <ime ); | 1690 | t = gmtime( <ime ); |
1664 | } | 1691 | # endif // QT_THREAD_SUPPORT && _POSIX_THREAD_SAFE_FUNCTIONS |
1692 | |||
1665 | ct->ds = (uint)( MSECS_PER_HOUR * t->tm_hour + MSECS_PER_MIN * t->tm_min + | 1693 | ct->ds = (uint)( MSECS_PER_HOUR * t->tm_hour + MSECS_PER_MIN * t->tm_min + |
1666 | 1000 * t->tm_sec + tv.tv_usec / 1000 ); | 1694 | 1000 * t->tm_sec + tv.tv_usec / 1000 ); |
1667 | #else | 1695 | #else |
1668 | time_t ltime; // no millisecond resolution | 1696 | time_t ltime; // no millisecond resolution |
1669 | ::time( <ime ); | 1697 | ::time( <ime ); |
1670 | tm *t; | 1698 | tm *t; |
1671 | if ( ts == Qt::LocalTime ) | 1699 | if ( ts == Qt::LocalTime ) |
1672 | localtime( <ime ); | 1700 | localtime( <ime ); |
1673 | else | 1701 | else |
1674 | gmtime( <ime ); | 1702 | gmtime( <ime ); |
1675 | ct->ds = (uint) ( MSECS_PER_HOUR * t->tm_hour + MSECS_PER_MIN * t->tm_min + | 1703 | ct->ds = (uint) ( MSECS_PER_HOUR * t->tm_hour + MSECS_PER_MIN * t->tm_min + |
1676 | 1000 * t->tm_sec ); | 1704 | 1000 * t->tm_sec ); |
1677 | #endif | 1705 | #endif |
1678 | // 00:00.00 to 00:00.59.999 is considered as "midnight or right after" | 1706 | // 00:00.00 to 00:00.59.999 is considered as "midnight or right after" |
1679 | return ct->ds < (uint) MSECS_PER_MIN; | 1707 | return ct->ds < (uint) MSECS_PER_MIN; |
1680 | } | 1708 | } |
1681 | 1709 | ||
1682 | /*! | 1710 | /*! |
1683 | \overload | 1711 | \overload |
1684 | 1712 | ||
1685 | Returns TRUE if the specified time is valid; otherwise returns | 1713 | Returns TRUE if the specified time is valid; otherwise returns |
1686 | FALSE. | 1714 | FALSE. |
1687 | 1715 | ||
1688 | The time is valid if \a h is in the range 0..23, \a m and \a s are | 1716 | The time is valid if \a h is in the range 0..23, \a m and \a s are |
1689 | in the range 0..59, and \a ms is in the range 0..999. | 1717 | in the range 0..59, and \a ms is in the range 0..999. |
1690 | 1718 | ||
1691 | Example: | 1719 | Example: |
1692 | \code | 1720 | \code |
1693 | QTime::isValid(21, 10, 30); // returns TRUE | 1721 | QTime::isValid(21, 10, 30); // returns TRUE |
1694 | QTime::isValid(22, 5, 62); // returns FALSE | 1722 | QTime::isValid(22, 5, 62); // returns FALSE |
1695 | \endcode | 1723 | \endcode |
1696 | */ | 1724 | */ |
1697 | 1725 | ||
1698 | bool QTime::isValid( int h, int m, int s, int ms ) | 1726 | bool QTime::isValid( int h, int m, int s, int ms ) |
1699 | { | 1727 | { |
1700 | return (uint)h < 24 && (uint)m < 60 && (uint)s < 60 && (uint)ms < 1000; | 1728 | return (uint)h < 24 && (uint)m < 60 && (uint)s < 60 && (uint)ms < 1000; |
1701 | } | 1729 | } |
1702 | 1730 | ||
1703 | 1731 | ||
1704 | /*! | 1732 | /*! |
1705 | Sets this time to the current time. This is practical for timing: | 1733 | Sets this time to the current time. This is practical for timing: |
1706 | 1734 | ||
1707 | \code | 1735 | \code |
1708 | QTime t; | 1736 | QTime t; |
1709 | t.start(); // start clock | 1737 | t.start(); |
1710 | ... // some lengthy task | 1738 | some_lengthy_task(); |
1711 | qDebug( "%d\n", t.elapsed() ); // prints the number of msecs elapsed | 1739 | qDebug( "Time elapsed: %d ms", t.elapsed() ); |
1712 | \endcode | 1740 | \endcode |
1713 | 1741 | ||
1714 | \sa restart(), elapsed(), currentTime() | 1742 | \sa restart(), elapsed(), currentTime() |
1715 | */ | 1743 | */ |
1716 | 1744 | ||
1717 | void QTime::start() | 1745 | void QTime::start() |
1718 | { | 1746 | { |
1719 | *this = currentTime(); | 1747 | *this = currentTime(); |
1720 | } | 1748 | } |
1721 | 1749 | ||
1722 | /*! | 1750 | /*! |
1723 | Sets this time to the current time and returns the number of | 1751 | Sets this time to the current time and returns the number of |
1724 | milliseconds that have elapsed since the last time start() or | 1752 | milliseconds that have elapsed since the last time start() or |
1725 | restart() was called. | 1753 | restart() was called. |
1726 | 1754 | ||
1727 | This function is guaranteed to be atomic and is thus very handy | 1755 | This function is guaranteed to be atomic and is thus very handy |
1728 | for repeated measurements. Call start() to start the first | 1756 | for repeated measurements. Call start() to start the first |
1729 | measurement and then restart() for each later measurement. | 1757 | measurement and then restart() for each later measurement. |
1730 | 1758 | ||
1731 | Note that the counter wraps to zero 24 hours after the last call | 1759 | Note that the counter wraps to zero 24 hours after the last call |
1732 | to start() or restart(). | 1760 | to start() or restart(). |
1733 | 1761 | ||
1734 | \warning If the system's clock setting has been changed since the | 1762 | \warning If the system's clock setting has been changed since the |
1735 | last time start() or restart() was called, the result is | 1763 | last time start() or restart() was called, the result is |
1736 | undefined. This can happen when daylight savings time is turned on | 1764 | undefined. This can happen when daylight savings time is turned on |
1737 | or off. | 1765 | or off. |
1738 | 1766 | ||
1739 | \sa start(), elapsed(), currentTime() | 1767 | \sa start(), elapsed(), currentTime() |
1740 | */ | 1768 | */ |
1741 | 1769 | ||
1742 | int QTime::restart() | 1770 | int QTime::restart() |
1743 | { | 1771 | { |
1744 | QTime t = currentTime(); | 1772 | QTime t = currentTime(); |
1745 | int n = msecsTo( t ); | 1773 | int n = msecsTo( t ); |
1746 | if ( n < 0 ) // passed midnight | 1774 | if ( n < 0 ) // passed midnight |
1747 | n += 86400*1000; | 1775 | n += 86400*1000; |
1748 | *this = t; | 1776 | *this = t; |
1749 | return n; | 1777 | return n; |
1750 | } | 1778 | } |
1751 | 1779 | ||
1752 | /*! | 1780 | /*! |
1753 | Returns the number of milliseconds that have elapsed since the | 1781 | Returns the number of milliseconds that have elapsed since the |
1754 | last time start() or restart() was called. | 1782 | last time start() or restart() was called. |
1755 | 1783 | ||
1756 | Note that the counter wraps to zero 24 hours after the last call | 1784 | Note that the counter wraps to zero 24 hours after the last call |
1757 | to start() or restart. | 1785 | to start() or restart. |
1758 | 1786 | ||
1759 | Note that the accuracy depends on the accuracy of the underlying | 1787 | Note that the accuracy depends on the accuracy of the underlying |
@@ -1915,106 +1943,124 @@ QDateTime::QDateTime( const QDate &date, const QTime &time ) | |||
1915 | 1943 | ||
1916 | \sa setTime_t() | 1944 | \sa setTime_t() |
1917 | */ | 1945 | */ |
1918 | 1946 | ||
1919 | uint QDateTime::toTime_t() const | 1947 | uint QDateTime::toTime_t() const |
1920 | { | 1948 | { |
1921 | tm brokenDown; | 1949 | tm brokenDown; |
1922 | brokenDown.tm_sec = t.second(); | 1950 | brokenDown.tm_sec = t.second(); |
1923 | brokenDown.tm_min = t.minute(); | 1951 | brokenDown.tm_min = t.minute(); |
1924 | brokenDown.tm_hour = t.hour(); | 1952 | brokenDown.tm_hour = t.hour(); |
1925 | brokenDown.tm_mday = d.day(); | 1953 | brokenDown.tm_mday = d.day(); |
1926 | brokenDown.tm_mon = d.month() - 1; | 1954 | brokenDown.tm_mon = d.month() - 1; |
1927 | brokenDown.tm_year = d.year() - 1900; | 1955 | brokenDown.tm_year = d.year() - 1900; |
1928 | brokenDown.tm_isdst = -1; | 1956 | brokenDown.tm_isdst = -1; |
1929 | int secsSince1Jan1970UTC = (int) mktime( &brokenDown ); | 1957 | int secsSince1Jan1970UTC = (int) mktime( &brokenDown ); |
1930 | if ( secsSince1Jan1970UTC < -1 ) | 1958 | if ( secsSince1Jan1970UTC < -1 ) |
1931 | secsSince1Jan1970UTC = -1; | 1959 | secsSince1Jan1970UTC = -1; |
1932 | return (uint) secsSince1Jan1970UTC; | 1960 | return (uint) secsSince1Jan1970UTC; |
1933 | } | 1961 | } |
1934 | 1962 | ||
1935 | /*! | 1963 | /*! |
1936 | \overload | 1964 | \overload |
1937 | 1965 | ||
1938 | Convenience function that sets the date and time to local time | 1966 | Convenience function that sets the date and time to local time |
1939 | based on the given UTC time. | 1967 | based on the given UTC time. |
1940 | */ | 1968 | */ |
1941 | 1969 | ||
1942 | void QDateTime::setTime_t( uint secsSince1Jan1970UTC ) | 1970 | void QDateTime::setTime_t( uint secsSince1Jan1970UTC ) |
1943 | { | 1971 | { |
1944 | setTime_t( secsSince1Jan1970UTC, Qt::LocalTime ); | 1972 | setTime_t( secsSince1Jan1970UTC, Qt::LocalTime ); |
1945 | } | 1973 | } |
1946 | 1974 | ||
1947 | /*! | 1975 | /*! |
1948 | Sets the date and time to \a ts time (\c Qt::LocalTime or \c | 1976 | Sets the date and time to \a ts time (\c Qt::LocalTime or \c |
1949 | Qt::UTC) given the number of seconds that have passed since | 1977 | Qt::UTC) given the number of seconds that have passed since |
1950 | 1970-01-01T00:00:00, Coordinated Universal Time (UTC). On systems | 1978 | 1970-01-01T00:00:00, Coordinated Universal Time (UTC). On systems |
1951 | that do not support timezones this function will behave as if | 1979 | that do not support timezones this function will behave as if |
1952 | local time were UTC. | 1980 | local time were UTC. |
1953 | 1981 | ||
1954 | On Windows, only a subset of \a secsSince1Jan1970UTC values are | 1982 | On Windows, only a subset of \a secsSince1Jan1970UTC values are |
1955 | supported, as Windows starts counting from 1980. | 1983 | supported, as Windows starts counting from 1980. |
1956 | 1984 | ||
1957 | \sa toTime_t() | 1985 | \sa toTime_t() |
1958 | */ | 1986 | */ |
1959 | void QDateTime::setTime_t( uint secsSince1Jan1970UTC, Qt::TimeSpec ts ) | 1987 | void QDateTime::setTime_t( uint secsSince1Jan1970UTC, Qt::TimeSpec ts ) |
1960 | { | 1988 | { |
1961 | time_t tmp = (time_t) secsSince1Jan1970UTC; | 1989 | time_t tmp = (time_t) secsSince1Jan1970UTC; |
1962 | tm *brokenDown = 0; | 1990 | tm *brokenDown = 0; |
1991 | |||
1992 | #if defined(Q_OS_UNIX) && defined(QT_THREAD_SUPPORT) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) | ||
1993 | // posix compliant system | ||
1994 | // use the reentrant versions of localtime() and gmtime() where available | ||
1995 | tm res; | ||
1996 | if ( ts == Qt::LocalTime ) | ||
1997 | brokenDown = localtime_r( &tmp, &res ); | ||
1998 | if ( !brokenDown ) { | ||
1999 | brokenDown = gmtime_r( &tmp, &res ); | ||
2000 | if ( !brokenDown ) { | ||
2001 | d.jd = QDate::gregorianToJulian( 1970, 1, 1 ); | ||
2002 | t.ds = 0; | ||
2003 | return; | ||
2004 | } | ||
2005 | } | ||
2006 | #else | ||
1963 | if ( ts == Qt::LocalTime ) | 2007 | if ( ts == Qt::LocalTime ) |
1964 | brokenDown = localtime( &tmp ); | 2008 | brokenDown = localtime( &tmp ); |
1965 | if ( !brokenDown ) { | 2009 | if ( !brokenDown ) { |
1966 | brokenDown = gmtime( &tmp ); | 2010 | brokenDown = gmtime( &tmp ); |
1967 | if ( !brokenDown ) { | 2011 | if ( !brokenDown ) { |
1968 | d.jd = QDate::gregorianToJulian( 1970, 1, 1 ); | 2012 | d.jd = QDate::gregorianToJulian( 1970, 1, 1 ); |
1969 | t.ds = 0; | 2013 | t.ds = 0; |
1970 | return; | 2014 | return; |
1971 | } | 2015 | } |
1972 | } | 2016 | } |
2017 | #endif | ||
2018 | |||
1973 | d.jd = QDate::gregorianToJulian( brokenDown->tm_year + 1900, | 2019 | d.jd = QDate::gregorianToJulian( brokenDown->tm_year + 1900, |
1974 | brokenDown->tm_mon + 1, | 2020 | brokenDown->tm_mon + 1, |
1975 | brokenDown->tm_mday ); | 2021 | brokenDown->tm_mday ); |
1976 | t.ds = MSECS_PER_HOUR * brokenDown->tm_hour + | 2022 | t.ds = MSECS_PER_HOUR * brokenDown->tm_hour + |
1977 | MSECS_PER_MIN * brokenDown->tm_min + | 2023 | MSECS_PER_MIN * brokenDown->tm_min + |
1978 | 1000 * brokenDown->tm_sec; | 2024 | 1000 * brokenDown->tm_sec; |
1979 | } | 2025 | } |
1980 | #ifndef QT_NO_DATESTRING | 2026 | #ifndef QT_NO_DATESTRING |
1981 | #ifndef QT_NO_SPRINTF | 2027 | #ifndef QT_NO_SPRINTF |
1982 | /*! | 2028 | /*! |
1983 | \overload | 2029 | \overload |
1984 | 2030 | ||
1985 | Returns the datetime as a string. The \a f parameter determines | 2031 | Returns the datetime as a string. The \a f parameter determines |
1986 | the format of the string. | 2032 | the format of the string. |
1987 | 2033 | ||
1988 | If \a f is \c Qt::TextDate, the string format is "Wed May 20 | 2034 | If \a f is \c Qt::TextDate, the string format is "Wed May 20 |
1989 | 03:40:13 1998" (using QDate::shortDayName(), QDate::shortMonthName(), | 2035 | 03:40:13 1998" (using QDate::shortDayName(), QDate::shortMonthName(), |
1990 | and QTime::toString() to generate the string, so the day and month | 2036 | and QTime::toString() to generate the string, so the day and month |
1991 | names will have localized names). | 2037 | names will have localized names). |
1992 | 2038 | ||
1993 | If \a f is \c Qt::ISODate, the string format corresponds to the | 2039 | If \a f is \c Qt::ISODate, the string format corresponds to the |
1994 | ISO 8601 extended specification for representations of dates and | 2040 | ISO 8601 extended specification for representations of dates and |
1995 | times, which is YYYY-MM-DDTHH:MM:SS. | 2041 | times, which is YYYY-MM-DDTHH:MM:SS. |
1996 | 2042 | ||
1997 | If \a f is \c Qt::LocalDate, the string format depends on the | 2043 | If \a f is \c Qt::LocalDate, the string format depends on the |
1998 | locale settings of the system. | 2044 | locale settings of the system. |
1999 | 2045 | ||
2000 | If the format \a f is invalid, toString() returns a null string. | 2046 | If the format \a f is invalid, toString() returns a null string. |
2001 | 2047 | ||
2002 | \sa QDate::toString() QTime::toString() | 2048 | \sa QDate::toString() QTime::toString() |
2003 | */ | 2049 | */ |
2004 | 2050 | ||
2005 | QString QDateTime::toString( Qt::DateFormat f ) const | 2051 | QString QDateTime::toString( Qt::DateFormat f ) const |
2006 | { | 2052 | { |
2007 | if ( f == Qt::ISODate ) { | 2053 | if ( f == Qt::ISODate ) { |
2008 | return d.toString( Qt::ISODate ) + "T" + t.toString( Qt::ISODate ); | 2054 | return d.toString( Qt::ISODate ) + "T" + t.toString( Qt::ISODate ); |
2009 | } | 2055 | } |
2010 | #ifndef QT_NO_TEXTDATE | 2056 | #ifndef QT_NO_TEXTDATE |
2011 | else if ( f == Qt::TextDate ) { | 2057 | else if ( f == Qt::TextDate ) { |
2012 | #ifndef Q_WS_WIN | 2058 | #ifndef Q_WS_WIN |
2013 | QString buf = d.shortDayName( d.dayOfWeek() ); | 2059 | QString buf = d.shortDayName( d.dayOfWeek() ); |
2014 | buf += ' '; | 2060 | buf += ' '; |
2015 | buf += d.shortMonthName( d.month() ); | 2061 | buf += d.shortMonthName( d.month() ); |
2016 | buf += ' '; | 2062 | buf += ' '; |
2017 | buf += QString().setNum( d.day() ); | 2063 | buf += QString().setNum( d.day() ); |
2018 | buf += ' '; | 2064 | buf += ' '; |
2019 | #else | 2065 | #else |
2020 | QString buf; | 2066 | QString buf; |
@@ -2255,97 +2301,97 @@ bool QDateTime::operator!=( const QDateTime &dt ) const | |||
2255 | returns FALSE. | 2301 | returns FALSE. |
2256 | */ | 2302 | */ |
2257 | 2303 | ||
2258 | bool QDateTime::operator<( const QDateTime &dt ) const | 2304 | bool QDateTime::operator<( const QDateTime &dt ) const |
2259 | { | 2305 | { |
2260 | if ( d < dt.d ) | 2306 | if ( d < dt.d ) |
2261 | return TRUE; | 2307 | return TRUE; |
2262 | return d == dt.d ? t < dt.t : FALSE; | 2308 | return d == dt.d ? t < dt.t : FALSE; |
2263 | } | 2309 | } |
2264 | 2310 | ||
2265 | /*! | 2311 | /*! |
2266 | Returns TRUE if this datetime is earlier than or equal to \a dt; | 2312 | Returns TRUE if this datetime is earlier than or equal to \a dt; |
2267 | otherwise returns FALSE. | 2313 | otherwise returns FALSE. |
2268 | */ | 2314 | */ |
2269 | 2315 | ||
2270 | bool QDateTime::operator<=( const QDateTime &dt ) const | 2316 | bool QDateTime::operator<=( const QDateTime &dt ) const |
2271 | { | 2317 | { |
2272 | if ( d < dt.d ) | 2318 | if ( d < dt.d ) |
2273 | return TRUE; | 2319 | return TRUE; |
2274 | return d == dt.d ? t <= dt.t : FALSE; | 2320 | return d == dt.d ? t <= dt.t : FALSE; |
2275 | } | 2321 | } |
2276 | 2322 | ||
2277 | /*! | 2323 | /*! |
2278 | Returns TRUE if this datetime is later than \a dt; otherwise | 2324 | Returns TRUE if this datetime is later than \a dt; otherwise |
2279 | returns FALSE. | 2325 | returns FALSE. |
2280 | */ | 2326 | */ |
2281 | 2327 | ||
2282 | bool QDateTime::operator>( const QDateTime &dt ) const | 2328 | bool QDateTime::operator>( const QDateTime &dt ) const |
2283 | { | 2329 | { |
2284 | if ( d > dt.d ) | 2330 | if ( d > dt.d ) |
2285 | return TRUE; | 2331 | return TRUE; |
2286 | return d == dt.d ? t > dt.t : FALSE; | 2332 | return d == dt.d ? t > dt.t : FALSE; |
2287 | } | 2333 | } |
2288 | 2334 | ||
2289 | /*! | 2335 | /*! |
2290 | Returns TRUE if this datetime is later than or equal to \a dt; | 2336 | Returns TRUE if this datetime is later than or equal to \a dt; |
2291 | otherwise returns FALSE. | 2337 | otherwise returns FALSE. |
2292 | */ | 2338 | */ |
2293 | 2339 | ||
2294 | bool QDateTime::operator>=( const QDateTime &dt ) const | 2340 | bool QDateTime::operator>=( const QDateTime &dt ) const |
2295 | { | 2341 | { |
2296 | if ( d > dt.d ) | 2342 | if ( d > dt.d ) |
2297 | return TRUE; | 2343 | return TRUE; |
2298 | return d == dt.d ? t >= dt.t : FALSE; | 2344 | return d == dt.d ? t >= dt.t : FALSE; |
2299 | } | 2345 | } |
2300 | 2346 | ||
2301 | /*! | 2347 | /*! |
2302 | \overload | 2348 | \overload |
2303 | 2349 | ||
2304 | Returns the current datetime, as reported by the system clock. | 2350 | Returns the current datetime, as reported by the system clock. |
2305 | 2351 | ||
2306 | \sa QDate::currentDate(), QTime::currentTime() | 2352 | \sa QDate::currentDate(), QTime::currentTime() |
2307 | */ | 2353 | */ |
2308 | 2354 | ||
2309 | QDateTime QDateTime::currentDateTime() | 2355 | QDateTime QDateTime::currentDateTime() |
2310 | { | 2356 | { |
2311 | return currentDateTime( Qt::LocalTime ); | 2357 | return currentDateTime( Qt::LocalTime ); |
2312 | } | 2358 | } |
2313 | 2359 | ||
2314 | /*! | 2360 | /*! |
2315 | Returns the current datetime, as reported by the system clock, for the | 2361 | Returns the current datetime, as reported by the system clock, for the |
2316 | TimeSpec \a ts. The default TimeSpec is LocalTime. | 2362 | TimeSpec \a ts. The default TimeSpec is LocalTime. |
2317 | 2363 | ||
2318 | \sa QDate::currentDate(), QTime::currentTime(), Qt::TimeSpec | 2364 | \sa QDate::currentDate(), QTime::currentTime(), Qt::TimeSpec |
2319 | */ | 2365 | */ |
2320 | 2366 | ||
2321 | QDateTime QDateTime::currentDateTime( Qt::TimeSpec ts ) | 2367 | QDateTime QDateTime::currentDateTime( Qt::TimeSpec ts ) |
2322 | { | 2368 | { |
2323 | QDateTime dt; | 2369 | QDateTime dt; |
2324 | QTime t; | 2370 | QTime t; |
2325 | dt.setDate( QDate::currentDate(ts) ); | 2371 | dt.setDate( QDate::currentDate(ts) ); |
2326 | if ( QTime::currentTime(&t, ts) ) // midnight or right after? | 2372 | if ( QTime::currentTime(&t, ts) ) // midnight or right after? |
2327 | dt.setDate( QDate::currentDate(ts) ); // fetch date again | 2373 | dt.setDate( QDate::currentDate(ts) ); // fetch date again |
2328 | dt.setTime( t ); | 2374 | dt.setTime( t ); |
2329 | return dt; | 2375 | return dt; |
2330 | } | 2376 | } |
2331 | 2377 | ||
2332 | #ifndef QT_NO_DATESTRING | 2378 | #ifndef QT_NO_DATESTRING |
2333 | /*! | 2379 | /*! |
2334 | Returns the QDateTime represented by the string \a s, using the | 2380 | Returns the QDateTime represented by the string \a s, using the |
2335 | format \a f, or an invalid datetime if this is not possible. | 2381 | format \a f, or an invalid datetime if this is not possible. |
2336 | 2382 | ||
2337 | Note for \c Qt::TextDate: It is recommended that you use the | 2383 | Note for \c Qt::TextDate: It is recommended that you use the |
2338 | English short month names (e.g. "Jan"). Although localized month | 2384 | English short month names (e.g. "Jan"). Although localized month |
2339 | names can also be used, they depend on the user's locale settings. | 2385 | names can also be used, they depend on the user's locale settings. |
2340 | 2386 | ||
2341 | \warning Note that \c Qt::LocalDate cannot be used here. | 2387 | \warning Note that \c Qt::LocalDate cannot be used here. |
2342 | */ | 2388 | */ |
2343 | QDateTime QDateTime::fromString( const QString& s, Qt::DateFormat f ) | 2389 | QDateTime QDateTime::fromString( const QString& s, Qt::DateFormat f ) |
2344 | { | 2390 | { |
2345 | if ( ( s.isEmpty() ) || ( f == Qt::LocalDate ) ) { | 2391 | if ( ( s.isEmpty() ) || ( f == Qt::LocalDate ) ) { |
2346 | #if defined(QT_CHECK_RANGE) | 2392 | #if defined(QT_CHECK_RANGE) |
2347 | qWarning( "QDateTime::fromString: Parameter out of range" ); | 2393 | qWarning( "QDateTime::fromString: Parameter out of range" ); |
2348 | #endif | 2394 | #endif |
2349 | return QDateTime(); | 2395 | return QDateTime(); |
2350 | } | 2396 | } |
2351 | if ( f == Qt::ISODate ) { | 2397 | if ( f == Qt::ISODate ) { |