Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qdatetime.cpp File Reference

(45e90b73c75b2c7997a0f8d750f9927f64e05a0e)

#include "qdatetime.h"
#include "qcalendar.h"
#include "qdatastream.h"
#include "qdebug.h"
#include "qlocale.h"
#include "qset.h"
#include "private/qcalendarmath_p.h"
#include "private/qdatetime_p.h"
#include "private/qgregoriancalendar_p.h"
#include "private/qlocale_tools_p.h"
#include "private/qlocaltime_p.h"
#include "private/qnumeric_p.h"
#include "private/qstringconverter_p.h"
#include "private/qstringiterator_p.h"
#include <cmath>
#include <private/qtools_p.h>
+ Include dependency graph for qdatetime.cpp:

Go to the source code of this file.

Typedefs

typedef QDateTimePrivate::QDateTimeShortData ShortData
 
typedef QDateTimePrivate::QDateTimeData QDateTimeData
 

Enumerations

enum class  DaySide { Start , End , Start , End }
 
enum class  DaySide { Start , End , Start , End }
 

Functions

static QDate fixedDate (QCalendar::YearMonthDay parts, QCalendar cal)
 
static QDate fixedDate (QCalendar::YearMonthDay parts)
 
static QString toOffsetString (Qt::DateFormat format, int offset)
 
static bool inDateTimeRange (qint64 jd, DaySide side)
 
static QDateTime toEarliest (QDate day, const QTimeZone &zone)
 
static QDateTime toLatest (QDate day, const QTimeZone &zone)
 
static qint64 msecsToJulianDay (qint64 msecs)
 
static QDate msecsToDate (qint64 msecs)
 
static QTime msecsToTime (qint64 msecs)
 
static bool daysAndMillisOverflow (qint64 days, qint64 millisInDay, qint64 *sumMillis)
 
static qint64 timeToMSecs (QDate date, QTime time)
 
static bool millisInSystemRange (qint64 millis, qint64 slack=0)
 
static int systemTimeYearMatching (int year)
 
static auto millisToWithinRange (qint64 millis)
 
static constexpr QDateTimePrivate::TransitionOptions toTransitionOptions (QDateTime::TransitionResolution res)
 
static constexpr QDateTimePrivate::TransitionOptions toTransitionOptions (QDateTimePrivate::DaylightStatus dst)
 
static QDateTimePrivate::ZoneState stateAtMillis (const QTimeZone &zone, qint64 millis, QDateTimePrivate::TransitionOptions resolve)
 
static bool specCanBeSmall (Qt::TimeSpec spec)
 
static bool msecsCanBeSmall (qint64 msecs)
 
static constexpr QDateTimePrivate::StatusFlags mergeSpec (QDateTimePrivate::StatusFlags status, Qt::TimeSpec spec)
 
static constexpr Qt::TimeSpec extractSpec (QDateTimePrivate::StatusFlags status)
 
static constexpr QDateTimePrivate::StatusFlags mergeDaylightStatus (QDateTimePrivate::StatusFlags sf, QDateTimePrivate::DaylightStatus status)
 
static constexpr QDateTimePrivate::DaylightStatus extractDaylightStatus (QDateTimePrivate::StatusFlags status)
 
static qint64 getMSecs (const QDateTimeData &d)
 
static QDateTimePrivate::StatusFlags getStatus (const QDateTimeData &d)
 
static Qt::TimeSpec getSpec (const QDateTimeData &d)
 
static bool usesSameOffset (const QDateTimeData &a, const QDateTimeData &b)
 
bool areFarEnoughApart (qint64 leftMillis, qint64 rightMillis)
 
static void refreshZonedDateTime (QDateTimeData &d, const QTimeZone &zone, QDateTimePrivate::TransitionOptions resolve)
 
static void refreshSimpleDateTime (QDateTimeData &d)
 
static void checkValidDateTime (QDateTimeData &d, QDateTime::TransitionResolution resolve)
 
static void reviseTimeZone (QDateTimeData &d, const QTimeZone &zone, QDateTime::TransitionResolution resolve)
 
static void setDateTime (QDateTimeData &d, QDate date, QTime time)
 
static std::pair< QDate, QTimegetDateTime (const QDateTimeData &d)
 
static void massageAdjustedDateTime (QDateTimeData &d, QDate date, QTime time, bool forward)
 
Qt::weak_ordering compareThreeWay (const QDateTime &lhs, const QDateTime &rhs)
 
size_t qHash (const QDateTime &key, size_t seed)
 \qhashold{QHash}
 
size_t qHash (QDate key, size_t seed) noexcept
 \qhashold{QHash}
 
size_t qHash (QTime key, size_t seed) noexcept
 \qhashold{QHash}
 

Typedef Documentation

◆ QDateTimeData

