Bug 308444 - %OLONGTIME template variable does not yield timezone information
Summary: %OLONGTIME template variable does not yield timezone information
Status: RESOLVED FIXED
Alias: None
Product: kmail2
Classification: Applications
Component: composer (show other bugs)
Version: 4.9.2
Platform: openSUSE Linux
: NOR normal
Target Milestone: ---
Assignee: kdepim bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-10-15 15:40 UTC by Thomas Baumgart
Modified: 2017-01-11 12:29 UTC (History)
5 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
Patch to messagelib that fixes the problem (5.55 KB, patch)
2017-01-11 04:00 UTC, Matt Whitlock
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Baumgart 2012-10-15 15:40:19 UTC
Using the following line in the reply-to template

On %ODATE %OTIMELONG you wrote:

yields the following results with the resp. date header found in the original mail presented on the line underneath:

On Monday 15 October 2012 13:34:36 you wrote:
Date: Mon, 15 Oct 2012 13:34:36 +0000

On Monday 15 October 2012 15:34:56 you wrote:
Date: Mon, 15 Oct 2012 15:34:56 +0200

These are taken from two different mails which I received and that are sent just 20 seconds apart. Replying to them shows a two hour difference though and no timezone information is given. I would expect that the first one above would show 15:34:36 as time which is my local time.

I also tried the other template vars %OLONGTIMEEN and %OTIME but that does not make a difference.
Comment 1 Laurent Montel 2012-10-15 15:58:28 UTC
could you paste header from theses two emails please ?
Comment 2 Thomas Baumgart 2012-10-15 16:14:39 UTC
The above 'Date:' lines are copied directly from the mail's headers. Do you need more? Which ones?
Comment 3 Laurent Montel 2012-10-17 14:51:16 UTC
I don't understand why there is this bug.
If there is a bug it's in kdelibs.
We use kdelibs code to return date
Comment 4 Sergiu Bivol 2014-06-13 09:09:19 UTC
I can confirm this behaviour on Kontact 4.14. 
The message headers contain the time in UTC (for example "Date: Fri, 13 Jun 2014 07:40:23 +0000") but I'm in another time zone (+3000). The person that sent the mail is in the same time zone as me.

I'd like to have %OTIME taking into account my tome zone, or if that is not possible, then at least a new command (something like "%OTIMELOCALTZ") that displays the time of the original message but converted to the local time zone.

This look more like a wish, but it causes inconsistencies in the Kontact interface: I see "10:40:23" as the time when the email was sent to me, but when replying to the same email I get %OTIME inserted as 07:40:23.
It also confuses the receiving party, because %OTIME does not print the time zone near the time it generates.
Comment 5 Sergiu Bivol 2014-06-13 09:10:18 UTC
Correction: Kontact 4.13
Comment 6 Ben 2016-01-05 00:05:56 UTC
See also https://bugs.kde.org/show_bug.cgi?id=355195
Comment 7 Matt Whitlock 2017-01-11 04:00:56 UTC
Created attachment 103342 [details]
Patch to messagelib that fixes the problem

QDateTime::time() returns a QTime, which conveys no time zone information. QLocale::toString(const QTime &, QLocale::FormatType) then assumes that the passed QTime is a local time. This causes a problem when processing a template in that the time zone information of the Date header in the original message is ignored, and the time part is then reinterpreted as a local time, which is incorrect.

Example illustrating the problem:

	Original message header:
	Date: Sun, 1 Jan 2017 13:31:25 -0600

	%OTIMELONG in reply template expands to:
	1:31:25 PM EST

QLocale apparently offers no method to format a QTime with a specific QTimeZone, so the best that can be done is to convert the QDateTime of the original message into a local time by calling QDateTime::toLocalTime().

After applying this fix, the above example becomes:

	Original message header:
	Date: Sun, 1 Jan 2017 13:31:25 -0600

	%OTIMELONG in reply template expands to:
	2:31:25 PM EST
Comment 8 Laurent Montel 2017-01-11 12:28:27 UTC
Git commit 2fafabbf7563c44d75f9e9b06b5314ef3dce4763 by Montel Laurent.
Committed on 11/01/2017 at 12:27.
Pushed by mlaurent into branch 'master'.

Apply patch from  Matt Whitlock + add autotest to validate it

QDateTime::time() returns a QTime, which conveys no time zone information. QLocale::toString(const QTime &, QLocale::FormatType) then assumes that the passed QTime is a local time. This causes a problem when processing a template in that the time zone information of the Date header in the original message is ignored, and the time part is then reinterpreted as a local time, which is incorrect.

Example illustrating the problem:

	Original message header:
	Date: Sun, 1 Jan 2017 13:31:25 -0600

	%OTIMELONG in reply template expands to:
	1:31:25 PM EST

QLocale apparently offers no method to format a QTime with a specific QTimeZone, so the best that can be done is to convert the QDateTime of the original message into a local time by calling QDateTime::toLocalTime().

After applying this fix, the above example becomes:

	Original message header:
	Date: Sun, 1 Jan 2017 13:31:25 -0600

	%OTIMELONG in reply template expands to:
	2:31:25 PM EST
Related: bug 355195, bug 366768

M  +52   -14   templateparser/autotests/templateparsertest.cpp
M  +3    -0    templateparser/autotests/templateparsertest.h
M  +8    -8    templateparser/src/templateparser.cpp

https://commits.kde.org/messagelib/2fafabbf7563c44d75f9e9b06b5314ef3dce4763
Comment 9 Laurent Montel 2017-01-11 12:29:23 UTC
Git commit 48ecc0d629cb55e2c45d4facd62b9012db385cff by Montel Laurent.
Committed on 11/01/2017 at 12:29.
Pushed by mlaurent into branch 'Applications/16.12'.

Apply patch from  Matt Whitlock + add autotest to validate it

QDateTime::time() returns a QTime, which conveys no time zone information. QLocale::toString(const QTime &, QLocale::FormatType) then assumes that the passed QTime is a local time. This causes a problem when processing a template in that the time zone information of the Date header in the original message is ignored, and the time part is then reinterpreted as a local time, which is incorrect.

Example illustrating the problem:

	Original message header:
	Date: Sun, 1 Jan 2017 13:31:25 -0600

	%OTIMELONG in reply template expands to:
	1:31:25 PM EST

QLocale apparently offers no method to format a QTime with a specific QTimeZone, so the best that can be done is to convert the QDateTime of the original message into a local time by calling QDateTime::toLocalTime().

After applying this fix, the above example becomes:

	Original message header:
	Date: Sun, 1 Jan 2017 13:31:25 -0600

	%OTIMELONG in reply template expands to:
	2:31:25 PM EST
Related: bug 355195, bug 366768
(cherry picked from commit 2fafabbf7563c44d75f9e9b06b5314ef3dce4763)

M  +52   -14   templateparser/autotests/templateparsertest.cpp
M  +3    -0    templateparser/autotests/templateparsertest.h
M  +8    -8    templateparser/src/templateparser.cpp

https://commits.kde.org/messagelib/48ecc0d629cb55e2c45d4facd62b9012db385cff