/src/corelib/tools/qdatetime.cpp
C++ | 5919 lines | 3271 code | 538 blank | 2110 comment | 918 complexity | 10ce232512263108c056c8ac91dca609 MD5 | raw file
Possible License(s): LGPL-2.0, LGPL-3.0, BSD-3-Clause, CC0-1.0, CC-BY-SA-4.0, LGPL-2.1, GPL-3.0, Apache-2.0
Large files files are truncated, but you can click here to view the full file
- /****************************************************************************
- **
- ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
- ** All rights reserved.
- ** Contact: Nokia Corporation (qt-info@nokia.com)
- **
- ** This file is part of the QtCore module of the Qt Toolkit.
- **
- ** $QT_BEGIN_LICENSE:LGPL$
- ** GNU Lesser General Public License Usage
- ** This file may be used under the terms of the GNU Lesser General Public
- ** License version 2.1 as published by the Free Software Foundation and
- ** appearing in the file LICENSE.LGPL included in the packaging of this
- ** file. Please review the following information to ensure the GNU Lesser
- ** General Public License version 2.1 requirements will be met:
- ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
- **
- ** In addition, as a special exception, Nokia gives you certain additional
- ** rights. These rights are described in the Nokia Qt LGPL Exception
- ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
- **
- ** GNU General Public License Usage
- ** Alternatively, this file may be used under the terms of the GNU General
- ** Public License version 3.0 as published by the Free Software Foundation
- ** and appearing in the file LICENSE.GPL included in the packaging of this
- ** file. Please review the following information to ensure the GNU General
- ** Public License version 3.0 requirements will be met:
- ** http://www.gnu.org/copyleft/gpl.html.
- **
- ** Other Usage
- ** Alternatively, this file may be used in accordance with the terms and
- ** conditions contained in a signed written agreement between you and Nokia.
- **
- **
- **
- **
- **
- ** $QT_END_LICENSE$
- **
- ****************************************************************************/
- #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"
- #if defined(Q_OS_WIN32) || defined(Q_OS_WINCE)
- #include <qt_windows.h>
- #endif
- #ifndef Q_WS_WIN
- #include <locale.h>
- #endif
- #include <time.h>
- #if defined(Q_OS_WINCE)
- #include "qfunctions_wince.h"
- #endif
- //#define QDATETIMEPARSER_DEBUG
- #if defined (QDATETIMEPARSER_DEBUG) && !defined(QT_NO_DEBUG_STREAM)
- # define QDTPDEBUG qDebug() << QString("%1:%2").arg(__FILE__).arg(__LINE__)
- # define QDTPDEBUGN qDebug
- #else
- # define QDTPDEBUG if (false) qDebug()
- # define QDTPDEBUGN if (false) qDebug
- #endif
- #if defined(Q_WS_MAC)
- #include <private/qcore_mac_p.h>
- #endif
- #if defined(Q_OS_SYMBIAN)
- #include <e32std.h>
- #include <tz.h>
- #endif
- QT_BEGIN_NAMESPACE
- enum {
- FIRST_YEAR = -4713,
- FIRST_MONTH = 1,
- FIRST_DAY = 2, // ### Qt 5: make FIRST_DAY = 1, by support jd == 0 as valid
- SECS_PER_DAY = 86400,
- MSECS_PER_DAY = 86400000,
- SECS_PER_HOUR = 3600,
- MSECS_PER_HOUR = 3600000,
- SECS_PER_MIN = 60,
- MSECS_PER_MIN = 60000,
- JULIAN_DAY_FOR_EPOCH = 2440588 // result of julianDayFromGregorianDate(1970, 1, 1)
- };
- static inline QDate fixedDate(int y, int m, int d)
- {
- QDate result(y, m, 1);
- result.setDate(y, m, qMin(d, result.daysInMonth()));
- return result;
- }
- static inline uint julianDayFromGregorianDate(int year, int month, int day)
- {
- // Gregorian calendar starting from October 15, 1582
- // Algorithm from Henry F. Fliegel and Thomas C. Van Flandern
- return (1461 * (year + 4800 + (month - 14) / 12)) / 4
- + (367 * (month - 2 - 12 * ((month - 14) / 12))) / 12
- - (3 * ((year + 4900 + (month - 14) / 12) / 100)) / 4
- + day - 32075;
- }
- static uint julianDayFromDate(int year, int month, int day)
- {
- if (year < 0)
- ++year;
- if (year > 1582 || (year == 1582 && (month > 10 || (month == 10 && day >= 15)))) {
- return julianDayFromGregorianDate(year, month, day);
- } else if (year < 1582 || (year == 1582 && (month < 10 || (month == 10 && day <= 4)))) {
- // Julian calendar until October 4, 1582
- // Algorithm from Frequently Asked Questions about Calendars by Claus Toendering
- int a = (14 - month) / 12;
- return (153 * (month + (12 * a) - 3) + 2) / 5
- + (1461 * (year + 4800 - a)) / 4
- + day - 32083;
- } else {
- // the day following October 4, 1582 is October 15, 1582
- return 0;
- }
- }
- static void getDateFromJulianDay(uint julianDay, int *year, int *month, int *day)
- {
- int y, m, d;
- if (julianDay >= 2299161) {
- // Gregorian calendar starting from October 15, 1582
- // This algorithm is from Henry F. Fliegel and Thomas C. Van Flandern
- qulonglong ell, n, i, j;
- ell = qulonglong(julianDay) + 68569;
- n = (4 * ell) / 146097;
- ell = ell - (146097 * n + 3) / 4;
- i = (4000 * (ell + 1)) / 1461001;
- ell = ell - (1461 * i) / 4 + 31;
- j = (80 * ell) / 2447;
- d = ell - (2447 * j) / 80;
- ell = j / 11;
- m = j + 2 - (12 * ell);
- y = 100 * (n - 49) + i + ell;
- } else {
- // Julian calendar until October 4, 1582
- // Algorithm from Frequently Asked Questions about Calendars by Claus Toendering
- julianDay += 32082;
- int dd = (4 * julianDay + 3) / 1461;
- int ee = julianDay - (1461 * dd) / 4;
- int mm = ((5 * ee) + 2) / 153;
- d = ee - (153 * mm + 2) / 5 + 1;
- m = mm + 3 - 12 * (mm / 10);
- y = dd - 4800 + (mm / 10);
- if (y <= 0)
- --y;
- }
- if (year)
- *year = y;
- if (month)
- *month = m;
- if (day)
- *day = d;
- }
- static const char monthDays[] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
- #ifndef QT_NO_TEXTDATE
- static const char * const qt_shortMonthNames[] = {
- "Jan", "Feb", "Mar", "Apr", "May", "Jun",
- "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
- #endif
- #ifndef QT_NO_DATESTRING
- static QString fmtDateTime(const QString& f, const QTime* dt = 0, const QDate* dd = 0);
- #endif
- /*****************************************************************************
- QDate member functions
- *****************************************************************************/
- /*!
- \since 4.5
- \enum QDate::MonthNameType
- This enum describes the types of the string representation used
- for the month name.
- \value DateFormat This type of name can be used for date-to-string formatting.
- \value StandaloneFormat This type is used when you need to enumerate months or weekdays.
- Usually standalone names are represented in singular forms with
- capitalized first letter.
- */
- /*!
- \class QDate
- \reentrant
- \brief The QDate class provides date functions.
- A QDate object contains a calendar date, i.e. year, month, and day
- numbers, in the Gregorian calendar. (see \l{QDate G and J} {Use of
- Gregorian and Julian Calendars} for dates prior to 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. Note that QDate interprets two
- digit years as is, i.e., years 0 - 99. A QDate can also be
- constructed with the static function currentDate(), which 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 a date is in a leap year.
- \section1
- \target QDate G and J
- \section2 Use of Gregorian and Julian Calendars
- QDate uses the Gregorian calendar in all locales, beginning
- on the date 15 October 1582. For dates up to and including 4
- October 1582, the Julian calendar is used. This means there is a
- 10-day gap in the internal calendar between the 4th and the 15th
- of October 1582. When you use QDateTime for dates in that epoch,
- the day after 4 October 1582 is 15 October 1582, and the dates in
- the gap are invalid.
- The Julian to Gregorian changeover date used here is the date when
- the Gregorian calendar was first introduced, by Pope Gregory
- XIII. That change was not universally accepted and some localities
- only executed it at a later date (if at all). QDateTime
- doesn't take any of these historical facts into account. If an
- application must support a locale-specific dating system, it must
- do so on its own, remembering to convert the dates using the
- Julian day.
- \section2 No Year 0
- There is no year 0. Dates in that year are considered invalid. The
- year -1 is the year "1 before Christ" or "1 before current era."
- The day before 0001-01-01 is December 31st, 1 BCE.
- \section2 Range of Valid Dates
- The range of valid dates is from January 2nd, 4713 BCE, to
- sometime in the year 11 million CE. The Julian Day returned by
- QDate::toJulianDay() is a number in the contiguous range from 1 to
- \e{overflow}, even across QDateTime's "date holes". It is suitable
- for use in applications that must convert a QDateTime to a date in
- another calendar system, e.g., Hebrew, Islamic or Chinese.
- \sa QTime, QDateTime, QDateEdit, QDateTimeEdit, QCalendarWidget
- */
- /*!
- \fn QDate::QDate()
- Constructs a null date. Null dates are invalid.
- \sa isNull(), isValid()
- */
- /*!
- Constructs a date with year \a y, month \a m and day \a d.
- If the specified date is invalid, the date is not set and
- isValid() returns false. A date before 2 January 4713 B.C. is
- considered invalid.
- \warning Years 0 to 99 are interpreted as is, i.e., years
- 0-99.
- \sa isValid()
- */
- QDate::QDate(int y, int m, int d)
- {
- setDate(y, m, d);
- }
- /*!
- \fn bool QDate::isNull() const
- Returns true if the date is null; otherwise returns false. A null
- date is invalid.
- \note The behavior of this function is equivalent to isValid().
- \sa isValid()
- */
- /*!
- Returns true if this date is valid; otherwise returns false.
- \sa isNull()
- */
- bool QDate::isValid() const
- {
- return !isNull();
- }
- /*!
- Returns the year of this date. Negative numbers indicate years
- before 1 A.D. = 1 C.E., such that year -44 is 44 B.C.
- \sa month(), day()
- */
- int QDate::year() const
- {
- int y;
- getDateFromJulianDay(jd, &y, 0, 0);
- return y;
- }
- /*!
- Returns the number corresponding to the month of this date, using
- the following convention:
- \list
- \i 1 = "January"
- \i 2 = "February"
- \i 3 = "March"
- \i 4 = "April"
- \i 5 = "May"
- \i 6 = "June"
- \i 7 = "July"
- \i 8 = "August"
- \i 9 = "September"
- \i 10 = "October"
- \i 11 = "November"
- \i 12 = "December"
- \endlist
- \sa year(), day()
- */
- int QDate::month() const
- {
- int m;
- getDateFromJulianDay(jd, 0, &m, 0);
- return m;
- }
- /*!
- Returns the day of the month (1 to 31) of this date.
- \sa year(), month(), dayOfWeek()
- */
- int QDate::day() const
- {
- int d;
- getDateFromJulianDay(jd, 0, 0, &d);
- return d;
- }
- /*!
- Returns the weekday (1 to 7) for this date.
- \sa day(), dayOfYear(), Qt::DayOfWeek
- */
- int QDate::dayOfWeek() const
- {
- return (jd % 7) + 1;
- }
- /*!
- Returns the day of the year (1 to 365 or 366 on leap years) for
- this date.
- \sa day(), dayOfWeek()
- */
- int QDate::dayOfYear() const
- {
- return jd - julianDayFromDate(year(), 1, 1) + 1;
- }
- /*!
- Returns the number of days in the month (28 to 31) for this date.
- \sa day(), daysInYear()
- */
- int QDate::daysInMonth() const
- {
- int y, m, d;
- getDateFromJulianDay(jd, &y, &m, &d);
- if (m == 2 && isLeapYear(y))
- return 29;
- else
- return monthDays[m];
- }
- /*!
- Returns the number of days in the year (365 or 366) for this date.
- \sa day(), daysInMonth()
- */
- int QDate::daysInYear() const
- {
- int y, m, d;
- getDateFromJulianDay(jd, &y, &m, &d);
- return isLeapYear(y) ? 366 : 365;
- }
- /*!
- Returns the week number (1 to 53), and stores the year in
- *\a{yearNumber} unless \a yearNumber is null (the default).
- Returns 0 if the date is invalid.
- In accordance with ISO 8601, weeks start on Monday and the first
- Thursday of a year is always in week 1 of that year. Most years
- have 52 weeks, but some have 53.
- *\a{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.
- \legalese
- 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.
- \sa isValid()
- */
- int QDate::weekNumber(int *yearNumber) const
- {
- if (!isValid())
- return 0;
- int year = QDate::year();
- int yday = dayOfYear() - 1;
- int wday = dayOfWeek();
- if (wday == 7)
- wday = 0;
- int w;
- for (;;) {
- int len;
- int bot;
- int top;
- len = isLeapYear(year) ? 366 : 365;
- /*
- ** What yday (-3 ... 3) does
- ** the ISO year begin on?
- */
- bot = ((yday + 11 - wday) % 7) - 3;
- /*
- ** What yday does the NEXT
- ** ISO year begin on?
- */
- top = bot - (len % 7);
- if (top < -3)
- top += 7;
- top += len;
- if (yday >= top) {
- ++year;
- w = 1;
- break;
- }
- if (yday >= bot) {
- w = 1 + ((yday - bot) / 7);
- break;
- }
- --year;
- yday += isLeapYear(year) ? 366 : 365;
- }
- if (yearNumber != 0)
- *yearNumber = year;
- return w;
- }
- #ifndef QT_NO_TEXTDATE
- /*!
- \since 4.5
- Returns the short name of the \a month for the representation specified
- by \a type.
- The months are enumerated using the following convention:
- \list
- \i 1 = "Jan"
- \i 2 = "Feb"
- \i 3 = "Mar"
- \i 4 = "Apr"
- \i 5 = "May"
- \i 6 = "Jun"
- \i 7 = "Jul"
- \i 8 = "Aug"
- \i 9 = "Sep"
- \i 10 = "Oct"
- \i 11 = "Nov"
- \i 12 = "Dec"
- \endlist
- The month names will be localized according to the system's locale
- settings.
- \sa toString(), longMonthName(), shortDayName(), longDayName()
- */
- QString QDate::shortMonthName(int month, QDate::MonthNameType type)
- {
- if (month < 1 || month > 12) {
- month = 1;
- }
- switch (type) {
- case QDate::DateFormat:
- return QLocale::system().monthName(month, QLocale::ShortFormat);
- case QDate::StandaloneFormat:
- return QLocale::system().standaloneMonthName(month, QLocale::ShortFormat);
- default:
- break;
- }
- return QString();
- }
- /*!
- Returns the short version of the name of the \a month. The
- returned name is in normal type which can be used for date formatting.
- \sa toString(), longMonthName(), shortDayName(), longDayName()
- */
- QString QDate::shortMonthName(int month)
- {
- return shortMonthName(month, QDate::DateFormat);
- }
- /*!
- \since 4.5
- Returns the long name of the \a month for the representation specified
- by \a type.
- The months are enumerated using the following convention:
- \list
- \i 1 = "January"
- \i 2 = "February"
- \i 3 = "March"
- \i 4 = "April"
- \i 5 = "May"
- \i 6 = "June"
- \i 7 = "July"
- \i 8 = "August"
- \i 9 = "September"
- \i 10 = "October"
- \i 11 = "November"
- \i 12 = "December"
- \endlist
- The month names will be localized according to the system's locale
- settings.
- \sa toString(), shortMonthName(), shortDayName(), longDayName()
- */
- QString QDate::longMonthName(int month, MonthNameType type)
- {
- if (month < 1 || month > 12) {
- month = 1;
- }
- switch (type) {
- case QDate::DateFormat:
- return QLocale::system().monthName(month, QLocale::LongFormat);
- case QDate::StandaloneFormat:
- return QLocale::system().standaloneMonthName(month, QLocale::LongFormat);
- default:
- break;
- }
- return QString();
- }
- /*!
- Returns the long version of the name of the \a month. The
- returned name is in normal type which can be used for date formatting.
- \sa toString(), shortMonthName(), shortDayName(), longDayName()
- */
- QString QDate::longMonthName(int month)
- {
- if (month < 1 || month > 12) {
- month = 1;
- }
- return QLocale::system().monthName(month, QLocale::LongFormat);
- }
- /*!
- \since 4.5
- Returns the short name of the \a weekday for the representation specified
- by \a type.
- The days are enumerated using the following convention:
- \list
- \i 1 = "Mon"
- \i 2 = "Tue"
- \i 3 = "Wed"
- \i 4 = "Thu"
- \i 5 = "Fri"
- \i 6 = "Sat"
- \i 7 = "Sun"
- \endlist
- The day names will be localized according to the system's locale
- settings.
- \sa toString(), shortMonthName(), longMonthName(), longDayName()
- */
- QString QDate::shortDayName(int weekday, MonthNameType type)
- {
- if (weekday < 1 || weekday > 7) {
- weekday = 1;
- }
- switch (type) {
- case QDate::DateFormat:
- return QLocale::system().dayName(weekday, QLocale::ShortFormat);
- case QDate::StandaloneFormat:
- return QLocale::system().standaloneDayName(weekday, QLocale::ShortFormat);
- default:
- break;
- }
- return QString();
- }
- /*!
- Returns the short version of the name of the \a weekday. The
- returned name is in normal type which can be used for date formatting.
- \sa toString(), longDayName(), shortMonthName(), longMonthName()
- */
- QString QDate::shortDayName(int weekday)
- {
- if (weekday < 1 || weekday > 7) {
- weekday = 1;
- }
- return QLocale::system().dayName(weekday, QLocale::ShortFormat);
- }
- /*!
- \since 4.5
- Returns the long name of the \a weekday for the representation specified
- by \a type.
- The days are enumerated using the following convention:
- \list
- \i 1 = "Monday"
- \i 2 = "Tuesday"
- \i 3 = "Wednesday"
- \i 4 = "Thursday"
- \i 5 = "Friday"
- \i 6 = "Saturday"
- \i 7 = "Sunday"
- \endlist
- The day names will be localized according to the system's locale
- settings.
- \sa toString(), shortDayName(), shortMonthName(), longMonthName()
- */
- QString QDate::longDayName(int weekday, MonthNameType type)
- {
- if (weekday < 1 || weekday > 7) {
- weekday = 1;
- }
- switch (type) {
- case QDate::DateFormat:
- return QLocale::system().dayName(weekday, QLocale::LongFormat);
- case QDate::StandaloneFormat:
- return QLocale::system().standaloneDayName(weekday, QLocale::LongFormat);
- default:
- break;
- }
- return QLocale::system().dayName(weekday, QLocale::LongFormat);
- }
- /*!
- Returns the long version of the name of the \a weekday. The
- returned name is in normal type which can be used for date formatting.
- \sa toString(), shortDayName(), shortMonthName(), longMonthName()
- */
- QString QDate::longDayName(int weekday)
- {
- if (weekday < 1 || weekday > 7) {
- weekday = 1;
- }
- return QLocale::system().dayName(weekday, QLocale::LongFormat);
- }
- #endif //QT_NO_TEXTDATE
- #ifndef QT_NO_DATESTRING
- /*!
- \fn QString QDate::toString(Qt::DateFormat format) const
- \overload
- Returns the date as a string. The \a format parameter determines
- the format of the string.
- If the \a 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 \a 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 \a format is Qt::SystemLocaleShortDate or
- Qt::SystemLocaleLongDate, the string format depends on the locale
- settings of the system. Identical to calling
- QLocale::system().toString(date, QLocale::ShortFormat) or
- QLocale::system().toString(date, QLocale::LongFormat).
- If the \a format is Qt::DefaultLocaleShortDate or
- Qt::DefaultLocaleLongDate, 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) or QLocale().toString(date,
- QLocale::LongFormat).
- If the date is invalid, an empty string will be returned.
- \warning The Qt::ISODate format is only valid for years in the
- range 0 to 9999. This restriction may apply to locale-aware
- formats as well, depending on the locale settings.
- \sa shortDayName(), shortMonthName()
- */
- QString QDate::toString(Qt::DateFormat f) const
- {
- if (!isValid())
- return QString();
- int y, m, d;
- getDateFromJulianDay(jd, &y, &m, &d);
- switch (f) {
- case Qt::SystemLocaleDate:
- case Qt::SystemLocaleShortDate:
- case Qt::SystemLocaleLongDate:
- return QLocale::system().toString(*this, f == Qt::SystemLocaleLongDate ? QLocale::LongFormat
- : QLocale::ShortFormat);
- case Qt::LocaleDate:
- case Qt::DefaultLocaleShortDate:
- case Qt::DefaultLocaleLongDate:
- return QLocale().toString(*this, f == Qt::DefaultLocaleLongDate ? QLocale::LongFormat
- : QLocale::ShortFormat);
- default:
- #ifndef QT_NO_TEXTDATE
- case Qt::TextDate:
- {
- return QString::fromLatin1("%0 %1 %2 %3")
- .arg(shortDayName(dayOfWeek()))
- .arg(shortMonthName(m))
- .arg(d)
- .arg(y);
- }
- #endif
- case Qt::ISODate:
- {
- if (year() < 0 || year() > 9999)
- return QString();
- QString month(QString::number(m).rightJustified(2, QLatin1Char('0')));
- QString day(QString::number(d).rightJustified(2, QLatin1Char('0')));
- return QString::number(y) + QLatin1Char('-') + month + QLatin1Char('-') + day;
- }
- }
- }
- /*!
- Returns the date as a string. The \a format parameter determines
- the format of the result string.
- These expressions may be used:
- \table
- \header \i Expression \i Output
- \row \i d \i the day as number without a leading zero (1 to 31)
- \row \i dd \i the day as number with a leading zero (01 to 31)
- \row \i ddd
- \i the abbreviated localized day name (e.g. 'Mon' to 'Sun').
- Uses QDate::shortDayName().
- \row \i dddd
- \i the long localized day name (e.g. 'Monday' to 'Sunday').
- Uses QDate::longDayName().
- \row \i M \i the month as number without a leading zero (1 to 12)
- \row \i MM \i the month as number with a leading zero (01 to 12)
- \row \i MMM
- \i the abbreviated localized month name (e.g. 'Jan' to 'Dec').
- Uses QDate::shortMonthName().
- \row \i MMMM
- \i the long localized month name (e.g. 'January' to 'December').
- Uses QDate::longMonthName().
- \row \i yy \i the year as two digit number (00 to 99)
- \row \i yyyy \i the year as four digit number. If the year is negative,
- a minus sign is prepended in addition.
- \endtable
- 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. Two consecutive singlequotes ("''") are replaced by a singlequote
- in the output.
- Example format strings (assuming that the QDate is the 20 July
- 1969):
- \table
- \header \o Format \o Result
- \row \o dd.MM.yyyy \o 20.07.1969
- \row \o ddd MMMM d yy \o Sun July 20 69
- \row \o 'The day is' dddd \o The day is Sunday
- \endtable
- If the datetime is invalid, an empty string will be returned.
- \warning The Qt::ISODate format is only valid for years in the
- range 0 to 9999. This restriction may apply to locale-aware
- formats as well, depending on the locale settings.
- \sa QDateTime::toString() QTime::toString()
- */
- QString QDate::toString(const QString& format) const
- {
- if (year() > 9999)
- return QString();
- return fmtDateTime(format, 0, this);
- }
- #endif //QT_NO_DATESTRING
- /*!
- \obsolete
- Sets the date's year \a y, month \a m, and day \a d.
- If \a y is in the range 0 to 99, it is interpreted as 1900 to
- 1999.
- Use setDate() instead.
- */
- bool QDate::setYMD(int y, int m, int d)
- {
- if (uint(y) <= 99)
- y += 1900;
- return setDate(y, m, d);
- }
- /*!
- \since 4.2
- Sets the date's \a year, \a month, and \a day. Returns true if
- the date is valid; otherwise returns false.
- 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.
- \sa isValid()
- */
- bool QDate::setDate(int year, int month, int day)
- {
- if (!isValid(year, month, day)) {
- jd = 0;
- } else {
- jd = julianDayFromDate(year, month, day);
- }
- return jd != 0;
- }
- /*!
- \since 4.5
- Extracts the date's year, month, and day, and assigns them to
- *\a year, *\a month, and *\a day. The pointers may be null.
- \sa year(), month(), day(), isValid()
- */
- void QDate::getDate(int *year, int *month, int *day)
- {
- getDateFromJulianDay(jd, year, month, day);
- }
- /*!
- Returns a QDate object containing a date \a ndays later than the
- date of this object (or earlier if \a ndays is negative).
- \sa addMonths() addYears() daysTo()
- */
- QDate QDate::addDays(int ndays) const
- {
- QDate d;
- // this is basically "d.jd = jd + ndays" with checks for integer overflow
- if (ndays >= 0)
- d.jd = (jd + ndays >= jd) ? jd + ndays : 0;
- else
- d.jd = (jd + ndays < jd) ? jd + ndays : 0;
- return d;
- }
- /*!
- Returns a QDate object containing a date \a nmonths later than the
- date of this object (or earlier if \a nmonths is negative).
- \note If the ending day/month combination does not exist in the
- resulting month/year, this function will return a date that is the
- latest valid date.
- \warning QDate has a date hole around the days introducing the
- Gregorian calendar (the days 5 to 14 October 1582, inclusive, do
- not exist). If the calculation ends in one of those days, QDate
- will return either October 4 or October 15.
- \sa addDays() addYears()
- */
- QDate QDate::addMonths(int nmonths) const
- {
- if (!isValid())
- return QDate();
- if (!nmonths)
- return *this;
- int old_y, y, m, d;
- getDateFromJulianDay(jd, &y, &m, &d);
- old_y = y;
- bool increasing = nmonths > 0;
- while (nmonths != 0) {
- if (nmonths < 0 && nmonths + 12 <= 0) {
- y--;
- nmonths+=12;
- } else if (nmonths < 0) {
- m+= nmonths;
- nmonths = 0;
- if (m <= 0) {
- --y;
- m += 12;
- }
- } else if (nmonths - 12 >= 0) {
- y++;
- nmonths -= 12;
- } else if (m == 12) {
- y++;
- m = 0;
- } else {
- m += nmonths;
- nmonths = 0;
- if (m > 12) {
- ++y;
- m -= 12;
- }
- }
- }
- // was there a sign change?
- if ((old_y > 0 && y <= 0) ||
- (old_y < 0 && y >= 0))
- // yes, adjust the date by +1 or -1 years
- y += increasing ? +1 : -1;
- // did we end up in the Gregorian/Julian conversion hole?
- if (y == 1582 && m == 10 && d > 4 && d < 15)
- d = increasing ? 15 : 4;
- return fixedDate(y, m, d);
- }
- /*!
- Returns a QDate object containing a date \a nyears later than the
- date of this object (or earlier if \a nyears is negative).
- \note If the ending day/month combination does not exist in the
- resulting year (i.e., if the date was Feb 29 and the final year is
- not a leap year), this function will return a date that is the
- latest valid date (that is, Feb 28).
- \sa addDays(), addMonths()
- */
- QDate QDate::addYears(int nyears) const
- {
- if (!isValid())
- return QDate();
- int y, m, d;
- getDateFromJulianDay(jd, &y, &m, &d);
- int old_y = y;
- y += nyears;
- // was there a sign change?
- if ((old_y > 0 && y <= 0) ||
- (old_y < 0 && y >= 0))
- // yes, adjust the date by +1 or -1 years
- y += nyears > 0 ? +1 : -1;
- return fixedDate(y, m, d);
- }
- /*!
- Returns the number of days from this date to \a d (which is
- negative if \a d is earlier than this date).
- Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qdatetime.cpp 0
- \sa addDays()
- */
- int QDate::daysTo(const QDate &d) const
- {
- return d.jd - jd;
- }
- /*!
- \fn bool QDate::operator==(const QDate &d) const
- Returns true if this date is equal to \a d; otherwise returns
- false.
- */
- /*!
- \fn bool QDate::operator!=(const QDate &d) const
- Returns true if this date is different from \a d; otherwise
- returns false.
- */
- /*!
- \fn bool QDate::operator<(const QDate &d) const
- Returns true if this date is earlier than \a d; otherwise returns
- false.
- */
- /*!
- \fn bool QDate::operator<=(const QDate &d) const
- Returns true if this date is earlier than or equal to \a d;
- otherwise returns false.
- */
- /*!
- \fn bool QDate::operator>(const QDate &d) const
- Returns true if this date is later than \a d; otherwise returns
- false.
- */
- /*!
- \fn bool QDate::operator>=(const QDate &d) const
- Returns true if this date is later than or equal to \a d;
- otherwise returns false.
- */
- /*!
- \fn QDate::currentDate()
- Returns the current date, as reported by the system clock.
- \sa QTime::currentTime(), QDateTime::currentDateTime()
- */
- #ifndef QT_NO_DATESTRING
- /*!
- \fn QDate QDate::fromString(const QString &string, Qt::DateFormat format)
- Returns the QDate represented by the \a string, using the
- \a 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.
- */
- QDate QDate::fromString(const QString& s, Qt::DateFormat f)
- {
- if (s.isEmpty())
- return QDate();
- switch (f) {
- case Qt::ISODate:
- {
- int year(s.mid(0, 4).toInt());
- int month(s.mid(5, 2).toInt());
- int day(s.mid(8, 2).toInt());
- if (year && month && day)
- return QDate(year, month, day);
- }
- break;
- case Qt::SystemLocaleDate:
- case Qt::SystemLocaleShortDate:
- case Qt::SystemLocaleLongDate:
- return fromString(s, QLocale::system().dateFormat(f == Qt::SystemLocaleLongDate ? QLocale::LongFormat
- : QLocale::ShortFormat));
- case Qt::LocaleDate:
- case Qt::DefaultLocaleShortDate:
- case Qt::DefaultLocaleLongDate:
- return fromString(s, QLocale().dateFormat(f == Qt::DefaultLocaleLongDate ? QLocale::LongFormat
- : QLocale::ShortFormat));
- default:
- #ifndef QT_NO_TEXTDATE
- case Qt::TextDate: {
- QStringList parts = s.split(QLatin1Char(' '), QString::SkipEmptyParts);
- if (parts.count() != 4) {
- return QDate();
- }
- QString monthName = parts.at(1);
- int month = -1;
- // Assume that English monthnames are the default
- for (int i = 0; i < 12; ++i) {
- if (monthName == QLatin1String(qt_shortMonthNames[i])) {
- month = i + 1;
- break;
- }
- }
- // If English names can't be found, search the localized ones
- if (month == -1) {
- for (int i = 1; i <= 12; ++i) {
- if (monthName == QDate::shortMonthName(i)) {
- month = i;
- break;
- }
- }
- }
- if (month < 1 || month > 12) {
- return QDate();
- }
- bool ok;
- int day = parts.at(2).toInt(&ok);
- if (!ok) {
- return QDate();
- }
- int year = parts.at(3).toInt(&ok);
- if (!ok) {
- return QDate();
- }
- return QDate(year, month, day);
- }
- #else
- break;
- #endif
- }
- return QDate();
- }
- /*!
- \fn QDate::fromString(const QString &string, const QString &format)
- Returns the QDate represented by the \a string, using the \a
- format given, or an invalid date if the string cannot be parsed.
- These expressions may be used for the format:
- \table
- \header \i Expression \i Output
- \row \i d \i The day as a number without a leading zero (1 to 31)
- \row \i dd \i The day as a number with a leading zero (01 to 31)
- \row \i ddd
- \i The abbreviated localized day name (e.g. 'Mon' to 'Sun').
- Uses QDate::shortDayName().
- \row \i dddd
- \i The long localized day name (e.g. 'Monday' to 'Sunday').
- Uses QDate::longDayName().
- \row \i M \i The month as a number without a leading zero (1 to 12)
- \row \i MM \i The month as a number with a leading zero (01 to 12)
- \row \i MMM
- \i The abbreviated localized month name (e.g. 'Jan' to 'Dec').
- Uses QDate::shortMonthName().
- \row \i MMMM
- \i The long localized month name (e.g. 'January' to 'December').
- Uses QDate::longMonthName().
- \row \i yy \i The year as two digit number (00 to 99)
- \row \i yyyy \i The year as four digit number. If the year is negative,
- a minus sign is prepended in addition.
- \endtable
- 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:
- \snippet doc/src/snippets/code/src_corelib_tools_qdatetime.cpp 1
- 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:
- \snippet doc/src/snippets/code/src_corelib_tools_qdatetime.cpp 2
- For any field that is not represented in the format the following
- defaults are used:
- \table
- \header \i Field \i Default value
- \row \i Year \i 1900
- \row \i Month \i 1
- \row \i Day \i 1
- \endtable
- The following examples demonstrate the default values:
- \snippet doc/src/snippets/code/src_corelib_tools_qdatetime.cpp 3
- \sa QDateTime::fromString(), QTime::fromString(), QDate::toString(),
- QDateTime::toString(), QTime::toString()
- */
- QDate QDate::fromString(const QString &string, const QString &format)
- {
- QDate date;
- #ifndef QT_BOOTSTRAPPED
- QDateTimeParser dt(QVariant::Date, QDateTimeParser::FromString);
- if (dt.parseFormat(format))
- dt.fromString(string, &date, 0);
- #else
- Q_UNUSED(string);
- Q_UNUSED(format);
- #endif
- return date;
- }
- #endif // QT_NO_DATESTRING
- /*!
- \overload
- Returns true if the specified date (\a year, \a month, and \a
- day) is valid; otherwise returns false.
- Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qdatetime.cpp 4
- \sa isNull(), setDate()
- */
- bool QDate::isValid(int year, int month, int day)
- {
- if (year < FIRST_YEAR
- || (year == FIRST_YEAR &&
- (month < FIRST_MONTH
- || (month == FIRST_MONTH && day < FIRST_DAY)))
- || year == 0) // there is no year 0 in the Julian calendar
- return false;
- // passage from Julian to Gregorian calendar
- if (year == 1582 && month == 10 && day > 4 && day < 15)
- return 0;
- return (day > 0 && month > 0 && month <= 12) &&
- (day <= monthDays[month] || (day == 29 && month == 2 && isLeapYear(year)));
- }
- /*!
- \fn bool QDate::isLeapYear(int year)
- Returns true if the specified \a year is a leap year; otherwise
- returns false.
- */
- bool QDate::isLeapYear(int y)
- {
- if (y < 1582) {
- if ( y < 1) { // No year 0 in Julian calendar, so -1, -5, -9 etc are leap years
- ++y;
- }
- return y % 4 == 0;
- } else {
- return (y % 4 == 0 && y % 100 != 0) || y % 400 == 0;
- }
- }
- /*!
- \internal
- This function has a confusing name and shouldn't be part of the
- API anyway, since we have toJulian() and fromJulian().
- ### Qt 5: remove it
- */
- uint QDate::gregorianToJulian(int y, int m, int d)
- {
- return julianDayFromDate(y, m, d);
- }
- /*!
- \internal
- This function has a confusing name and shouldn't be part of the
- API anyway, since we have toJulian() and fromJulian().
- ### Qt 5: remove it
- */
- void QDate::julianToGregorian(uint jd, int &y, int &m, int &d)
- {
- getDateFromJulianDay(jd, &y, &m, &d);
- }
- /*! \fn static QDate QDate::fromJulianDay(int jd)
- Converts the Julian day \a jd to a QDate.
- \sa toJulianDay()
- */
- /*! \fn int QDate::toJulianDay() const
- Converts the date to a Julian day.
- \sa fromJulianDay()
- */
- /*****************************************************************************
- QTime member functions
- *****************************************************************************/
- /*!
- \class QTime
- \reentrant
- \brief The QTime class provides clock time functions.
- A QTime object contains a clock time, i.e. the number of hours,
- minutes, seconds, and milliseconds since midnight. It can read the
- current time from the system clock and measure a span of elapsed
- time. It provides functions for comparing times and for
- manipulating a time by adding a number of milliseconds.
- QTime uses the 24-hour clock format; it has no concept of AM/PM.
- Unlike QDateTime, QTime knows nothing about time zones or
- daylight savings time (DST).
- A QTime object is typically created either by giving the number
- of hours, minutes, seconds, and milliseconds explicitly, or by
- using the static function currentTime(), which creates a QTime
- object that contains the system's local time. Note that the
- accuracy depends on the accuracy of the underlying operating
- system; not all systems provide 1-millisecond accuracy.
- The hour(), minute(), second(), and msec() functions provide
- access to the number of hours, minutes, seconds, and milliseconds
- of the time. The same information is provided in textual format by
- the toString() function.
- QTime provides a full set of operators to compare two QTime
- objects. One time is considered smaller than another if it is
- earlier than the other.
- The time a given number of seconds or milliseconds later than a
- given time can be found using the addSecs() or addMSecs()
- functions. Correspondingly, the number of seconds or milliseconds
- between two times can be found using secsTo() or msecsTo().
- QTime can be used to measure a span of elapsed time using the
- start(), restart(), and elapsed() functions.
- \sa QDate, QDateTime
- */
- /*!
- \fn QTime::QTime()
- Constructs a null time object. A null time can be a QTime(0, 0, 0, 0)
- (i.e., midnight) object, except that isNull() returns true and isValid()
- returns false.
- \sa isNull(), isValid()
- */
- /*!
- Constructs a time with hour \a h, minute \a m, seconds \a s and
- milliseconds \a ms.
- \a h must be in the range 0 to 23, \a m and \a s must be in the
- range 0 to 59, and \a ms must be in the range 0 to 999.
- \sa isValid()
- */
- QTime::QTime(int h, int m, int s, int ms)
- {
- setHMS(h, m, s, ms);
- }
- /*!
- \fn bool QTime::isNull() const
- Returns true if the time is null (i.e., the QTime object was
- constructed using the default constructor); otherwise returns
- false. A null time is also an invalid time.
- \sa isValid()
- */
- /*!
- Returns true if the time is valid; otherwise returns false. For example,
- the time 23:30:55.746 is valid, but 24:12:30 is invalid.
- \sa isNull()
- */
- bool QTime::isValid() const
- {
- return mds > NullTime && mds < MSECS_PER_DAY;
- }
- /*!
- Returns the hour part (0 to 23) of the time.
- \sa minute(), second(), msec()
- */
- int QTime::hour() const
- {
- return ds() / MSECS_PER_HOUR;
- }
- /*!
- Returns the minute part (0 to 59) of the time.
- \sa hour(), second(), msec()
- */
- int QTime::minute() const
- {
- return (ds() % MSECS_PER_HOUR) / MSECS_PER_MIN;
- }
- /*!
- Returns the second part (0 to 59) of the time.
- \sa hour(), minute(), msec()
- */
- int QTime::second() const
- {
- return (ds() / 1000)%SECS_PER_MIN;
- }
- /*!
- Returns the millisecond part (0 to 999) of the time.
- \sa hour(), minute(), second()
- */
- int QTime::msec() const
- {
- return ds() % 1000;
- }
- #ifndef QT_NO_DATESTRING
- /*!
- \overload
- Returns the time as a string. Milliseconds are not included. The
- \a format parameter determines the format of the string.
- If \a format is Qt::TextDate, the string format is HH:MM:SS; e.g. 1
- second before midnight would be "23:59:59".
- If \a format is Qt::ISODate, the string format corresponds to the
- ISO 8601 extended specification for representations of dates,
- which is also HH:mm:ss. (However, contrary to ISO 8601, dates
- before 15 October 1582 are handled as Julian dates, not Gregorian
- dates. See \l{QDate G and J} {Use of Gregorian and Julian
- Calendars}. This might change in a future version of Qt.)
- If the \a format is Qt::SystemLocaleShortDate or
- Qt::SystemLocaleLongDate, the string format depends on the locale
- settings of the system. Identical to calling
- QLocale::system().toString(time, QLocale::ShortFormat) or
- QLocale::system().toString(time, QLocale::LongFormat).
- If the \a format is Qt::DefaultLocaleShortDate or
- Qt::DefaultLocaleLongDate, 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(time,
- QLocale::ShortFormat) or QLocale().toString(time,
- QLocale::LongFormat).
- If the time is invalid, an empty string will be returned.
- */
- QString QTime::toString(Qt::DateFormat format) const
- {
- if (!isValid())
- return QString();
- switch (format) {
- case Qt::SystemLocaleDate:
- case Qt::SystemLocaleShortDate:
- case Qt::SystemLocaleLongDate:
- return QLocale::system().toString(*this, format == Qt::SystemLocaleLongDate ? QLocale::LongFormat
- : QLocale::ShortFormat);
- case Qt::LocaleDate:
- case Qt::DefaultLocaleShortDate:
- case Qt::DefaultLocaleLongDate:
- return QLocale().toString(*this, format == Qt::DefaultLocaleLongDate ? QLocale::LongFormat
- : QLocale::ShortFormat);
- default:
- case Qt::ISODate:
- case Qt::TextDate:
- return QString::fromLatin1("%1:%2:%3")
- .arg(hour(), 2, 10, QLatin1Char('0'))
- .arg(minute(), 2, 10, QLatin1Char('0'))
- .arg(second(), 2, 10, QLatin1Char('0'));
- }
- }
- /*!
- Returns the time as a string. The \a format parameter determines
- the format of the result string.
- These expressions may be used:
- \table
- \header \i Expression \i Output
- \row \i h
- \i the hour without a leading zero (0 to 23 or 1 to 12 if AM/PM display)
- \row \i hh
- \i the hour with a leading zero (00 to 23 or 01 to 12 if AM/PM display)
- \row \i H
- \i the hour without a leading zero (0 to 23, even with AM/PM display)
- \row \i HH
- \i the hour with a leading zero (00 to 23, even with AM/PM display)
- \row \i m \i the minute without a leading zero (0 to 59)
- \row \i mm \i the minute with a leading zero (00 to 59)
- \row \i s \i the second without a leading zero (0 to 59)
- \row \i ss \i the second with a leading zero (00 to 59)
- \row \i z \i the milliseconds without leading zeroes (0 to 999)
- \row \i zzz \i the milliseconds with leading zeroes (000 to 999)
- \row \i AP or A
- \i use AM/PM display. \e AP will be replaced by either "AM" or "PM".
- \row \i ap or a
- \i use am/pm display. \e ap will be replaced by either "am" or "pm".
- \row \i t \i the timezone (for example "CEST")
- \endtable
- 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. Two consecutive singlequotes ("''") are replaced by a singlequote
- in the output.
- Example format strings (assuming that the QTime is 14:13:09.042)
- \table
- \header \i Format \i Result
- \row \i hh:mm:ss.zzz \i 14:13:09.042
- \row \i h:m:s ap \i 2:13:9 pm
- \row \i H:m:s a \i 14:13:9 pm
- \endtable
- If the datetime is invalid, an empty string will be returned.
- If \a format is empty, the default format "hh:mm:ss" is used.
- \sa QDate::toString() QDateTime::toString()
- */
- QString QTime::toString(const QString& format) const
- {
- return fmtDateTime(format, this, 0);
- }
- #endif //QT_NO_DATESTRING
- /*!
- Sets the time to hour \a h, minute \a m, seconds \a s and
- milliseconds \a ms.
- \a h must be in the range 0 to 23, \a m and \a s must be in the
- range 0 to 59, and \a ms must be in the range 0 to 999.
- Returns true if the set time is valid; otherwise returns false.
- \sa isValid()
- */
- bool QTime::setHMS(int h, int m, int s, int ms)
- {
- #if defined(Q_OS_WINCE)
- startTick = NullTime;
- #endif
- if (!isValid(h,m,s,ms)) {
- mds = NullTime; // make this invalid
- return false;
- }
- mds = (h*SECS_PER_HOUR + m*SECS_PER_MIN + s)*1000 + ms;
- return true;
- }
- /*!
- Returns a QTime object containing a time \a s seconds later
- than the time of this object (or earlier if \a s is negative).
- Note that the time will wrap if it passes midnight.
- Example:
- \snippet doc/src/snippets/code/src_corelib_tools_qdatetime.cpp 5
- \sa addMSecs(), secsTo(), QDateTime::addSecs()
- */
- QTime QTime::addSecs(int s) const
- {
- return addMSecs(s * 1000);
- }
- /*!
- Returns the number of seconds from this time to \a t.
- If \a t is earlier than this time, the number of seconds returned
- is negative.
- Because QTime measures time within a day and there are 86400
- seconds in a day, the result is always between -86400 and 86400.
- secsTo() does not take into account any milliseconds.
- \sa addSecs(), QDateTime::secsTo()
- */
- int QTime::secsTo(const QTime &t) const
- {
- return (t.ds() - ds()) / 1000;
- }
- /*!
- Returns a QTime object containing a time \a ms milliseconds later
- than the time of this object (or earlier if \a ms is negative).
- Note that the time will wrap if it passes midnight. See addSecs()
- for an example.
- \sa addSecs(), msecsTo(), QDateTime::addMSecs()
- */
- QTime QTime::addMSecs(int ms) const
- {
- QTime t;
- if (ms < 0) {
- // % not well-defined for -ve, but / is.
- int negdays = (MSECS_PER_DAY - ms) / MSECS_PER_DAY;
- t.mds = (ds() + ms + negdays * MSECS_PER_DAY) % MSECS_PER_DAY;
- } else {
- t.mds = (ds() + ms) % MSECS_PER_DAY;
- }
- #if defined(Q_OS_WINCE)
- if (startTick > NullTime)
- t.startTick = (startTick + ms) % MSECS_PER_DAY;
- #endif
- return t;
- }
- /*!
- Returns the number of milliseconds from this time to \a t.
- If \a t is earlier than this time, the number of milliseconds returned
- is negative.
- Because QTime measures time within a day and there are 86400
- seconds in a day, the result is always between -86400000 and
- 86400000 ms.
- \sa secsTo(), addMSecs(), QDateTime::msecsTo()
- */
- int QTime::msecsTo(const QTime &…
Large files files are truncated, but you can click here to view the full file