]> git.lyx.org Git - lyx.git/blobdiff - src/support/lyxtime.cpp
Fix Coverity false positive for null-pointer dereference
[lyx.git] / src / support / lyxtime.cpp
index f5290a2324a4cf67696c1928221ae81316958250..c155ed428d531426c66e16eb21777ff72c327aa4 100644 (file)
@@ -27,20 +27,23 @@ namespace support {
 
 time_t current_time()
 {
-       return time(0);
+       return time(nullptr);
 }
 
 
-string const formatted_time(time_t t, string const & fmt)
+docstring formatted_datetime(time_t t, string const & fmt)
 {
-       struct tm * loc_tm = localtime(&t);
-       char date[50];
-       strftime(date, sizeof(date), fmt.c_str(), loc_tm);
-       return string(date);
+       QString qres;
+       if (fmt.empty())
+               qres = QLocale().toString(QDateTime::fromTime_t(t),
+                                         QLocale::ShortFormat);
+       else
+               qres = QLocale().toString(QDateTime::fromTime_t(t), toqstr(fmt));
+       return qstring_to_ucs4(qres);
 }
 
 
-time_t from_gmtime(string t)
+time_t from_asctime_utc(string t)
 {
        // Example for the format: "Sun Nov  6 10:39:39 2011\n"
        // Generously remove trailing '\n' (and other whitespace if needed)