#include <qdatetime.h>
A QDate object contains a calendar date, i.e. year, month, and day numbers, in the Gregorian calendar (Julian calendar for dates before 15 October 1582). It can read the current date from the system clock. It provides functions for comparing dates, and for manipulating dates. For example, it is possible to add and subtract days, months, and years to dates.
A QDate object is typically created either by giving the year, month, and day numbers explicitly, or by using the static function currentDate() that creates a QDate object containing the system clock's date. An explicit date can also be set using setDate(). The fromString() function returns a QDate given a string and a date format which is used to interpret the date within the string.
The year(), month(), and day() functions provide access to the year, month, and day numbers. Also, dayOfWeek() and dayOfYear() functions are provided. The same information is provided in textual format by the toString(), shortDayName(), longDayName(), shortMonthName(), and longMonthName() functions.
QDate provides a full set of operators to compare two QDate objects where smaller means earlier, and larger means later.
You can increment (or decrement) a date by a given number of days using addDays(). Similarly you can use addMonths() and addYears(). The daysTo() function returns the number of days between two dates.
The daysInMonth() and daysInYear() functions return how many days there are in this date's month and year, respectively. The isLeapYear() function indicates whether this date is in a leap year.
Note that the Gregorian calendar was introduced at different dates in different countries and regions. QDate uses the Gregorian calendar starting from 15 October 1582, and uses the Julian calendar for dates up to 4 October 1582.
Definition at line 34 of file qdatetime.h.
Public Member Functions | |
| QDate () | |
| QDate (int y, int m, int d) | |
| bool | isNull () const |
| bool | isValid () const |
| int | year () const |
| int | month () const |
| int | day () const |
| int | dayOfWeek () const |
| int | dayOfYear () const |
| int | daysInMonth () const |
| int | daysInYear () const |
| int | weekNumber (int *yearNum=0) const |
| QString | toString (Qt::DateFormat f=Qt::TextDate) const |
| QString | toString (const QString &format) const |
| bool | setYMD (int y, int m, int d) |
| bool | setDate (int year, int month, int date) |
| QDate | addDays (int days) const |
| QDate | addMonths (int months) const |
| QDate | addYears (int years) const |
| int | daysTo (const QDate &) const |
| bool | operator== (const QDate &other) const |
| bool | operator!= (const QDate &other) const |
| bool | operator< (const QDate &other) const |
| bool | operator<= (const QDate &other) const |
| bool | operator> (const QDate &other) const |
| bool | operator>= (const QDate &other) const |
| int | toJulianDay () const |
Static Public Member Functions | |
| static QString | shortMonthName (int month) |
| static QString | shortDayName (int weekday) |
| static QString | longMonthName (int month) |
| static QString | longDayName (int weekday) |
| static QDate | currentDate () |
| static QDate | fromString (const QString &s, Qt::DateFormat f=Qt::TextDate) |
| static QDate | fromString (const QString &s, const QString &format) |
| static bool | isValid (int y, int m, int d) |
| static bool | isLeapYear (int year) |
| static uint | gregorianToJulian (int y, int m, int d) |
| static void | julianToGregorian (uint jd, int &y, int &m, int &d) |
| static QDate | fromJulianDay (int jd) |
Private Attributes | |
| uint | jd |
Friends | |
| class | QDateTime |
| class | QDateTimePrivate |
| Q_CORE_EXPORT QDataStream & | operator<< (QDataStream &, const QDate &) |
| Q_CORE_EXPORT QDataStream & | operator>> (QDataStream &, QDate &) |
| QDate::QDate | ( | ) | [inline] |
Constructs a null date. Null dates are invalid.
Definition at line 37 of file qdatetime.h.
Referenced by fromString().
00037 { jd = 0; }
| QDate::QDate | ( | int | y, | |
| int | m, | |||
| int | d | |||
| ) |
Constructs a date with year y, month m and day d.
If the specified date is invalid, the date is not set and isValid() returns false. Any date before 2 January 4713 B.C. is considered invalid.
Definition at line 230 of file qdatetime.cpp.
Here is the call graph for this function:

