#include "qplatformdefs.h"
#include "private/qdatetime_p.h"
#include "qdatastream.h"
#include "qset.h"
#include "qlocale.h"
#include "qdatetime.h"
#include "qregexp.h"
#include "qdebug.h"
#include <locale.h>
#include <time.h>
Include dependency graph for qdatetime.cpp:

Go to the source code of this file.
Defines | |
| #define | QDTPDEBUG if (false) qDebug() |
| #define | QDTPDEBUGN if (false) qDebug |
Enumerations | |
| enum | |
Functions | |
| static QDate | strictDate (int y, int m, int d) |
| static QDate | fixedDate (int y, int m, int d) |
| static uint | julianDayFromDate (int year, int month, int day) |
| static void | getDateFromJulianDay (uint julianDay, int *year, int *month, int *day) |
| static QString | fmtDateTime (const QString &f, const QTime *dt=0, const QDate *dd=0) |
| static uint | toTime_t (const QDate &utcDate, const QTime &utcTime) |
| static bool | hasUnquotedAP (const QString &f) |
| static QString | getFmtString (const QString &f, const QTime *dt=0, const QDate *dd=0, bool am_pm=false) |
| static QDateTimePrivate::Spec | utcToLocal (QDate &date, QTime &time) |
| static void | localToUtc (QDate &date, QTime &time, int isdst) |
| QDebug | operator<< (QDebug dbg, const QDate &date) |
| QDebug | operator<< (QDebug dbg, const QTime &time) |
| QDebug | operator<< (QDebug dbg, const QDateTime &date) |
| static QString | unquote (const QString &str) |
| static int | countRepeat (const QString &str, int index) |
| bool | operator== (const QDateTimeParser::SectionNode &s1, const QDateTimeParser::SectionNode &s2) |
Variables | |
| static const char | monthDays [] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 } |
| static const char *const | qt_shortMonthNames [] |
| static const int | LowerYear = 1970 |
| #define QDTPDEBUG if (false) qDebug() |
Definition at line 47 of file qdatetime.cpp.
Referenced by QDateTimeParser::checkIntermediate(), QDateTimeParser::findAmPm(), QDateTimeParser::findMonth(), QDateTimeParser::parse(), QDateTimeParser::parseFormat(), QDateTimeParser::parseSection(), QDateTimeParser::potentialValueHelper(), and QDateTimeParser::sectionPos().
| #define QDTPDEBUGN if (false) qDebug |
Definition at line 48 of file qdatetime.cpp.
Referenced by QDateTimeParser::parse(), QDateTimeParser::parseFormat(), and QDateTimeParser::parseSection().
| anonymous enum |
Definition at line 56 of file qdatetime.cpp.
00056 { 00057 FIRST_YEAR = -4713, 00058 FIRST_MONTH = 1, 00059 FIRST_DAY = 2, // ### Qt 5: make FIRST_DAY = 1, by support jd == 0 as valid 00060 SECS_PER_DAY = 86400, 00061 MSECS_PER_DAY = 86400000, 00062 SECS_PER_HOUR = 3600, 00063 MSECS_PER_HOUR = 3600000, 00064 SECS_PER_MIN = 60, 00065 MSECS_PER_MIN = 60000 00066 };
| static int countRepeat | ( | const QString & | str, | |
| int | index | |||
| ) | [static] |
Definition at line 3486 of file qdatetime.cpp.
References QString::at(), and QString::size().
Referenced by QDateTimeParser::parseFormat().
03487 { 03488 Q_ASSERT(index >= 0 && index < str.size()); 03489 int count = 1; 03490 const QChar ch = str.at(index); 03491 while (index + count < str.size() && str.at(index + count) == ch) 03492 ++count; 03493 return count; 03494 }
Here is the call graph for this function:

| static QDate fixedDate | ( | int | y, | |
| int | m, | |||
| int | d | |||
| ) | [inline, static] |
Definition at line 75 of file qdatetime.cpp.
References QDate::daysInMonth(), qMin(), QDate::setDate(), and strictDate().
Referenced by QDate::addMonths(), QDate::addYears(), and QDateTimeParser::setDigit().
00076 { 00077 QDate result(strictDate(y, m, 1)); 00078 result.setDate(y, m, qMin(d, result.daysInMonth())); 00079 return result; 00080 }
Here is the call graph for this function:

| static QString fmtDateTime | ( | const QString & | f, | |
| const QTime * | dt = 0, |
|||
| const QDate * | dd = 0 | |||
| ) | [static] |
Definition at line 3058 of file qdatetime.cpp.
References QString::at(), buf, QString::clear(), getFmtString(), hasUnquotedAP(), i, int, QString::isEmpty(), QTime::isValid(), QDate::isValid(), and QString::length().
Referenced by QDateTime::toString(), QDate::toString(), and QTime::toString().
03059 { 03060 const QLatin1Char quote('\''); 03061 if (f.isEmpty()) 03062 return QString(); 03063 if (dt && !dt->isValid()) 03064 return QString(); 03065 if (dd && !dd->isValid()) 03066 return QString(); 03067 03068 const bool ap = hasUnquotedAP(f); 03069 03070 QString buf; 03071 QString frm; 03072 QChar status = QLatin1Char('0'); 03073 03074 for (int i = 0; i < (int)f.length(); ++i) { 03075 if (f.at(i) == quote) { 03076 if (status == quote) { 03077 status = QLatin1Char('0'); 03078 } else { 03079 if (!frm.isEmpty()) { 03080 buf += getFmtString(frm, dt, dd, ap); 03081 frm.clear(); 03082 } 03083 status = quote; 03084 } 03085 } else if (status == quote) { 03086 buf += f.at(i); 03087 } else if (f.at(i) == status) { 03088 if ((ap) && ((f.at(i) == QLatin1Char('P')) || (f.at(i) == QLatin1Char('p')))) 03089 status = QLatin1Char('0'); 03090 frm += f.at(i); 03091 } else { 03092 buf += getFmtString(frm, dt, dd, ap); 03093 frm.clear(); 03094 if ((f.at(i) == QLatin1Char('h')) || (f.at(i) == QLatin1Char('m')) 03095 || (f.at(i) == QLatin1Char('H')) 03096 || (f.at(i) == QLatin1Char('s')) || (f.at(i) == QLatin1Char('z'))) { 03097 status = f.at(i); 03098 frm += f.at(i); 03099 } else if ((f.at(i) == QLatin1Char('d')) || (f.at(i) == QLatin1Char('M')) || (f.at(i) == QLatin1Char('y'))) { 03100 status = f.at(i); 03101 frm += f.at(i); 03102 } else if ((ap) && (f.at(i) == QLatin1Char('A'))) { 03103 status = QLatin1Char('P'); 03104 frm += f.at(i); 03105 } else if((ap) && (f.at(i) == QLatin1Char('a'))) { 03106 status = QLatin1Char('p'); 03107 frm += f.at(i); 03108 } else { 03109 buf += f.at(i); 03110 status = QLatin1Char('0'); 03111 } 03112 } 03113 } 03114 03115 buf += getFmtString(frm, dt, dd, ap); 03116 03117 return buf; 03118 }
Here is the call graph for this function:

| static void getDateFromJulianDay | ( | uint | julianDay, | |
| int * | year, | |||
| int * | month, | |||
| int * | day | |||
| ) | [static] |
Definition at line 107 of file qdatetime.cpp.
References d, i, j, m, n, and y.
Referenced by QDate::addMonths(), QDate::addYears(), QDate::day(), QDate::daysInMonth(), QDate::daysInYear(), QDate::julianToGregorian(), QDate::month(), QDate::toString(), and QDate::year().
00108 { 00109 int y, m, d; 00110 00111 if (julianDay >= 2299161) { 00112 // Gregorian calendar starting from October 15, 1582 00113 // This algorithm is from Henry F. Fliegel and Thomas C. Van Flandern 00114 qulonglong ell, n, i, j; 00115 ell = qulonglong(julianDay) + 68569; 00116 n = (4 * ell) / 146097; 00117 ell = ell - (146097 * n + 3) / 4; 00118 i = (4000 * (ell + 1)) / 1461001; 00119 ell = ell - (1461 * i) / 4 + 31; 00120 j = (80 * ell) / 2447; 00121 d = ell - (2447 * j) / 80; 00122 ell = j / 11; 00123 m = j + 2 - (12 * ell); 00124 y = 100 * (n - 49) + i + ell; 00125 } else { 00126 // Julian calendar until October 4, 1582 00127 // Algorithm from Frequently Asked Questions about Calendars by Claus Toendering 00128 julianDay += 32082; 00129 int dd = (4 * julianDay + 3) / 1461; 00130 int ee = julianDay - (1461 * dd) / 4; 00131 int mm = ((5 * ee) + 2) / 153; 00132 d = ee - (153 * mm + 2) / 5 + 1; 00133 m = mm + 3 - 12 * (mm / 10); 00134 y = dd - 4800 + (mm / 10); 00135 if (y <= 0) 00136 --y; 00137 } 00138 *year = y; 00139 *month = m; 00140 *day = d; 00141 }
| static QString getFmtString | ( | const QString & | f, | |
| const QTime * | dt = 0, |
|||
| const QDate * | dd = 0, |
|||
| bool | am_pm = false | |||
| ) | [static] |
Definition at line 2959 of file qdatetime.cpp.
References QString::at(), buf, QString::isEmpty(), QChar::isUpper(), QString::mid(), QString::number(), QTextStream::right(), QString::size(), QString::startsWith(), QChar::toUpper(), and QUnicodeTables::upper().
Referenced by fmtDateTime().
02960 { 02961 if (f.isEmpty()) 02962 return QString(); 02963 02964 QString buf = f; 02965 int removed = 0; 02966 02967 if (dt) { 02968 if (f.startsWith(QLatin1String("hh")) || f.startsWith(QLatin1String("HH"))) { 02969 const bool hour12 = f.at(0) == QLatin1Char('h') && am_pm; 02970 if (hour12 && dt->hour() > 12) 02971 buf = QString::number(dt->hour() - 12).rightJustified(2, QLatin1Char('0'), true); 02972 else if (hour12 && dt->hour() == 0) 02973 buf = QLatin1String("12"); 02974 else 02975 buf = QString::number(dt->hour()).rightJustified(2, QLatin1Char('0'), true); 02976 removed = 2; 02977 } else if (f.at(0) == QLatin1Char('h') || f.at(0) == QLatin1Char('H')) { 02978 const bool hour12 = f.at(0) == QLatin1Char('h') && am_pm; 02979 if (hour12 && dt->hour() > 12) 02980 buf = QString::number(dt->hour() - 12); 02981 else if (hour12 && dt->hour() == 0) 02982 buf = QLatin1String("12"); 02983 else 02984 buf = QString::number(dt->hour()); 02985 removed = 1; 02986 } else if (f.startsWith(QLatin1String("mm"))) { 02987 buf = QString::number(dt->minute()).rightJustified(2, QLatin1Char('0'), true); 02988 removed = 2; 02989 } else if (f.at(0) == (QLatin1Char('m'))) { 02990 buf = QString::number(dt->minute()); 02991 removed = 1; 02992 } else if (f.startsWith(QLatin1String("ss"))) { 02993 buf = QString::number(dt->second()).rightJustified(2, QLatin1Char('0'), true); 02994 removed = 2; 02995 } else if (f.at(0) == QLatin1Char('s')) { 02996 buf = QString::number(dt->second()); 02997 } else if (f.startsWith(QLatin1String("zzz"))) { 02998 buf = QString::number(dt->msec()).rightJustified(3, QLatin1Char('0'), true); 02999 removed = 3; 03000 } else if (f.at(0) == QLatin1Char('z')) { 03001 buf = QString::number(dt->msec()); 03002 removed = 1; 03003 } else if (f.at(0).toUpper() == QLatin1Char('A')) { 03004 const bool upper = f.at(0) == QLatin1Char('A'); 03005 buf = dt->hour() < 12 ? QLatin1String("am") : QLatin1String("pm"); 03006 if (upper) 03007 buf = buf.toUpper(); 03008 if (f.size() > 1 && f.at(1).toUpper() == QLatin1Char('P') && 03009 f.at(0).isUpper() == f.at(1).isUpper()) { 03010 removed = 2; 03011 } else { 03012 removed = 1; 03013 } 03014 } 03015 } 03016 03017 if (dd) { 03018 if (f.startsWith(QLatin1String("dddd"))) { 03019 buf = dd->longDayName(dd->dayOfWeek()); 03020 removed = 4; 03021 } else if (f.startsWith(QLatin1String("ddd"))) { 03022 buf = dd->shortDayName(dd->dayOfWeek()); 03023 removed = 3; 03024 } else if (f.startsWith(QLatin1String("dd"))) { 03025 buf = QString::number(dd->day()).rightJustified(2, QLatin1Char('0'), true); 03026 removed = 2; 03027 } else if (f.at(0) == QLatin1Char('d')) { 03028 buf = QString::number(dd->day()); 03029 removed = 1; 03030 } else if (f.startsWith(QLatin1String("MMMM"))) { 03031 buf = dd->longMonthName(dd->month()); 03032 removed = 4; 03033 } else if (f.startsWith(QLatin1String("MMM"))) { 03034 buf = dd->shortMonthName(dd->month()); 03035 removed = 3; 03036 } else if (f.startsWith(QLatin1String("MM"))) { 03037 buf = QString::number(dd->month()).rightJustified(2, QLatin1Char('0'), true); 03038 removed = 2; 03039 } else if (f.at(0) == QLatin1Char('M')) { 03040 buf = QString::number(dd->month()); 03041 removed = 1; 03042 } else if (f.startsWith(QLatin1String("yyyy"))) { 03043 buf = QString::number(dd->year()); 03044 removed = 4; 03045 } else if (f.startsWith(QLatin1String("yy"))) { 03046 buf = QString::number(dd->year()).right(2); 03047 removed = 2; 03048 } 03049 } 03050 if (removed == 0 || removed >= f.size()) { 03051 return buf; 03052 } 03053 03054 return buf + getFmtString(f.mid(removed), dt, dd, am_pm); 03055 }
Here is the call graph for this function:

| static bool hasUnquotedAP | ( | const QString & | f | ) | [static] |
Definition at line 2939 of file qdatetime.cpp.
References QString::at(), i, QString::size(), and QChar::toUpper().
Referenced by fmtDateTime(), and QDateTimeParser::parseFormat().
02940 { 02941 const QLatin1Char quote('\''); 02942 bool inquote = false; 02943 for (int i=0; i < f.size(); ++i) { 02944 if (f.at(i) == quote) { 02945 inquote = !inquote; 02946 } else if (!inquote && f.at(i).toUpper() == QLatin1Char('A')) { 02947 return true; 02948 } 02949 } 02950 return false; 02951 }
Here is the call graph for this function:

| static uint julianDayFromDate | ( | int | year, | |
| int | month, | |||
| int | day | |||
| ) | [static] |
Definition at line 82 of file qdatetime.cpp.
References a.
Referenced by QDate::currentDate(), QDateTime::currentDateTime(), QDate::dayOfYear(), QDate::gregorianToJulian(), and QDate::setDate().
00083 { 00084 if (year < 0) 00085 ++year; 00086 00087 if (year > 1582 || (year == 1582 && (month > 10 || (month == 10 && day >= 15)))) { 00088 // Gregorian calendar starting from October 15, 1582 00089 // Algorithm from Henry F. Fliegel and Thomas C. Van Flandern 00090 return (1461 * (year + 4800 + (month - 14) / 12)) / 4 00091 + (367 * (month - 2 - 12 * ((month - 14) / 12))) / 12 00092 - (3 * ((year + 4900 + (month - 14) / 12) / 100)) / 4 00093 + day - 32075; 00094 } else if (year < 1582 || (year == 1582 && (month < 10 || (month == 10 && day <= 4)))) { 00095 // Julian calendar until October 4, 1582 00096 // Algorithm from Frequently Asked Questions about Calendars by Claus Toendering 00097 int a = (14 - month) / 12; 00098 return (153 * (month + (12 * a) - 3) + 2) / 5 00099 + (1461 * (year + 4800 - a)) / 4 00100 + day - 32083; 00101 } else { 00102 // the day following October 4, 1582 is October 15, 1582 00103 return 0; 00104 } 00105 }
Definition at line 3172 of file qdatetime.cpp.
References QDate::day(), QDate::daysTo(), QTime::hour(), int, QDate::isValid(), LowerYear, QTime::minute(), QDate::month(), QTime::msec(), QTime::second(), and QDate::year().
Referenced by QDateTimePrivate::getUTC().
03173 { 03174 if (!date.isValid()) 03175 return; 03176 03177 QDate lowerLimit(LowerYear, 1, 2); 03178 QDate upperLimit(2037, 12, 30); 03179 03180 QDate fakeDate = date; 03181 03182 if (fakeDate < lowerLimit) { 03183 fakeDate = lowerLimit; 03184 isdst = false; 03185 } else if (fakeDate > upperLimit) { 03186 fakeDate = upperLimit; 03187 isdst = false; 03188 } 03189 03190 tm localTM; 03191 localTM.tm_sec = time.second(); 03192 localTM.tm_min = time.minute(); 03193 localTM.tm_hour = time.hour(); 03194 localTM.tm_mday = fakeDate.day(); 03195 localTM.tm_mon = fakeDate.month() - 1; 03196 localTM.tm_year = fakeDate.year() - 1900; 03197 localTM.tm_isdst = (int)isdst; 03198 03199 time_t secsSince1Jan1970UTC = mktime(&localTM); 03200 tm *brokenDown = 0; 03201 03202 #if !defined(QT_NO_THREAD) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) 03203 // use the reentrant version of gmtime() where available 03204 tm res; 03205 brokenDown = gmtime_r(&secsSince1Jan1970UTC, &res); 03206 #elif defined(_MSC_VER) && _MSC_VER >= 1400 03207 tm res; 03208 if (!_gmtime64_s(&res, &secsSince1Jan1970UTC)) 03209 brokenDown = &res; 03210 #else 03211 brokenDown = gmtime(&secsSince1Jan1970UTC); 03212 #endif // !QT_NO_THREAD && _POSIX_THREAD_SAFE_FUNCTIONS 03213 if (!brokenDown) { 03214 date = QDate(1970, 1, 1); 03215 time = QTime(); 03216 } else { 03217 int deltaDays = fakeDate.daysTo(date); 03218 date = QDate(brokenDown->tm_year + 1900, brokenDown->tm_mon + 1, brokenDown->tm_mday); 03219 time = QTime(brokenDown->tm_hour, brokenDown->tm_min, brokenDown->tm_sec, time.msec()); 03220 date = date.addDays(deltaDays); 03221 } 03222 }
Here is the call graph for this function:

Definition at line 3254 of file qdatetime.cpp.
03255 { 03256 dbg.nospace() << "QDateTime(" << date.toString() << ")"; 03257 return dbg.space(); 03258 }
Definition at line 3248 of file qdatetime.cpp.
03249 { 03250 dbg.nospace() << "QTime(" << time.toString() << ")"; 03251 return dbg.space(); 03252 }
Definition at line 3242 of file qdatetime.cpp.
03243 { 03244 dbg.nospace() << "QDate(" << date.toString() << ")"; 03245 return dbg.space(); 03246 }
| bool operator== | ( | const QDateTimeParser::SectionNode & | s1, | |
| const QDateTimeParser::SectionNode & | s2 | |||
| ) |
| static QDate strictDate | ( | int | y, | |
| int | m, | |||
| int | d | |||
| ) | [inline, static] |
Definition at line 68 of file qdatetime.cpp.
References QDate::setDate().
Referenced by fixedDate(), QDate::fromString(), QDateTime::fromString(), and QDateTimeParser::parse().
Here is the call graph for this function:

Definition at line 2019 of file qdatetime.cpp.
References Q_INT64_C, and SECS_PER_DAY.
Referenced by ConnectionManager::clientId(), QUuid::createUuid(), QDateTime::toTime_t(), utcToLocal(), writeAdaptor(), and writeProxy().
02020 { 02021 int days = QDate(1970, 1, 1).daysTo(utcDate); 02022 int secs = QTime().secsTo(utcTime); 02023 if (days < 0 || (days == 0 && secs < 0)) 02024 return uint(-1); 02025 02026 qlonglong retval = (qlonglong(days) * SECS_PER_DAY) + secs; 02027 if (retval >= Q_INT64_C(0xFFFFFFFF)) 02028 return uint(-1); 02029 return uint(retval); 02030 }
Definition at line 3456 of file qdatetime.cpp.
References QString::at(), i, QString::isEmpty(), and QString::size().
Referenced by QDateTimeParser::parseFormat(), split_arg_list(), and ProFileEvaluator::visitProValue().
03457 { 03458 const QLatin1Char quote('\''); 03459 const QLatin1Char slash('\\'); 03460 const QLatin1Char zero('0'); 03461 QString ret; 03462 QChar status = zero; 03463 for (int i=0; i<str.size(); ++i) { 03464 if (str.at(i) == quote) { 03465 if (status != quote) { 03466 status = quote; 03467 } else if (!ret.isEmpty() && str.at(i - 1) == slash) { 03468 ret[ret.size() - 1] = quote; 03469 } else { 03470 status = zero; 03471 } 03472 } else { 03473 ret += str.at(i); 03474 } 03475 } 03476 return ret; 03477 }
Here is the call graph for this function:

| static QDateTimePrivate::Spec utcToLocal | ( | QDate & | date, | |
| QTime & | time | |||
| ) | [static] |
Definition at line 3127 of file qdatetime.cpp.
References QDate::daysTo(), QDateTimePrivate::LocalDST, QDateTimePrivate::LocalStandard, QDateTimePrivate::LocalUnknown, LowerYear, QTime::msec(), and toTime_t().
Referenced by QDateTimePrivate::getLocal().
03128 { 03129 QDate lowerLimit(LowerYear, 1, 2); 03130 QDate upperLimit(2037, 12, 30); 03131 03132 QDate fakeDate = date; 03133 03134 if (fakeDate < lowerLimit) { 03135 fakeDate = lowerLimit; 03136 } else if (fakeDate > upperLimit) { 03137 fakeDate = upperLimit; 03138 } 03139 03140 time_t secsSince1Jan1970UTC = toTime_t(fakeDate, time); 03141 tm *brokenDown = 0; 03142 03143 #if !defined(QT_NO_THREAD) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) 03144 // use the reentrant version of localtime() where available 03145 tm res; 03146 brokenDown = localtime_r(&secsSince1Jan1970UTC, &res); 03147 #elif defined(_MSC_VER) && _MSC_VER >= 1400 03148 tm res; 03149 if (!_localtime64_s(&res, &secsSince1Jan1970UTC)) 03150 brokenDown = &res; 03151 #else 03152 brokenDown = localtime(&secsSince1Jan1970UTC); 03153 #endif 03154 if (!brokenDown) { 03155 date = QDate(1970, 1, 1); 03156 time = QTime(); 03157 return QDateTimePrivate::LocalUnknown; 03158 } else { 03159 int deltaDays = fakeDate.daysTo(date); 03160 date = QDate(brokenDown->tm_year + 1900, brokenDown->tm_mon + 1, brokenDown->tm_mday); 03161 time = QTime(brokenDown->tm_hour, brokenDown->tm_min, brokenDown->tm_sec, time.msec()); 03162 date = date.addDays(deltaDays); 03163 if (brokenDown->tm_isdst > 0) 03164 return QDateTimePrivate::LocalDST; 03165 else if (brokenDown->tm_isdst < 0) 03166 return QDateTimePrivate::LocalUnknown; 03167 else 03168 return QDateTimePrivate::LocalStandard; 03169 } 03170 }
Here is the call graph for this function:

const int LowerYear = 1970 [static] |
const char monthDays[] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 } [static] |
Definition at line 144 of file qdatetime.cpp.
Referenced by QDate::daysInMonth(), and QDate::isValid().
const char* const qt_shortMonthNames[] [static] |
Initial value:
{
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }
Definition at line 147 of file qdatetime.cpp.
Referenced by QDateTimeParser::findMonth(), QDate::fromString(), and QDateTime::fromString().
1.5.1