Definition at line 2714 of file qdatetime.cpp.

◆ ShortData

Enumeration Type Documentation

◆ DaySide [1/2]

enum class DaySide
strong
Enumerator
Start 
End 
Start 
End 

Definition at line 838 of file qdatetime.cpp.

◆ DaySide [2/2]

enum class DaySide
strong
Enumerator
Start 
End 
Start 
End 

Definition at line 838 of file qdatetime.cpp.

Function Documentation

◆ areFarEnoughApart()

bool areFarEnoughApart ( qint64 leftMillis,
qint64 rightMillis )

Definition at line 3186 of file qdatetime.cpp.

◆ checkValidDateTime()

static void checkValidDateTime ( QDateTimeData & d,
QDateTime::TransitionResolution resolve )
static

Definition at line 3269 of file qdatetime.cpp.

References refreshSimpleDateTime().

+ Here is the call graph for this function:

◆ compareThreeWay()

Qt::weak_ordering compareThreeWay ( const QDateTime & lhs,
const QDateTime & rhs )

Definition at line 5267 of file qdatetime.cpp.

◆ daysAndMillisOverflow()

static bool daysAndMillisOverflow ( qint64 days,
qint64 millisInDay,
qint64 * sumMillis )
inlinestatic

Definition at line 2734 of file qdatetime.cpp.

◆ extractDaylightStatus()

static constexpr QDateTimePrivate::DaylightStatus extractDaylightStatus ( QDateTimePrivate::StatusFlags status)
inlinestaticconstexpr

Definition at line 3110 of file qdatetime.cpp.

◆ extractSpec()

static constexpr Qt::TimeSpec extractSpec ( QDateTimePrivate::StatusFlags status)
inlinestaticconstexpr

Definition at line 3090 of file qdatetime.cpp.

◆ fixedDate() [1/2]

static QDate fixedDate ( QCalendar::YearMonthDay parts)
inlinestatic

Definition at line 63 of file qdatetime.cpp.

◆ fixedDate() [2/2]

static QDate fixedDate ( QCalendar::YearMonthDay parts,
QCalendar cal )
inlinestatic

Definition at line 54 of file qdatetime.cpp.

◆ getDateTime()

static std::pair< QDate, QTime > getDateTime ( const QDateTimeData & d)
static

Definition at line 3385 of file qdatetime.cpp.

◆ getMSecs()

static qint64 getMSecs ( const QDateTimeData & d)
inlinestatic

Definition at line 3119 of file qdatetime.cpp.

◆ getSpec()

static Qt::TimeSpec getSpec ( const QDateTimeData & d)
inlinestatic

Definition at line 3139 of file qdatetime.cpp.

◆ getStatus()

static QDateTimePrivate::StatusFlags getStatus ( const QDateTimeData & d)
inlinestatic

Definition at line 3129 of file qdatetime.cpp.

◆ inDateTimeRange()

static bool inDateTimeRange ( qint64 jd,
DaySide side )
static

Definition at line 840 of file qdatetime.cpp.

References End, and Start.

◆ massageAdjustedDateTime()

static void massageAdjustedDateTime ( QDateTimeData & d,
QDate date,
QTime time,
bool forward )
inlinestatic

Definition at line 4777 of file qdatetime.cpp.

References refreshSimpleDateTime().

+ Here is the call graph for this function:

◆ mergeDaylightStatus()

static constexpr QDateTimePrivate::StatusFlags mergeDaylightStatus ( QDateTimePrivate::StatusFlags sf,
QDateTimePrivate::DaylightStatus status )
inlinestaticconstexpr

Definition at line 3097 of file qdatetime.cpp.

◆ mergeSpec()

static constexpr QDateTimePrivate::StatusFlags mergeSpec ( QDateTimePrivate::StatusFlags status,
Qt::TimeSpec spec )
inlinestaticconstexpr

Definition at line 3083 of file qdatetime.cpp.

◆ millisInSystemRange()

static bool millisInSystemRange ( qint64 millis,
qint64 slack = 0 )
inlinestatic

Tests whether system functions can handle a given time.

The range of milliseconds for which the time_t-based functions work depends somewhat on platform (see computeSystemMillisRange() for details). This function tests whether the UTC time millis milliseconds from the epoch is in the supported range.

To test a local time, pass an upper bound on the magnitude of time-zone correction potentially needed as slack: in this case the range is extended by this many milliseconds at each end (where applicable). The function then returns true precisely if millis is within this (possibly) widened range. This doesn't guarantee that the time_t functions can handle the time, so check their returns to be sure. Values for which the function returns false should be assumed unrepresentable.

Definition at line 2773 of file qdatetime.cpp.

◆ millisToWithinRange()

static auto millisToWithinRange ( qint64 millis)
static