| bool QDate::isNull | ( | ) | const [inline] |
Returns true if the date is null; otherwise returns false. A null date is invalid.
Definition at line 40 of file qdatetime.h.
Referenced by QDateTime::isNull(), and isValid().
00040 { return jd == 0; }
| bool QDate::isValid | ( | ) | const |
Returns true if this date is valid; otherwise returns false.
Definition at line 254 of file qdatetime.cpp.
References isNull().
Referenced by QCalendarModel::cellForDate(), QCalendarModel::data(), Q3DateEdit::date(), QCalendarModel::dateForCell(), MySortFilterProxyModel::dateInRange(), QDateTimeEditPrivate::emitSignals(), Q3DateEdit::event(), QCalendarModel::flags(), fmtDateTime(), QSqlDriver::formatValue(), QIBaseDriver::formatValue(), QCalendarView::handleMouseEvent(), QDateTime::isValid(), localToUtc(), QCalendarView::mouseMoveEvent(), QCalendarView::mousePressEvent(), QCalendarView::mouseReleaseEvent(), operator<<(), Q3DateEdit::outOfRange(), QCalendarDelegate::paint(), QDateTimeParser::parse(), QDateTime::QDateTime(), QDateTimeEdit::QDateTimeEdit(), Q3DateEdit::setDate(), QDateTime::setDate(), setDate(), QDateTimeEdit::setDate(), QCalendarWidget::setDateRange(), QDateTimeEdit::setDateRange(), Q3DateEdit::setDay(), QCalendarWidget::setMaximumDate(), QDateTimeEdit::setMaximumDate(), QDateTimeEdit::setMinimumDate(), QCalendarWidget::setMinimumDate(), VariantDelegate::setModelData(), Q3DateEdit::setRange(), QCalendarWidget::setSelectedDate(), QTest::toString(), toString(), QCalendarWidgetPrivate::updateCurrentPage(), and weekNumber().
00255 { 00256 return !isNull(); 00257 }
Here is the call graph for this function:

| int QDate::year | ( | ) | const |
Returns the year of this date. Zero and negative numbers indicate years before 1 A.D. = 1 C.E., such that year 0 is 1 B.C.E., -1 is 2 B.C.E. and so forth.
Definition at line 268 of file qdatetime.cpp.
References d, getDateFromJulianDay(), jd, m, and y.
Referenced by QCalendarWidgetPrivate::_q_slotChangeDate(), QCalendarModel::cellForDate(), QCalendarWidgetPrivate::createHeader(), QAbstractFormBuilder::createProperty(), QCalendarModel::dateForCell(), dayOfYear(), QODBCResult::exec(), Q3DateEdit::fix(), QIBaseDriver::formatValue(), fromString(), MainWindow::insertCalendar(), localToUtc(), QCalendarView::moveCursor(), operator<<(), QDateTimeParser::parse(), QDateTimeParser::potentialValue(), QCalendarModel::QCalendarModel(), Q3DateEdit::setDate(), QCalendarWidget::setDateRange(), QDateTimeParser::setDigit(), QCalendarWidget::setMaximumDate(), QCalendarWidget::setMinimumDate(), MainWindow::setMonth(), QCalendarWidget::setSelectedDate(), MainWindow::setYear(), QCalendarWidget::showSelectedDate(), QCalendarWidget::showToday(), QLocale::toString(), QDateTime::toString(), toString(), QCalendarWidgetPrivate::updateMonthMenu(), and weekNumber().
00269 { 00270 int y, m, d; 00271 getDateFromJulianDay(jd, &y, &m, &d); 00272 return y; 00273 }
Here is the call graph for this function:

| int QDate::month | ( | ) | const |
Returns the number corresponding to the month of this date, using the following convention:
1 = "January" 2 = "February" 3 = "March" 4 = "April" 5 = "May" 6 = "June" 7 = "July" 8 = "August" 9 = "September" 10 = "October" 11 = "November" 12 = "December"
Definition at line 297 of file qdatetime.cpp.
References d, getDateFromJulianDay(), jd, m, and y.
Referenced by QCalendarWidgetPrivate::_q_monthChanged(), QCalendarWidgetPrivate::_q_slotChangeDate(), QCalendarWidgetPrivate::_q_yearEditingFinished(), QCalendarModel::cellForDate(), QDateTimeParser::checkIntermediate(), QCalendarWidgetPrivate::createHeader(), QAbstractFormBuilder::createProperty(), QCalendarModel::dateForCell(), QODBCResult::exec(), Q3DateEdit::fix(), QCalendarModel::formatForCell(), QIBaseDriver::formatValue(), fromString(), MainWindow::insertCalendar(), localToUtc(), QCalendarView::moveCursor(), operator<<(), QDateTimeParser::parse(), QCalendarModel::QCalendarModel(), Q3DateEdit::setDate(), QCalendarWidget::setDateRange(), QDateTimeParser::setDigit(), QCalendarWidget::setMaximumDate(), QCalendarWidget::setMinimumDate(), QCalendarWidget::setSelectedDate(), MainWindow::setYear(), QCalendarWidget::showSelectedDate(), QCalendarWidget::showToday(), QDateTime::toString(), QLocale::toString(), toString(), and QCalendarWidgetPrivate::updateMonthMenu().
00298 { 00299 int y, m, d; 00300 getDateFromJulianDay(jd, &y, &m, &d); 00301 return m; 00302 }
Here is the call graph for this function:

