X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fsupport%2Flyxtime.cpp;h=5415ac4eeb034057234b363d3931d7d004ca40ba;hb=28be7d552f62cc02fa86d7f79201d089bfb2d7b5;hp=c302531e2e0b0eb2104450bd24958d3a146ffef8;hpb=0dee3eff18078be7b931a3a409197f3f4dcc43b4;p=lyx.git diff --git a/src/support/lyxtime.cpp b/src/support/lyxtime.cpp index c302531e2e..5415ac4eeb 100644 --- a/src/support/lyxtime.cpp +++ b/src/support/lyxtime.cpp @@ -40,12 +40,23 @@ string const formatted_time(time_t t, string const & fmt) } -time_t from_ctime(string t) +docstring formatted_datetime(time_t t, string const & fmt) +{ + 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_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) t = trim(t, " \t\r\n"); -#if QT_VERSION >= 0x040400 // toDateTime() is too stupid to recognize variable amounts of // whitespace (needed because ctime() outputs double spaces before // single digit day numbers and hours) @@ -58,43 +69,8 @@ time_t from_ctime(string t) << "´ (invalid format)"); return static_cast(-1); } + loc_dt.setTimeSpec(Qt::UTC); return loc_dt.toTime_t(); -#elif defined(_WIN32) -#error "The minimum required Qt version on windows is Qt 4.4." -#else - // strptime() is not available on windows (defined by POSIX) - - // strptime() uses the current locale, so we need to switch to "C" - LYXERR(Debug::LOCALE, "Setting LC_ALL and LC_TIME to C"); - string oldLC_ALL = getEnv("LC_ALL"); - string oldLC_TIME = getEnv("LC_TIME"); - if (!setEnv("LC_ALL", "C")) - LYXERR(Debug::LOCALE, "\t... LC_ALL failed!"); - if (!setEnv("LC_TIME", "C")) - LYXERR(Debug::LOCALE, "\t... LC_TIME failed!"); - - struct tm loc_tm; - char const * const format = "%a%n%b%n%d%n%T%n%Y"; - char * remainder = strptime(t.c_str(), format, &loc_tm); - - LYXERR(Debug::LOCALE, "Resetting LC_ALL and LC_TIME"); - if(!setEnv("LC_TIME", oldLC_TIME)) - LYXERR(Debug::LOCALE, "\t... LC_TIME failed!"); - if (!setEnv("LC_ALL", oldLC_ALL)) - LYXERR(Debug::LOCALE, "\t... LC_ALL failed!"); - - if (!remainder) { - LYXERR(Debug::LOCALE, "Could not parse `" << t - << "´ (invalid format)"); - return static_cast(-1); - } - if (*remainder != '\0') { - LYXERR(Debug::LOCALE, "Could not parse `" << t - << "´ (excess characters)"); - return static_cast(-1); - } - return mktime(&loc_tm); -#endif } } // namespace support