[Interest] QDateTime uses different time zone offset prior to UNIX epoch?

Christian Ehrlicher Ch.Ehrlicher at gmx.de
Sat Sep 21 08:17:05 CEST 2019


Am 21.09.2019 um 00:12 schrieb Thiago Macieira:
> On Friday, 20 September 2019 14:20:40 PDT Patrick Stinson wrote:
>> QDateTime initializes with a different time zone offset when passed a QDate
>> before versus after Jan 1 1970. The following line says it all:
>>
>> QDateTime(QDate(1969, 10, 14)).offsetFromUtc() != QDateTime(QDate(1970, 10,
>> 14)).offsetFromUtc()
>>
>> It seems to me that the offsets for these two QDateTime objects should be
>> equal. Otherwise, this makes initializing and storing dates difficult.
>>
>> I assume this is intentional. What is the rationale for this design
>> decision? Is there a workaround?
> Your test is not reliable. It works for less than half the planet and for just
> over half the year.
>
> Anyway, there's no workaround. This is done because the timezone databases are
> inaccurate before 1970. So we just return each timezone's standard time, not
> accounting for DST.
This is what I told him at the forum - mktime() on windows simply
returns the wrong dst value for 1969 (but linux does in this case).

Christian



More information about the Interest mailing list