Re: [Interest] Relashionship between time_t and QDateTime

2013-08-28 Thread Calogero Mauceri
On 8/27/2013 11:01 PM, Constantin Makshin wrote: The original Calogero's message mentioned a file from December 2007, a date outside of DST (unless there's a country that uses DST during winter). Now it's August, so the DST is active and during UTC - local time conversion Windows adds that 1

Re: [Interest] Relashionship between time_t and QDateTime

2013-08-28 Thread Constantin Makshin
I looked at the MSVC 2012 runtime library sources and it appears that localtime() is not as bad as I thought. It applies the DST offset if daylight saving is found to be active. It also tries some dark magic to calculate historical DST transitions (I'm not sure I'm allowed to post fragments of

Re: [Interest] Relashionship between time_t and QDateTime

2013-08-27 Thread Calogero Mauceri
On 8/26/2013 7:30 PM, Thiago Macieira wrote: On segunda-feira, 26 de agosto de 2013 17:42:58, Calogero Mauceri wrote: QDateTime myDateTime = QDateTime::fromTime_t(f_mtime); The date time printed doing a myDateTime.toString() is Wed Dec 5 12:36:18 2007 Retrieving the last modified

Re: [Interest] Relashionship between time_t and QDateTime

2013-08-27 Thread Frank Hemer
On Tuesday 27 August 2013 10:19:06 Calogero Mauceri wrote: On 8/26/2013 7:30 PM, Thiago Macieira wrote: On segunda-feira, 26 de agosto de 2013 17:42:58, Calogero Mauceri wrote: QDateTime myDateTime = QDateTime::fromTime_t(f_mtime); The date time printed doing a myDateTime.toString() is

Re: [Interest] Relashionship between time_t and QDateTime

2013-08-27 Thread Thiago Macieira
On terça-feira, 27 de agosto de 2013 10:19:06, Calogero Mauceri wrote: Unfortunately the problem is still there even if I force a toUTC() conversion for both QDateTime, either the one initialized from time_t or the one returned by QFileInfo :/. Similarly QDateTime dtFromTime_t =

Re: [Interest] Relashionship between time_t and QDateTime

2013-08-27 Thread Constantin Makshin
When converting time from UTC to local time, Windows uses the *current* state of daylight saving, not one that was active at the time the original timestamp is pointing to. On 08/27/2013 01:55 PM, Frank Hemer wrote: On Tuesday 27 August 2013 10:19:06 Calogero Mauceri wrote: On 8/26/2013 7:30

Re: [Interest] Relashionship between time_t and QDateTime

2013-08-27 Thread Thiago Macieira
On terça-feira, 27 de agosto de 2013 21:40:29, Constantin Makshin wrote: When converting time from UTC to local time, Windows uses the *current* state of daylight saving, not one that was active at the time the original timestamp is pointing to. Hmm... we have two versions of the code:

Re: [Interest] Relashionship between time_t and QDateTime

2013-08-27 Thread Daniel Bowen
=bowensite@qt-project.org] On Behalf Of Constantin Makshin Sent: Tuesday, August 27, 2013 11:40 AM To: Qt Interest Subject: Re: [Interest] Relashionship between time_t and QDateTime When converting time from UTC to local time, Windows uses the *current* state of daylight saving, not one

Re: [Interest] Relashionship between time_t and QDateTime

2013-08-27 Thread Constantin Makshin
[mailto:interest-bounces+qtmailinglist1=bowensite@qt-project.org] On Behalf Of Constantin Makshin Sent: Tuesday, August 27, 2013 11:40 AM To: Qt Interest Subject: Re: [Interest] Relashionship between time_t and QDateTime When converting time from UTC to local time, Windows uses the *current* state

Re: [Interest] Relashionship between time_t and QDateTime

2013-08-27 Thread Thiago Macieira
On terça-feira, 27 de agosto de 2013 22:17:07, Constantin Makshin wrote: In MSVC's runtime library — yes, gmtime() is broken. From MSDN (http://msdn.microsoft.com/en-us/library/vstudio/0z9czt0w.aspx): Return Value A pointer to a structure of type tm. The fields of the returned structure

