diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2022-11-25 16:01:33 +0100 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2022-12-05 23:04:13 +0100 |
commit | c4a0630e4580c0d246cfb5786b80e09f3a3abf2e (patch) | |
tree | dbf54a5c0cfb14f8f00e7b1ae52a74ccb073cb6c /src/corelib | |
parent | ec8253d5c74aedde75cae2919b0571d1cf8d1949 (diff) |
QDateTime::to{LocalTime,UTC}(): relocate to among related code
These two functions were a long way from their closest relatives.
Relocate to make it easier to compare and contrast within the family.
Change-Id: I30062c16b318f222b75b527c6af5b443770fe36a
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/time/qdatetime.cpp | 99 |
1 files changed, 48 insertions, 51 deletions
diff --git a/src/corelib/time/qdatetime.cpp b/src/corelib/time/qdatetime.cpp index 3bac9fe504..f46f789141 100644 --- a/src/corelib/time/qdatetime.cpp +++ b/src/corelib/time/qdatetime.cpp @@ -4454,6 +4454,54 @@ QDateTime QDateTime::toOffsetFromUtc(int offsetSeconds) const return fromMSecsSinceEpoch(toMSecsSinceEpoch(), Qt::OffsetFromUTC, offsetSeconds); } +/*! + Returns a datetime containing the date and time information in + this datetime, but specified using the Qt::LocalTime definition. + + Example: + + \snippet code/src_corelib_time_qdatetime.cpp 17 + + \sa toUTC(), toOffsetFromUtc(), toTimeZone(), toTimeSpec() +*/ +QDateTime QDateTime::toLocalTime() const +{ + if (getSpec(d) == Qt::LocalTime) + return *this; + + if (!isValid()) { + QDateTime ret = *this; + ret.setTimeSpec(Qt::LocalTime); + return ret; + } + + return fromMSecsSinceEpoch(toMSecsSinceEpoch()); +} + +/*! + Returns a datetime containing the date and time information in + this datetime, but specified using the Qt::UTC definition. + + Example: + + \snippet code/src_corelib_time_qdatetime.cpp 18 + + \sa toLocalTime(), toOffsetFromUtc(), toTimeZone(), toTimeSpec() +*/ +QDateTime QDateTime::toUTC() const +{ + if (getSpec(d) == Qt::UTC) + return *this; + + if (!isValid()) { + QDateTime ret = *this; + ret.setTimeSpec(Qt::UTC); + return ret; + } + + return fromMSecsSinceEpoch(toMSecsSinceEpoch(), Qt::UTC); +} + #if QT_CONFIG(timezone) /*! \since 5.2 @@ -5179,57 +5227,6 @@ QDateTime QDateTime::fromString(const QString &string, QStringView format, QCale } #endif // datestring -/*! - \fn QDateTime QDateTime::toLocalTime() const - - Returns a datetime containing the date and time information in - this datetime, but specified using the Qt::LocalTime definition. - - Example: - - \snippet code/src_corelib_time_qdatetime.cpp 17 - - \sa toUTC(), toOffsetFromUtc(), toTimeZone(), toTimeSpec() -*/ -QDateTime QDateTime::toLocalTime() const -{ - if (getSpec(d) == Qt::LocalTime) - return *this; - - if (!isValid()) { - QDateTime ret = *this; - ret.setTimeSpec(Qt::LocalTime); - return ret; - } - - return fromMSecsSinceEpoch(toMSecsSinceEpoch()); -} - -/*! - \fn QDateTime QDateTime::toUTC() const - - Returns a datetime containing the date and time information in - this datetime, but specified using the Qt::UTC definition. - - Example: - - \snippet code/src_corelib_time_qdatetime.cpp 18 - - \sa toLocalTime(), toOffsetFromUtc(), toTimeZone(), toTimeSpec() -*/ -QDateTime QDateTime::toUTC() const -{ - if (getSpec(d) == Qt::UTC) - return *this; - - if (!isValid()) { - QDateTime ret = *this; - ret.setTimeSpec(Qt::UTC); - return ret; - } - - return fromMSecsSinceEpoch(toMSecsSinceEpoch(), Qt::UTC); -} /***************************************************************************** Date/time stream functions |