Definition at line 2869 of file qdatetime.cpp.

◆ msecsCanBeSmall()

static bool msecsCanBeSmall ( qint64 msecs)
inlinestatic

Definition at line 3072 of file qdatetime.cpp.

◆ msecsToDate()

static QDate msecsToDate ( qint64 msecs)
static

Definition at line 2722 of file qdatetime.cpp.

◆ msecsToJulianDay()

static qint64 msecsToJulianDay ( qint64 msecs)
static

Definition at line 2717 of file qdatetime.cpp.

◆ msecsToTime()

static QTime msecsToTime ( qint64 msecs)
static

Definition at line 2727 of file qdatetime.cpp.

◆ qHash() [1/3]

size_t qHash ( const QDateTime & key,
size_t seed )

\qhashold{QHash}

Since
5.0

Definition at line 6303 of file qdatetime.cpp.

◆ qHash() [2/3]

size_t qHash ( QDate key,
size_t seed )
noexcept

\qhashold{QHash}

Since
5.0

Definition at line 6316 of file qdatetime.cpp.

◆ qHash() [3/3]

size_t qHash ( QTime key,
size_t seed )
noexcept

\qhashold{QHash}

Since
5.0

Definition at line 6325 of file qdatetime.cpp.

◆ refreshSimpleDateTime()

static void refreshSimpleDateTime ( QDateTimeData & d)
static

Definition at line 3255 of file qdatetime.cpp.

Referenced by checkValidDateTime(), massageAdjustedDateTime(), and reviseTimeZone().

+ Here is the caller graph for this function:

◆ refreshZonedDateTime()

static void refreshZonedDateTime ( QDateTimeData & d,
const QTimeZone & zone,
QDateTimePrivate::TransitionOptions resolve )
static

Definition at line 3195 of file qdatetime.cpp.

◆ reviseTimeZone()

static void reviseTimeZone ( QDateTimeData & d,
const QTimeZone & zone,
QDateTime::TransitionResolution resolve )
static

Definition at line 3287 of file qdatetime.cpp.

References refreshSimpleDateTime().

+ Here is the call graph for this function:

◆ setDateTime()

static void setDateTime ( QDateTimeData & d,
QDate date,
QTime time )
static

Definition at line 3330 of file qdatetime.cpp.

◆ specCanBeSmall()

static bool specCanBeSmall ( Qt::TimeSpec spec)
inlinestatic

Definition at line 3067 of file qdatetime.cpp.

◆ stateAtMillis()

static QDateTimePrivate::ZoneState stateAtMillis ( const QTimeZone & zone,
qint64 millis,
QDateTimePrivate::TransitionOptions resolve )
inlinestatic

Definition at line 3055 of file qdatetime.cpp.

◆ systemTimeYearMatching()

static int systemTimeYearMatching ( int year)
static

Returns a year, in the system range, with the same day-of-week pattern

Returns the number of a year, in the range supported by system time_t functions, that starts and ends on the same days of the week as year. This implies it is a leap year precisely if year is. If year is before the epoch, a year early in the supported range is used; otherwise, one late in that range. For a leap year, this may be as much as 26 years years from the range's relevant end; for normal years at most a decade from the end.

This ensures that any DST rules based on, e.g., the last Sunday in a particular month will select the same date in the returned year as they would if applied to year. Of course, the zone's rules may be different in year than in the selected year, but it's hard to do better.

Definition at line 2796 of file qdatetime.cpp.

◆ timeToMSecs()

static qint64 timeToMSecs ( QDate date,
QTime time )
static

Definition at line 2741 of file qdatetime.cpp.

◆ toEarliest()

static QDateTime toEarliest ( QDate day,
const QTimeZone & zone )
static

Definition at line 860 of file qdatetime.cpp.

◆ toLatest()

static QDateTime toLatest ( QDate day,
const QTimeZone & zone )
static

Definition at line 1015 of file qdatetime.cpp.

◆ toOffsetString()

static QString toOffsetString ( Qt::DateFormat format,
int offset )
static

Definition at line 285 of file qdatetime.cpp.

◆ toTransitionOptions() [1/2]

static constexpr QDateTimePrivate::TransitionOptions toTransitionOptions ( QDateTime::TransitionResolution res)
staticconstexpr

Definition at line 2938 of file qdatetime.cpp.

◆ toTransitionOptions() [2/2]

static constexpr QDateTimePrivate::TransitionOptions toTransitionOptions ( QDateTimePrivate::DaylightStatus dst)
staticconstexpr

Definition at line 2963 of file qdatetime.cpp.

◆ usesSameOffset()

static bool usesSameOffset ( const QDateTimeData & a,
const QDateTimeData & b )
inlinestatic

Definition at line 3149 of file qdatetime.cpp.