Re: [Interest] Relashionship between time_t and QDateTime

2013-08-27 Thread Thiago Macieira
On terça-feira, 27 de agosto de 2013 22:59:44, Constantin Makshin wrote: Windows can store information about daylight saving transitions for past years, but always uses one for the current year. And since daylight saving transition dates and time tend to slightly drift from year to year,

Re: [Interest] Relashionship between time_t and QDateTime

2013-08-27 Thread Daniel Bowen
One key is in the Remarks section of SystemTimeToTzSpecificLocalTime()'s documentation (http://msdn.microsoft.com/en-us/library/windows/desktop/ms724949(v=vs.85).aspx): The SystemTimeToTzSpecificLocalTime function may calculate the local time incorrectly under the following conditions:

Re: [Interest] Relashionship between time_t and QDateTime

2013-08-27 Thread Daniel Bowen
One other note: And since daylight saving transition dates and time tend to slightly drift from year to year, there's absolutely no guarantees of getting correct time conversion results; in general case 1-hour error is nearly inevitable. The timezone structure on Windows tracks the ST-DT

Re: [Interest] Relashionship between time_t and QDateTime

2013-08-27 Thread Constantin Makshin
The original Calogero's message mentioned a file from December 2007, a date outside of DST (unless there's a country that uses DST during winter). Now it's August, so the DST is active and during UTC - local time conversion Windows adds that 1 hour Calogero is seeing. DST gets incorrectly applied

Re: [Interest] Relashionship between time_t and QDateTime

2013-08-27 Thread Constantin Makshin
Well, after some thoughts and looking at Qt 4.8 source code (Gitorious, at least its web interface, was closed for maintenance yesterday in the evening) my guess is that the problem is caused by Microsoft's implementation of localtime() (QDateTime::fromTime_t() ends up in utcToLocal() which on

Re: [Interest] Relashionship between time_t and QDateTime

2013-08-27 Thread Thiago Macieira
On quarta-feira, 28 de agosto de 2013 08:51:46, Constantin Makshin wrote: Well, after some thoughts and looking at Qt 4.8 source code (Gitorious, at least its web interface, was closed for maintenance yesterday in the evening A better browser:

Re: [Interest] Relashionship between time_t and QDateTime

2013-08-27 Thread Constantin Makshin
Damn, I just realized that I won't be able to test MSVC's localtime() because Russia isn't using DST transitions since 2011, making it impossible to distinguish DST is not used for past years from localtime() completely ignores daylight saving information. Someone else has to do it. On Aug 28,

Re: [Interest] Relashionship between time_t and QDateTime

2013-08-27 Thread Thiago Macieira
On quarta-feira, 28 de agosto de 2013 09:20:30, Constantin Makshin wrote: Damn, I just realized that I won't be able to test MSVC's localtime() because Russia isn't using DST transitions since 2011, making it impossible to distinguish DST is not used for past years from localtime() completely

[Interest] Relashionship between time_t and QDateTime

2013-08-26 Thread Calogero Mauceri
Hi all, I'm facing the following problem when initializing a QDateTime with time_t value. I get the last modified timestamp of a file as time_t value ... time_t mtime; struct stat statbuf; fstat(fd, statbuf); mtime = statbuf.st_mtime; ... Then I use that mtime value to

Re: [Interest] Relashionship between time_t and QDateTime

2013-08-26 Thread Thiago Macieira
On segunda-feira, 26 de agosto de 2013 17:42:58, Calogero Mauceri wrote: QDateTime myDateTime = QDateTime::fromTime_t(f_mtime); The date time printed doing a myDateTime.toString() is Wed Dec 5 12:36:18 2007 Retrieving the last modified information using QFileInfo, the result is

Re: [Interest] Relashionship between time_t and QDateTime

2013-08-26 Thread Constantin Makshin
As far as I understand the description of QDateTime::fromTime_t(), it automatically converts the passed value from UTC to local time. On the other hand, QFileInfo::lastModified() may immediately return the value retrieved from the system without any transformations. On Aug 26, 2013 7:43 PM,