[Qt-interest] New Date and Time Features in Qt5?
Konrad Rosenbaum
konrad at silmor.de
Tue May 31 10:36:54 CEST 2011
On Tue, May 31, 2011 07:56, David Ching wrote:
> I could be writing a UI that shows the user their time zone and whether or
> not DST is in effect or not.
Ok, I could understand that some users are interested in this.
> When showing user the timezone, they expect
> to
> always see the same one regardless of whether DST is in effect or not.
> For
> example, I am in San Francisco, I expect to see Pacific Time as UTC-8,
> even
> though currently DST is in effect, and thus current time is only 7 hours
> behind UTC. I do not expect to see the UI show me UTC-7 in this case,
> which
> is the only thing possible given the calculations that can currently be
> performed with QDateTime.
Hmm. This needs a clarification:
UTC-7 or UTC+2 is NOT a timezone it is an offset. So during DST you should
get a time zone of "Pacific Summer Time" with an offset of UTC-7. During
standard "winter" time you should get a timezone of "Pacific Time" with
offset UTC-8. You should never get "UTC-8" as a time zone (unless you are
on a system that allows you to use "unusual" time zones and you do use
them).
> I have another case where I need to query the current UTC time (current
> QDateTime provides this OK) and also the offset in minutes of the local
> timezone compared to UTC. This offset should not take into account DST
> (not
> possible in Qt now).
There is no base offset for time zones. Most time zones have two
definitions that switch on specific dates and each definition has its own
offset. There is no rule that the difference between those offsets has to
be one hour, that december is one hour behind june, or that the base time
is in winter, or that winter happens in june... ;-)
> These two info is sent via serial port to FTDI chip
> on
> a USB device to set its current time. It tracks DST itself and applies
> it,
> that's why the offset I send should not include DST.
This sounds broken by design. If the device was designed to work only in
your time zone: you can still hard code the offsets. If not: complain to
the manufacturer.
If you can change the firmware: I recommend to either make the device time
zone agnostic and let it track UTC (measurement or logging device) or make
it track local time without automatic DST changes (a display clock).
Otherwise you'll have to upload a lot of time zone definitions into it and
you'll have to perform periodic changes whenever some politician thinks he
has a bright idea about that time zone thing...
Konrad
More information about the Qt-interest-old
mailing list