| int QDate::day | ( | ) | const |
Returns the day of the month (1 to 31) of this date.
Definition at line 310 of file qdatetime.cpp.
References d, getDateFromJulianDay(), jd, m, and y.
Referenced by QCalendarWidgetPrivate::_q_yearEditingFinished(), QCalendarModel::cellForDate(), QAbstractFormBuilder::createProperty(), QCalendarModel::data(), QODBCResult::exec(), Q3DateEdit::fix(), QIBaseDriver::formatValue(), fromString(), localToUtc(), operator<<(), QDateTimeParser::parse(), Q3DateEdit::setDate(), QDateTimeParser::setDigit(), MainWindow::setMonth(), MainWindow::setYear(), QDateTimeEditPrivate::stepBy(), QLocale::toString(), QDateTime::toString(), and toString().
00311 { 00312 int y, m, d; 00313 getDateFromJulianDay(jd, &y, &m, &d); 00314 return d; 00315 }
Here is the call graph for this function:

| int QDate::dayOfWeek | ( | ) | const |
Returns the weekday (1 to 7) for this date.
Definition at line 323 of file qdatetime.cpp.
References jd.
Referenced by QCalendarModel::cellForDate(), QCalendarModel::dateForCell(), QDateTimeParser::parse(), QDateTime::toString(), QLocale::toString(), toString(), and weekNumber().
00324 { 00325 return (jd % 7) + 1; 00326 }
| int QDate::dayOfYear | ( | ) | const |
Returns the day of the year (1 to 365) for this date.
Definition at line 334 of file qdatetime.cpp.
References jd, julianDayFromDate(), and year().
Referenced by weekNumber().
00335 { 00336 return jd - julianDayFromDate(year(), 1, 1) + 1; 00337 }
Here is the call graph for this function:

| int QDate::daysInMonth | ( | ) | const |
Returns the number of days in the month (28 to 31) for this date.
Definition at line 345 of file qdatetime.cpp.
References d, getDateFromJulianDay(), isLeapYear(), jd, m, monthDays, and y.
Referenced by QCalendarModel::cellForDate(), QCalendarModel::dateForCell(), fixedDate(), QCalendarView::moveCursor(), QDateTimeParser::parse(), and QDateTimeEditPrivate::stepBy().
00346 { 00347 int y, m, d; 00348 getDateFromJulianDay(jd, &y, &m, &d); 00349 if (m == 2 && isLeapYear(y)) 00350 return 29; 00351 else 00352 return monthDays[m]; 00353 }
Here is the call graph for this function:

| int QDate::daysInYear | ( | ) | const |
Returns the number of days in the year (365 or 366) for this date.
Definition at line 361 of file qdatetime.cpp.
References d, getDateFromJulianDay(), isLeapYear(), jd, m, and y.
00362 { 00363 int y, m, d; 00364 getDateFromJulianDay(jd, &y, &m, &d); 00365 return isLeapYear(y) ? 366 : 365; 00366 }
Here is the call graph for this function:

| int QDate::weekNumber | ( | int * | yearNumber = 0 |
) | const |
Returns the week number (1 to 53), and stores the year in {yearNumber} unless yearNumber is null (the default).
Returns 0 if the date is invalid.
In accordance with ISO 8601, weeks start on Qt::Monday and the first Qt::Thursday of a year is always in week 1 of that year. Most years have 52 weeks, but some have 53.
{yearNumber} is not always the same as year(). For example, 1 January 2000 has week number 52 in the year 1999, and 31 December 2002 has week number 1 in the year 2003.
Copyright (c) 1989 The Regents of the University of California. All rights reserved.
Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, advertising materials, and other materials related to such distribution and use acknowledge that the software was developed by the University of California, Berkeley. The name of the University may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
Definition at line 401 of file qdatetime.cpp.
References dayOfWeek(), dayOfYear(), isLeapYear(), isValid(), len, w, and year().
Referenced by QCalendarModel::data().
00402 { 00403 if (!isValid()) 00404 return 0; 00405 00406 int year = QDate::year(); 00407 int yday = dayOfYear() - 1; 00408 int wday = dayOfWeek(); 00409 if (wday == 7) 00410 wday = 0; 00411 int w; 00412 00413 for (;;) { 00414 int len; 00415 int bot; 00416 int top; 00417 00418 len = isLeapYear(year) ? 366 : 365; 00419 /* 00420 ** What yday (-3 ... 3) does 00421 ** the ISO year begin on? 00422 */ 00423 bot = ((yday + 11 - wday) % 7) - 3; 00424 /* 00425 ** What yday does the NEXT 00426 ** ISO year begin on? 00427 */ 00428 top = bot - (len % 7); 00429 if (top < -3) 00430 top += 7; 00431 top += len; 00432 if (yday >= top) { 00433 ++year; 00434 w = 1; 00435 break; 00436 } 00437 if (yday >= bot) { 00438 w = 1 + ((yday - bot) / 7); 00439 break; 00440 } 00441 --year; 00442 yday += isLeapYear(year) ? 366 : 365; 00443 } 00444 if (yearNumber != 0) 00445 *yearNumber = year; 00446 return w; 00447 }
Here is the call graph for this function:

