PQt4 QDatetime: ¿Por qué obtengo la misma respuesta cuando uso addSecs() con dos valores de segundos diferentes?

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 segundos values to the QDateTime object produces the same time.

Aquí tienes un ejemplo del problema:

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")

Y la salida resultante:

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?

preguntado el 03 de mayo de 12 a las 18:05

yo obtengo 2010-11-07 01:09 y 2010-11-07 02:09 - two different values -

If I use QTime objects I get 01:09 y 02:09 when adding those seconds values. Otherwise it's always just as the question states. -

I used the code from your question, i.e. QDateTime -

:( I've even tried with Python 2.7.2 with the same result. Thanks for trying. -

1 Respuestas

it probably depends on your locale settings:

parece DST in the United States and other countries terminó el 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.

contestado el 03 de mayo de 12 a las 21:05

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.