summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJohn Layt <jlayt@kde.org>2013-09-02 16:35:25 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-09-20 23:45:06 +0200
commit8d6ee59948ef7d56694db0aa9e14212cb1787972 (patch)
tree5b7e654566a61169c02cd1217611cc65a3c9759d /src
parentfafc2daf94e46f4e4283abd3acf6613138262c27 (diff)
QDateTime - Add api for isDaylightTime()
Add new method to return if the current time is Daylight Time. [ChangeLog][QtCore][QDateTime] Added new method isDaylightTime() to return if the datetime is in Daylight Time or not. Change-Id: Icb93fd5dd0b2f7d83d2d4643eeb12922c1137e3e Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src')
-rw-r--r--src/corelib/tools/qdatetime.cpp26
-rw-r--r--src/corelib/tools/qdatetime.h1
2 files changed, 27 insertions, 0 deletions
diff --git a/src/corelib/tools/qdatetime.cpp b/src/corelib/tools/qdatetime.cpp
index d87a4c1b67..bfcbe1e050 100644
--- a/src/corelib/tools/qdatetime.cpp
+++ b/src/corelib/tools/qdatetime.cpp
@@ -2993,6 +2993,32 @@ QString QDateTime::timeZoneAbbreviation() const
}
/*!
+ \since 5.2
+
+ Returns if this datetime falls in Daylight Savings Time.
+
+ If the Qt::TimeSpec is not Qt::LocalTime then will always
+ return false.
+
+ \sa timeSpec()
+*/
+
+bool QDateTime::isDaylightTime() const
+{
+ switch (d->m_spec) {
+ case Qt::UTC:
+ case Qt::OffsetFromUTC:
+ return false;
+ case Qt::LocalTime: {
+ QDateTimePrivate::DaylightStatus status;
+ localMSecsToEpochMSecs(d->m_msecs, 0, 0, &status, 0);
+ return (status == QDateTimePrivate::DaylightTime);
+ }
+ }
+ return false;
+}
+
+/*!
Sets the date part of this datetime to \a date.
If no time is set, it is set to midnight.
diff --git a/src/corelib/tools/qdatetime.h b/src/corelib/tools/qdatetime.h
index 779aae5b5b..4b97cd797d 100644
--- a/src/corelib/tools/qdatetime.h
+++ b/src/corelib/tools/qdatetime.h
@@ -223,6 +223,7 @@ public:
Qt::TimeSpec timeSpec() const;
int offsetFromUtc() const;
QString timeZoneAbbreviation() const;
+ bool isDaylightTime() const;
qint64 toMSecsSinceEpoch() const;
// ### Qt 6: use quint64 instead of uint