| QString QDate::shortMonthName | ( | int | month | ) | [static] |
Returns the name of the month using the following convention:
1 = "Jan" 2 = "Feb" 3 = "Mar" 4 = "Apr" 5 = "May" 6 = "Jun" 7 = "Jul" 8 = "Aug" 9 = "Sep" 10 = "Oct" 11 = "Nov" 12 = "Dec"
The month names will be localized according to the system's locale settings.
Definition at line 475 of file qdatetime.cpp.
References QLocale::monthName(), qWarning(), QLocale::ShortFormat, and QLocale::system().
Referenced by QDateTimeParser::findMonth(), fromString(), QDateTime::fromString(), QDateTimeParser::sectionMaxSize(), QDateTime::toString(), and toString().
00476 { 00477 if (month < 1 || month > 12) { 00478 qWarning("QDate::shortMonthName: Parameter out ouf range"); 00479 month = 1; 00480 } 00481 return QLocale::system().monthName(month, QLocale::ShortFormat); 00482 }
Here is the call graph for this function:

| QString QDate::shortDayName | ( | int | weekday | ) | [static] |
Returns the name of the weekday using the following convention:
1 = "Mon" 2 = "Tue" 3 = "Wed" 4 = "Thu" 5 = "Fri" 6 = "Sat" 7 = "Sun"
The day names will be localized according to the system's locale settings.
Definition at line 538 of file qdatetime.cpp.
References QLocale::dayName(), qWarning(), QLocale::ShortFormat, and QLocale::system().
Referenced by QCalendarModel::dayName(), QDateTimeParser::findDay(), QDateTimeParser::sectionMaxSize(), QDateTime::toString(), and toString().
00539 { 00540 if (weekday < 1 || weekday > 7) { 00541 qWarning("QDate::shortDayName: Parameter out of range"); 00542 weekday = 1; 00543 } 00544 return QLocale::system().dayName(weekday, QLocale::ShortFormat); 00545 }
Here is the call graph for this function:

| QString QDate::longMonthName | ( | int | month | ) | [static] |
Returns the long name of the month using the following convention:
1 = "January" 2 = "February" 3 = "March" 4 = "April" 5 = "May" 6 = "June" 7 = "July" 8 = "August" 9 = "September" 10 = "October" 11 = "November" 12 = "December"
The month names will be localized according to the system's locale settings.
Definition at line 509 of file qdatetime.cpp.
References QLocale::LongFormat, QLocale::monthName(), qWarning(), and QLocale::system().
Referenced by QCalendarWidgetPrivate::createHeader(), QDateTimeParser::findMonth(), MainWindow::insertCalendar(), QCalendarWidget::minimumSizeHint(), QDateTimeParser::sectionMaxSize(), and QCalendarWidgetPrivate::updateHeader().
00510 { 00511 if (month < 1 || month > 12) { 00512 qWarning("QDate::longMonthName: Parameter out ouf range"); 00513 month = 1; 00514 } 00515 return QLocale::system().monthName(month, QLocale::LongFormat); 00516 }
Here is the call graph for this function:

| QString QDate::longDayName | ( | int | weekday | ) | [static] |
Returns the long name of the weekday using the following convention:
1 = "Monday" 2 = "Tuesday" 3 = "Wednesday" 4 = "Thursday" 5 = "Friday" 6 = "Saturday" 7 = "Sunday"
The day names will be localized according to the system's locale settings.
Definition at line 567 of file qdatetime.cpp.
References QLocale::dayName(), QLocale::LongFormat, qWarning(), and QLocale::system().
Referenced by QCalendarModel::dayName(), QDateTimeParser::findDay(), MainWindow::insertCalendar(), and QDateTimeParser::sectionMaxSize().
00568 { 00569 if (weekday < 1 || weekday > 7) { 00570 qWarning("QDate::longDayName: Parameter out of range"); 00571 weekday = 1; 00572 } 00573 return QLocale::system().dayName(weekday, QLocale::LongFormat); 00574 }
Here is the call graph for this function:

