PQt4 QDatetime: Why do I get the same answer when using addSecs() with two different seconds values?

StackOverflow https://stackoverflow.com/questions/10436868

  •  05-06-2021
  •  | 
  •  

Question

I'm using Python 2.6.6 and PyQt4. I have a start QDateTime object and I am iteratively adding 60 seconds to create a list of every minute within a given time span. I have discovered that there are several cases where adding two different seconds values to the QDateTime object produces the same time.

Here's an example of the problem:

from PyQt4 import QtCore

start = QtCore.QDateTime.fromString("2010-11-01 00:00", "yyyy-MM-dd hh:mm")

print start.addSecs(522540).toString("yyyy-MM-dd hh:mm")
print start.addSecs(526140).toString("yyyy-MM-dd hh:mm")

And the resulting output:

2010-11-07 01:09
2010-11-07 01:09

I've been banging my head on the keyboard trying to figure this out. What am I doing incorrectly?

Was it helpful?

Solution

it probably depends on your locale settings:

seems DST in the United States and other countries ended on 2010-11-07...

so i'd bet it's a result of that.

if you get any strange values from doing calculations with dates, always check if there hasn't been DST change or a leap year and consider different locales. sadly time isn't always as linear as it seems.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top