From e04523f77be2a6d2b5ca708900857154b1eff902 Mon Sep 17 00:00:00 2001 From: Kornel Benko Date: Mon, 7 Jan 2013 15:46:47 +0100 Subject: [PATCH] Make change tracking in export to latex be independent of timezone --- src/Changes.cpp | 2 +- src/support/lyxtime.cpp | 3 ++- src/support/lyxtime.h | 2 +- src/tex2lyx/test/test-structure.tex | 4 ++-- src/tex2lyx/text.cpp | 8 +++----- 5 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/Changes.cpp b/src/Changes.cpp index 766b698a3a..29095f9b79 100644 --- a/src/Changes.cpp +++ b/src/Changes.cpp @@ -400,7 +400,7 @@ int Changes::latexMarkChange(otexstream & os, BufferParams const & bparams, } docstring chgTime; - chgTime += ctime(&change.changetime); + chgTime += asctime(gmtime(&change.changetime)); // remove trailing '\n' chgTime.erase(chgTime.end() - 1); diff --git a/src/support/lyxtime.cpp b/src/support/lyxtime.cpp index 9bdde9cb3a..f5290a2324 100644 --- a/src/support/lyxtime.cpp +++ b/src/support/lyxtime.cpp @@ -40,7 +40,7 @@ string const formatted_time(time_t t, string const & fmt) } -time_t from_ctime(string t) +time_t from_gmtime(string t) { // Example for the format: "Sun Nov 6 10:39:39 2011\n" // Generously remove trailing '\n' (and other whitespace if needed) @@ -57,6 +57,7 @@ time_t from_ctime(string t) << "´ (invalid format)"); return static_cast(-1); } + loc_dt.setTimeSpec(Qt::UTC); return loc_dt.toTime_t(); } diff --git a/src/support/lyxtime.h b/src/support/lyxtime.h index 620965aebc..fcb22bd135 100644 --- a/src/support/lyxtime.h +++ b/src/support/lyxtime.h @@ -34,7 +34,7 @@ std::string const formatted_time(time_t t, std::string const & fmt); * time zone and daylight saving time are the same as when \p t was created * by ctime(). */ -time_t from_ctime(std::string t); +time_t from_gmtime(std::string t); } // namespace support } // namespace lyx diff --git a/src/tex2lyx/test/test-structure.tex b/src/tex2lyx/test/test-structure.tex index 096da4140c..745872b363 100644 --- a/src/tex2lyx/test/test-structure.tex +++ b/src/tex2lyx/test/test-structure.tex @@ -107,9 +107,9 @@ An environment \end{quote} We also support change tracking: -\lyxadded{Hans Wurst}{Sun Nov 6 10:39:39 2011}{Added text} +\lyxadded{Hans Wurst}{Sun Nov 6 09:39:39 2011}{Added text} some parts remain -\lyxdeleted{Hans Wurst}{Sun Nov 6 10:39:55 2011}{This was the original text} +\lyxdeleted{Hans Wurst}{Sun Nov 6 09:39:55 2011}{This was the original text} some parts remain \section*{A starred section for floats} diff --git a/src/tex2lyx/text.cpp b/src/tex2lyx/text.cpp index 5df8ef255d..2ccc7cd7c6 100644 --- a/src/tex2lyx/text.cpp +++ b/src/tex2lyx/text.cpp @@ -3204,11 +3204,9 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, string localtime = p.getArg('{', '}'); preamble.registerAuthor(name); Author const & author = preamble.getAuthor(name); - // from_ctime() will fail if LyX decides to output the - // time in the text language. It might also use a wrong - // time zone (if the original LyX document was exported - // with a different time zone). - time_t ptime = from_ctime(localtime); + // from_gmtime() will fail if LyX decides to output the + // time in the text language. + time_t ptime = from_gmtime(localtime); if (ptime == static_cast(-1)) { cerr << "Warning: Could not parse time `" << localtime << "´ for change tracking, using current time instead.\n";