| QString QDate::toString | ( | Qt::DateFormat | format = Qt::TextDate |
) | const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Returns the date as a string. The format parameter determines the format of the string.
If the format is Qt::TextDate, the string is formatted in the default way. QDate::shortDayName() and QDate::shortMonthName() are used to generate the string, so the day and month names will be localized names. An example of this formatting is "Sat May 20 1995".
If the format is Qt::ISODate, the string format corresponds to the ISO 8601 extended specification for representations of dates and times, taking the form YYYY-MM-DD, where YYYY is the year, MM is the month of the year (between 01 and 12), and DD is the day of the month between 01 and 31.
If the format is Qt::LocalDate or Qt::SystemLocaleDate, the string format depends on the locale settings of the system. Identical to calling QLocale::system().toString(date, QLocale::ShortFormat). {Qt::LocalDate has been deprecated, please use Qt::SystemLocaleDate instead.}
If the format is Qt::LocaleDate, the string format depends on the default application locale. This is the locale set with QLocale::setDefault(), or the system locale if no default locale has been set. Identical to calling QLocale().toString(date, QLocale::ShortFormat);
If the datetime is invalid, an empty string will be returned.
Definition at line 619 of file qdatetime.cpp.
References QString::arg(), d, day(), dayOfWeek(), QString::fromLatin1(), getDateFromJulianDay(), Qt::ISODate, isValid(), jd, Qt::LocaleDate, m, month(), QString::number(), shortDayName(), QLocale::ShortFormat, shortMonthName(), QLocale::system(), Qt::SystemLocaleDate, Qt::TextDate, QLocale::toString(), y, and year().
Referenced by Window::createDateTimeEdits(), MainWindow::createLetter(), QSqlDriver::formatValue(), operator<<(), Window::setFormatString(), SpreadSheetDelegate::setModelData(), QDateTime::toString(), QTest::toString(), and qdesigner_internal::DateProperty::toString().
00620 { 00621 if (!isValid()) 00622 return QString(); 00623 int y, m, d; 00624 getDateFromJulianDay(jd, &y, &m, &d); 00625 switch (f) { 00626 case Qt::SystemLocaleDate: 00627 return QLocale::system().toString(*this, QLocale::ShortFormat); 00628 case Qt::LocaleDate: 00629 return QLocale().toString(*this, QLocale::ShortFormat); 00630 default: 00631 #ifndef QT_NO_TEXTDATE 00632 case Qt::TextDate: 00633 { 00634 return QString::fromLatin1("%0 %1 %2 %3") 00635 .arg(shortDayName(dayOfWeek())) 00636 .arg(shortMonthName(m)) 00637 .arg(d) 00638 .arg(y); 00639 } 00640 #endif 00641 case Qt::ISODate: 00642 { 00643 if (year() < 0 || year() > 9999) 00644 return QString(); 00645 QString month(QString::number(m).rightJustified(2, QLatin1Char('0'))); 00646 QString day(QString::number(d).rightJustified(2, QLatin1Char('0'))); 00647 return QString::number(y) + QLatin1Char('-') + month + QLatin1Char('-') + day; 00648 } 00649 } 00650 }
Here is the call graph for this function:

Returns the date as a string. The format parameter determines the format of the result string.
These expressions may be used:
Expression Output d the day as number without a leading zero (1 to31) dd the day as number with a leading zero (01 to 31) ddd the abbreviated localized day name (e.g. 'Mon' to 'Sun'). Uses QDate::shortDayName(). dddd the long localized day name (e.g. 'QtMonday' to 'QtSunday'). Uses QDate::longDayName(). M the month as number without a leading zero (1-12) MM the month as number with a leading zero (01-12) MMM the abbreviated localized month name (e.g. 'Jan' to 'Dec'). Uses QDate::shortMonthName(). MMMM the long localized month name (e.g. 'January' to 'December'). Uses QDate::longMonthName(). yy the year as two digit number (00 to 99) yyyy the year as four digit number
All other input characters will be ignored. Any sequence of characters that are enclosed in singlequotes will be treated as text and not be used as an expression.
Example format strings (assuming that the QDate is the 20 July 1969):
Format Result dd.MM.yyyy 20.07.1969 ddd MMMM d yy Sun July 20 69 'The day is' dddd The day is Sunday
If the datetime is invalid, an empty string will be returned.
Definition at line 702 of file qdatetime.cpp.
References fmtDateTime(), and year().
00703 { 00704 if (uint(year()) > 9999) 00705 return QString(); 00706 return fmtDateTime(format, 0, this); 00707 }
Here is the call graph for this function:

| bool QDate::setYMD | ( | int | y, | |
| int | m, | |||
| int | d | |||
| ) |
Sets the date's year y, month m, and day d.
If y is in the range 0 to 99, it is interpreted as 1900 to 1999.
Use setDate() instead.
Definition at line 721 of file qdatetime.cpp.
References setDate().
Referenced by operator>>().
Here is the call graph for this function:

| bool QDate::setDate | ( | int | year, | |
| int | month, | |||
| int | day | |||
| ) |
If the specified date is invalid, the QDate object is set to be invalid. Any date before 2 January 4713 B.C. is considered invalid.
Definition at line 740 of file qdatetime.cpp.
References isValid(), jd, and julianDayFromDate().
Referenced by fixedDate(), QDate(), setYMD(), and strictDate().
00741 { 00742 if (!isValid(year, month, day)) { 00743 jd = 0; 00744 } else { 00745 jd = julianDayFromDate(year, month, day); 00746 } 00747 return jd != 0; 00748 }
Here is the call graph for this function:

| QDate QDate::addDays | ( | int | ndays | ) | const |
Returns a QDate object containing a date ndays later than the date of this object (or earlier if ndays is negative).
Definition at line 757 of file qdatetime.cpp.
Referenced by QDateTime::addDays(), fromDate(), fromTimeStamp(), QCalendarView::moveCursor(), and QDateTime::setTime_t().
| QDate QDate::addMonths | ( | int | nmonths | ) | const |
Returns a QDate object containing a date nmonths later than the date of this object (or earlier if nmonths is negative).
Definition at line 771 of file qdatetime.cpp.
References d, fixedDate(), getDateFromJulianDay(), jd, m, and y.
Referenced by QCalendarWidgetPrivate::_q_monthChanged(), QCalendarWidgetPrivate::_q_nextMonthClicked(), QCalendarWidgetPrivate::_q_prevMonthClicked(), QDateTime::addMonths(), QCalendarModel::cellForDate(), QCalendarModel::dateForCell(), and QCalendarView::moveCursor().
00772 { 00773 int y, m, d; 00774 getDateFromJulianDay(jd, &y, &m, &d); 00775 00776 while (nmonths != 0) { 00777 if (nmonths < 0 && nmonths + 12 <= 0) { 00778 y--; 00779 nmonths+=12; 00780 } else if (nmonths < 0) { 00781 m+= nmonths; 00782 nmonths = 0; 00783 if (m <= 0) { 00784 --y; 00785 m += 12; 00786 } 00787 } else if (nmonths - 12 >= 0) { 00788 y++; 00789 nmonths -= 12; 00790 } else if (m == 12) { 00791 y++; 00792 m = 0; 00793 } else { 00794 m += nmonths; 00795 nmonths = 0; 00796 if (m > 12) { 00797 ++y; 00798 m -= 12; 00799 } 00800 } 00801 } 00802 00803 return fixedDate(y, m, d); 00804 }
Here is the call graph for this function:

| QDate QDate::addYears | ( | int | nyears | ) | const |
Returns a QDate object containing a date nyears later than the date of this object (or earlier if nyears is negative).
Definition at line 813 of file qdatetime.cpp.
References d, fixedDate(), getDateFromJulianDay(), jd, m, and y.
Referenced by QDateTime::addYears().
00814 { 00815 int y, m, d; 00816 getDateFromJulianDay(jd, &y, &m, &d); 00817 y += nyears; 00818 return fixedDate(y, m, d); 00819 }
Here is the call graph for this function:

| int QDate::daysTo | ( | const QDate & | d | ) | const |
Returns the number of days from this date to d (which is negative if d is earlier than this date).
Example:
QDate d1(1995, 5, 17); // May 17, 1995 QDate d2(1995, 5, 20); // May 20, 1995 d1.daysTo(d2); // returns 3 d2.daysTo(d1); // returns -3
Definition at line 836 of file qdatetime.cpp.
Referenced by QDateTime::daysTo(), localToUtc(), QDateTime::secsTo(), toDate(), toTimeStamp(), QCalendarWidgetPrivate::updateCurrentPage(), and utcToLocal().
| bool QDate::operator== | ( | const QDate & | d | ) | const [inline] |
Returns true if this date is equal to d; otherwise returns false.
Definition at line 74 of file qdatetime.h.
References jd.
00074 { return jd == other.jd; }
| bool QDate::operator!= | ( | const QDate & | d | ) | const [inline] |
Returns true if this date is different from d; otherwise returns false.
Definition at line 75 of file qdatetime.h.
References jd.
00075 { return jd != other.jd; }
| bool QDate::operator< | ( | const QDate & | d | ) | const [inline] |
Returns true if this date is earlier than d; otherwise returns false.
Definition at line 76 of file qdatetime.h.
References jd.
00076 { return jd < other.jd; }
| bool QDate::operator<= | ( | const QDate & | d | ) | const [inline] |
Returns true if this date is earlier than or equal to d; otherwise returns false.
Definition at line 77 of file qdatetime.h.
References jd.
00077 { return jd <= other.jd; }
| bool QDate::operator> | ( | const QDate & | d | ) | const [inline] |
Returns true if this date is later than d; otherwise returns false.
Definition at line 78 of file qdatetime.h.
References jd.
00078 { return jd > other.jd; }
| bool QDate::operator>= | ( | const QDate & | d | ) | const [inline] |
Returns true if this date is later than or equal to d; otherwise returns false.
Definition at line 79 of file qdatetime.h.
References jd.
00079 { return jd >= other.jd; }
| QDate QDate::currentDate | ( | ) | [static] |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Returns the current date, as reported by the system clock.
Definition at line 891 of file qdatetime.cpp.
References d, julianDayFromDate(), and t.
Referenced by Window::createDateTimeEdits(), MainWindow::createLetter(), QDateTime::currentDateTime(), Q3DateEdit::fix(), MainWindow::insertCalendar(), MainWindow::newLetter(), Q3FtpDTP::parseDir(), QFtpDTP::parseDir(), QCalendarModel::QCalendarModel(), QueryPage::QueryPage(), and QCalendarWidget::showToday().
00892 { 00893 QDate d; 00894 #if defined(Q_OS_WIN) 00895 SYSTEMTIME st; 00896 memset(&st, 0, sizeof(SYSTEMTIME)); 00897 GetLocalTime(&st); 00898 d.jd = julianDayFromDate(st.wYear, st.wMonth, st.wDay); 00899 #else 00900 // posix compliant system 00901 time_t ltime; 00902 time(<ime); 00903 tm *t; 00904 00905 #if !defined(QT_NO_THREAD) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) 00906 // use the reentrant version of localtime() where available 00907 tm res; 00908 t = localtime_r(<ime, &res); 00909 #else 00910 t = localtime(<ime); 00911 #endif // !QT_NO_THREAD && _POSIX_THREAD_SAFE_FUNCTIONS 00912 00913 d.jd = julianDayFromDate(t->tm_year + 1900, t->tm_mon + 1, t->tm_mday); 00914 #endif 00915 return d; 00916 }
Here is the call graph for this function:

| QDate QDate::fromString | ( | const QString & | string, | |
| Qt::DateFormat | format = Qt::TextDate | |||
| ) | [static] |
Returns the QDate represented by the string, using the format given, or an invalid date if the string cannot be parsed.
Note for Qt::TextDate: It is recommended that you use the English short month names (e.g. "Jan"). Although localized month names can also be used, they depend on the user's locale settings.
Definition at line 932 of file qdatetime.cpp.
References day(), i, Qt::ISODate, Qt::LocalDate, month(), QDate(), qt_shortMonthNames, s, shortMonthName(), strictDate(), Qt::TextDate, and year().
Referenced by convert(), QPSQLResult::data(), QDateTime::fromString(), Q3FtpDTP::parseDir(), QFtpDTP::parseDir(), qDateFromString(), SpreadSheetDelegate::setEditorData(), and VariantDelegate::setModelData().
00933 { 00934 if ((s.isEmpty()) || (f == Qt::LocalDate)) 00935 return QDate(); 00936 00937 switch (f) { 00938 case Qt::ISODate: 00939 { 00940 int year(s.mid(0, 4).toInt()); 00941 int month(s.mid(5, 2).toInt()); 00942 int day(s.mid(8, 2).toInt()); 00943 if (year && month && day) 00944 return strictDate(year, month, day); 00945 } 00946 break; 00947 default: 00948 #ifndef QT_NO_TEXTDATE 00949 case Qt::TextDate: 00950 { 00951 /* 00952 This will fail gracefully if the input string doesn't 00953 contain any space. 00954 */ 00955 int monthPos = s.indexOf(QLatin1Char(' ')) + 1; 00956 int dayPos = s.indexOf(QLatin1Char(' '), monthPos) + 1; 00957 int yearPos = s.indexOf(QLatin1Char(' '), dayPos) + 1; 00958 00959 QString monthName(s.mid(monthPos, dayPos - monthPos - 1)); 00960 int month = -1; 00961 00962 // try English names first 00963 for (int i = 0; i < 12; i++) { 00964 if (monthName == QLatin1String(qt_shortMonthNames[i])) { 00965 month = i + 1; 00966 break; 00967 } 00968 } 00969 00970 // try the localized names 00971 if (month == -1) { 00972 for (int i = 0; i < 12; i++) { 00973 if (monthName == shortMonthName(i + 1)) { 00974 month = i + 1; 00975 break; 00976 } 00977 } 00978 } 00979 if (month >= 1 && month <= 12) { 00980 int day = s.mid(dayPos, 2).trimmed().toInt(); 00981 int year = s.mid(yearPos).toInt(); 00982 return strictDate(year, month, day); 00983 } 00984 } 00985 #else 00986 break; 00987 #endif 00988 } 00989 return QDate(); 00990 }
Here is the call graph for this function:

Returns the QDate represented by the string, using the format given, or an invalid date if the string cannot be parsed.
These expressions may be used for the format:
Expression Output d The day as a number without a leading zero (1 to 31) dd The day as a number with a leading zero (01 to 31) ddd The abbreviated localized day name (e.g. 'Mon' to 'Sun'). Uses QDate::shortDayName(). dddd The long localized day name (e.g. 'Monday' to 'Sunday'). Uses QDate::longDayName(). M The month as a number without a leading zero (1 to 12) MM The month as a number with a leading zero (01 to 12) MMM The abbreviated localized month name (e.g. 'Jan' to 'Dec'). Uses QDate::shortMonthName(). MMMM The long localized month name (e.g. 'January' to 'December'). Uses QDate::longMonthName(). yy The year as two digit number (00 to 99) yyyy The year as four digit number
All other input characters will be treated as text. Any sequence of characters that are enclosed in single quotes will also be treated as text and will not be used as an expression. For example:
QDate date = QDate::fromString("1MM12car2003", "d'MM'MMcaryyyy"); // date is 1 December 2003
If the format is not satisfied, an invalid QDate is returned. The expressions that don't expect leading zeroes (d, M) will be greedy. This means that they will use two digits even if this will put them outside the accepted range of values and leaves too few digits for other sections. For example, the following format string could have meant January 30 but the M will grab two digits, resulting in an invalid date:
QDate date = QDate::fromString("130", "Md"); // invalid
For any field that is not represented in the format the following defaults are used:
Field Default value Year 1900 Month 1 Day 1
The following examples demonstrate the default values:
QDate::fromString("1.30", "M.d"); // January 30 1900 QDate::fromString("20000110", "yyyyMMdd"); // January 10, 2000 QDate::fromString("20000110", "yyyyMd"); // January 10, 2000
Definition at line 1065 of file qdatetime.cpp.
References QVariant::Date, QDateTimeParser::fromString(), and QDateTimeParser::parseFormat().
01066 { 01067 QDate date; 01068 #ifndef QT_BOOTSTRAPPED 01069 QDateTimeParser dt(QVariant::Date); 01070 if (dt.parseFormat(format)) 01071 dt.fromString(string, &date, 0); 01072 #else 01073 Q_UNUSED(string); 01074 Q_UNUSED(format); 01075 #endif 01076 return date; 01077 }
Here is the call graph for this function:

| bool QDate::isValid | ( | int | year, | |
| int | month, | |||
| int | day | |||
| ) | [static] |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Returns true if the specified date (year, month, and day) is valid; otherwise returns false.
Example:
QDate::isValid(2002, 5, 17); // true QDate::isValid(2002, 2, 30); // false (Feb 30 does not exist) QDate::isValid(2004, 2, 29); // true (2004 is a leap year) QDate::isValid(2000, 2, 29); // true (2000 is a leap year) QDate::isValid(2006, 2, 29); // false (2006 is not a leap year) QDate::isValid(2100, 2, 29); // false (2100 is not a leap year) QDate::isValid(1202, 6, 6); // true (even though 1202 is pre-Gregorian)
Definition at line 1100 of file qdatetime.cpp.
References FIRST_DAY, FIRST_MONTH, FIRST_YEAR, isLeapYear(), and monthDays.
01101 { 01102 if (year < FIRST_YEAR 01103 || (year == FIRST_YEAR && (month < FIRST_MONTH || month == FIRST_MONTH && day < FIRST_DAY)) 01104 || year == 0) // there is no year 0 in the Julian calendar 01105 return false; 01106 01107 // passage from Julian to Gregorian calendar 01108 if (year == 1582 && month == 10 && day > 4 && day < 15) 01109 return 0; 01110 01111 return (day > 0 && month > 0 && month <= 12) && 01112 (day <= monthDays[month] || (day == 29 && month == 2 && isLeapYear(year))); 01113 }
Here is the call graph for this function:

| bool QDate::isLeapYear | ( | int | year | ) | [static] |
Returns true if the specified year is a leap year; otherwise returns false.
Definition at line 1122 of file qdatetime.cpp.
Referenced by daysInMonth(), daysInYear(), isValid(), and weekNumber().
01123 { 01124 if (y < 1582) { 01125 return qAbs(y) % 4 == 0; 01126 } else { 01127 return y % 4 == 0 && y % 100 != 0 || y % 400 == 0; 01128 } 01129 }
| uint QDate::gregorianToJulian | ( | int | y, | |
| int | m, | |||
| int | d | |||
| ) | [static] |
Definition at line 1138 of file qdatetime.cpp.
References julianDayFromDate().
01139 { 01140 return julianDayFromDate(y, m, d); 01141 }
Here is the call graph for this function:

| void QDate::julianToGregorian | ( | uint | jd, | |
| int & | y, | |||
| int & | m, | |||
| int & | d | |||
| ) | [static] |
Definition at line 1150 of file qdatetime.cpp.
References getDateFromJulianDay().
01151 { 01152 getDateFromJulianDay(jd, &y, &m, &d); 01153 }
Here is the call graph for this function:

| static QDate QDate::fromJulianDay | ( | int | jd | ) | [inline, static] |
Converts the Julian day jd to a QDate.
Definition at line 100 of file qdatetime.h.
References d.
Referenced by QCalendarModel::QCalendarModel().
| int QDate::toJulianDay | ( | ) | const [inline] |
Converts the date to a Julian day.
Definition at line 101 of file qdatetime.h.
00101 { return jd; }
friend class QDateTime [friend] |
Definition at line 106 of file qdatetime.h.
friend class QDateTimePrivate [friend] |
Definition at line 107 of file qdatetime.h.
| QDataStream & operator<< | ( | QDataStream & | out, | |
| const QDate & | date | |||
| ) | [friend] |
Writes the date to stream out.
Definition at line 2782 of file qdatetime.cpp.
| QDataStream & operator>> | ( | QDataStream & | in, | |
| QDate & | date | |||
| ) | [friend] |
Reads a date from stream in into the date.
Definition at line 2795 of file qdatetime.cpp.
uint QDate::jd [private] |
Definition at line 104 of file qdatetime.h.
Referenced by addDays(), addMonths(), QDateTimePrivate::addMSecs(), addYears(), day(), dayOfWeek(), dayOfYear(), daysInMonth(), daysInYear(), daysTo(), month(), operator!=(), operator<(), operator<=(), operator==(), operator>(), operator>=(), setDate(), toString(), and year().
1.5.1