Skip to content
Permalink
Browse files
[qtbase] Detect system time zone from linked symlinks.
  • Loading branch information
dcaliste committed May 21, 2019
1 parent a002c4e commit 4c5e5b94281ead3a702e5ed5258dcb6e5df357d4
Showing with 11 additions and 4 deletions.
  1. +11 −4 src/corelib/tools/qtimezoneprivate_tz.cpp
@@ -1013,11 +1013,18 @@ QByteArray QTzTimeZonePrivate::systemTimeZoneId() const

// On other distros /etc/localtime is symlink to real file so can extract name from the path
if (ianaId.isEmpty()) {
const QString path = QFile::symLinkTarget(QStringLiteral("/etc/localtime"));
if (!path.isEmpty()) {
QString path = QFile::symLinkTarget(QStringLiteral("/etc/localtime"));
int index;
int iteration = 0;
// Symlink may point to another symlink etc. before being under zoneinfo/
while (iteration < 5 && !path.isEmpty()
&& (index = path.indexOf(QLatin1String("/zoneinfo/"))) < 0) {
path = QFile::symLinkTarget(path);
iteration += 1;
}
if (!path.isEmpty() && index >= 0) {
// /etc/localtime is a symlink to the current TZ file, so extract from path
int index = path.indexOf(QLatin1String("/zoneinfo/")) + 10;
ianaId = path.mid(index).toUtf8();
ianaId = path.mid(index + 10).toUtf8();
}
}

0 comments on commit 4c5e5b9

Please sign in to comment.