QDateTime: How does one distinguish the "double hour" during DST switch?
-
According to docs, QDateTime supports daylight saving time. But how to I distinguish the twin time periods that happen when the clock is turned back during a DST switch? For example, before reaching 3am, the clock is turned back to 2am. If QDateTime says it's 2:39am, are we talking about the first or second such period?
Also, the toString() method seems to lack a way to express this. -
@m.sue said in QDateTime: How does one distinguish the "double hour" during DST switch?:
Hi,
I would guess that the function isDaylightTime() returns true during the first and false during second such hour.
-Michael.
True. That would still make it very cumbersome to "mark" the second of a duplicate time span, because I would need to understand the specific rules of the DST switch to know whether this is a time period that I need to mark at all.
Here is an example of what I am looking for.
UTC DST DESIRED OUTPUT 01:00:00 true 02:00:00 01:30:00 true 02:30:00 02:00:00 false 02b00:00 02:30:00 false 02b30:00 03:00:00 false 03:00:00
The details of the DST switch should best remain buried within Qt - as a user of the class, I would rather not know the details whether my timezone has DST at all, when and how often the switch occurs, and with what time difference.
-
Hi,
In that case, shouldn't you use a date time format that includes time zone information ? You'll then have the offset applied with DST and without.
-
Hi,
In that case, shouldn't you use a date time format that includes time zone information ? You'll then have the offset applied with DST and without.
@SGaist said in QDateTime: How does one distinguish the "double hour" during DST switch?:
Hi,
In that case, shouldn't you use a date time format that includes time zone information ? You'll then have the offset applied with DST and without.
I think you refer to the ISO 8601 format (Qt::ISODate). That format gives you time zone information, but it doesn't tell you (at one glance) whether you are in a double hour, either. As a user, you again have to understand the time zone specification, and I'd like to avoid that.
Also, it is rather long. -
-
Hi, I think @SGaist meant the vanilla QDateTime, anyway, what you can try:
#include "qdatetime.h"
andif (!QDateTime::currentDateTime().isDaylightTime() && QDateTime::currentDateTime().addSecs(-3600).isDaylightTime()) // inside the double hour
@hskoglund said in QDateTime: How does one distinguish the "double hour" during DST switch?:
Hi, I think @SGaist meant the vanilla QDateTime, anyway, what you can try:
#include "qdatetime.h"
andif (!QDateTime::currentDateTime().isDaylightTime() && QDateTime::currentDateTime().addSecs(-3600).isDaylightTime()) // inside the double hour
Good point. That could work. Thanks!