Results 1 to 2 of 2

Thread: QDateTime and Support for Daylight Savings Time

  1. #1
    Join Date
    Mar 2011
    Posts
    25
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QDateTime and Support for Daylight Savings Time

    According to QtAssistant, the QDateTime class is aware of Daylight Savings Time, but there either seems to be some gaps, or I'm overlooking something.

    The specific problem I have is that I need to converted formated date/time strings into a QDateTime; there's good support for that except (as far as I can see) when DST ends. A specific example is that, in 2010, in most of the U.S., DST ended on November 7, 2010 at 2:00 AM; the clock was set back an hour, producing two 2:00's and two hours between 1:00 and 2:00.

    So if I have the string below to parse, it's impossible to determine, from the string alone, whether it's the first 1:15 AM on that day or the second one.

    Nov 7, 2010 01:15

    We keep a DST flag to identify these from when the formatted text was created (and no, I don't have the option of rewriting the system to pass UTC everywhere...sorry). Our existing date/time functions (that I'm trying to avoid because they're terrible) accept this flag and adjust the resulting UTC time accordingly.

    Qt doesn't seem to provide any way of allowing me to specify which of those hours the string represents. I can check the flag and if set, add an hour to the result, but that will break down in locales that change time by some value other than an hour. Those are probably not relevant for my purposes at this time, but I hate to code something that I know is wrong.

    Ideas?

    Doug

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QDateTime and Support for Daylight Savings Time

    I don't think Qt is in any way non-standard here. Even your own time specification doesn't have means to determine which of the zones the time represents and you need an additional flag to store this info. Only the UTC time contains such information so that should be your standard time specification. You can convert it to the local time (including timezones and DST) on demand using QDateTime::toLocalTime().
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. run-time vs linked OpenSSL support
    By piotr.dobrogost in forum Installation and Deployment
    Replies: 12
    Last Post: 30th March 2012, 06:56
  2. Linux, detect DST (daylight saving time)
    By JeanC in forum General Programming
    Replies: 2
    Last Post: 13th February 2011, 08:10
  3. Replies: 2
    Last Post: 8th February 2011, 14:53
  4. How to convert unix time to QDateTime
    By lni in forum Qt Programming
    Replies: 3
    Last Post: 14th November 2007, 00:25
  5. QDateTime GMT add sec. or - sec. from locale time....
    By patrik08 in forum Qt Programming
    Replies: 2
    Last Post: 20th February 2007, 16:39

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.