Bug 355858

Summary: digital clock does not display anything
Product: [Plasma] plasmashell Reporter: M G Berberich <kde>
Component: Digital ClockAssignee: Plasma Bugs List <plasma-bugs>
Status: RESOLVED UPSTREAM    
Severity: normal CC: kde, mklapetek, plasma-bugs
Priority: NOR    
Version: 5.4.2   
Target Milestone: 1.0   
Platform: Debian testing   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:
Attachments: screenshot

Description M G Berberich 2015-11-24 20:31:04 UTC
Created attachment 95708 [details]
screenshot

In the panel it shows a small gray area or collapses to a vertical line if date should be shown.
As dekstop-widget it shows gray rectangle.
Startet with “plasmawindowed /usr/share/plasma/plasmoids/org.kde.plasma.digitalclock/” it shows a gray area.
In neither case a time or date is shown, in all cases the menu works and timezone-tooltips work.
Changing font, timezone(s) display of date or seconds or changing 12/24 hours does not change anything. Mousewheel does not help either. I can not find any debug message.

Probably some bug in this qml-junk.

BTW. The timezone selectors shows double vertical scrollbars in normal size.
Comment 1 M G Berberich 2015-11-24 20:32:59 UTC
package of plasma-workspace is 4:5.4.2-1+b1
This version can not be selected from the “Version” dropdown.
Comment 2 David Edmundson 2015-11-25 07:44:24 UTC
I've seen this before where the users /etc/localtime was broken

Can you show me the output of "ls -l /etc/localtime"
Comment 3 M G Berberich 2015-11-25 08:18:26 UTC
Sure

> ls -l /etc/localtime
-rw-r--r-- 1 root root 2309 Okt  7 17:51 /etc/localtime

It is set to Europe/Berlin.
Setting it to Europe/Helsinki temporarily does not help.
Comment 4 M G Berberich 2015-11-30 14:42:10 UTC
I tried the version from git. Does not work either.
Comment 5 David Edmundson 2015-11-30 14:43:35 UTC
That's not right, it should be a symlink to somewhere in /usr/share/timezone

like this: 

lrwxrwxrwx  1 root root     35 Oct 17 09:19 localtime -> ../usr/share/zoneinfo/Europe/London
Comment 6 M G Berberich 2015-11-30 15:29:44 UTC
That’s probably distribution dependent.
On Debian “dpkg-reconfigure tzdata” copies a file from /usr/share/zoneinfo/ to /etc. In my case “/usr/share/zoneinfo/Europe/Berlin“ and “/etc/localtime” are identical.
Comment 7 David Edmundson 2015-11-30 15:38:56 UTC
Timezones on Linux are apparently a mess. We have 4 different systems.
/etc/localtime is done by resolving the symlink path.

    // Check TZ env var first, if not populated try find it
    QByteArray ianaId = qgetenv("TZ");
    if (!ianaId.isEmpty() && ianaId.at(0) == ':')
        ianaId = ianaId.mid(1);

    // On Debian Etch and later /etc/localtime is real file with name held in /etc/timezone
    if (ianaId.isEmpty()) {
        QFile tzif(QStringLiteral("/etc/timezone"));
        if (tzif.open(QIODevice::ReadOnly)) {
            // TODO QTextStream inefficient, replace later
            QTextStream ts(&tzif);
            if (!ts.atEnd())
                ianaId = ts.readLine().toUtf8();
        }
    }

    // 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()) {
            // /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();
        }
    }

    // On some Red Hat distros /etc/localtime is real file with name held in /etc/sysconfig/clock
    // in a line like ZONE="Europe/Oslo" or TIMEZONE="Europe/Oslo"
    if (ianaId.isEmpty()) {
        QFile tzif(QStringLiteral("/etc/sysconfig/clock"));
        if (tzif.open(QIODevice::ReadOnly)) {
            // TODO QTextStream inefficient, replace later
            QTextStream ts(&tzif);
            QString line;
            while (ianaId.isEmpty() && !ts.atEnd() && ts.status() == QTextStream::Ok) {
                line = ts.readLine();
                if (line.startsWith(QLatin1String("ZONE="))) {
                    ianaId = line.mid(6, line.size() - 7).toUtf8();
                } else if (line.startsWith(QLatin1String("TIMEZONE="))) {
                    ianaId = line.mid(10, line.size() - 11).toUtf8();
                }
            }
        }
    }

could you set the date with timedatectl?

Finally, do you have the env var TZ set? is there a /etc/timezone?
Comment 8 M G Berberich 2015-11-30 21:38:32 UTC
Yes, I can query and set the timezone with timedatectl. It does not help to do so.
Yes, there is a /etc/timezone and it contains „Europe/Berlin“
TZ is unset. If I set TZ to “CET” the digital clock works.
Comment 9 M G Berberich 2015-12-03 21:09:54 UTC
I was wrong.
On Debian TZ is set to “:/etc/localtime”, this makes the clock fail.
Unsetting TZ makes the clock work, at least if startet with plasmawindowed
  TZ=   plasmawindowed /usr/share/plasma/plasmoids/org.kde.plasma.digitalclock/
does work.
Comment 10 Martin Klapetek 2015-12-04 19:51:07 UTC
> On Debian TZ is set to “:/etc/localtime”, this makes the clock fail.

That Qt code is clearly wrong. According to the glibc docs[1], ":/something/something" should be read as a path, not a timezone. The code however assumes it's the IANA ID, which then results in invalid timezone.

I'll see if I can get it fixed in Qt.

[1] http://www.gnu.org/software/libc/manual/html_node/TZ-Variable.html
Comment 11 Martin Klapetek 2015-12-04 21:08:42 UTC
Qt patch at https://codereview.qt-project.org/#/c/143091/
Comment 12 Martin Klapetek 2015-12-07 20:14:03 UTC
Fix in Qt 5.6 [1].

You might want to notify Debian Qt maintainers to backport this patch to their current package.

[1] - http://code.qt.io/cgit/qt/qtbase.git/commit/?id=891c98ebd63b5a5b079a1f5a2736a29d89afcbd2
Comment 13 M G Berberich 2015-12-07 20:32:36 UTC
① The patch does not solve the problem, it is a workaround, because a correctly set TZ-Variable gets ignored if it uses the “:”-syntax.

② digital-clock should fail more gracefully if it can not determine the timezone. At the moment the plasmoid gets totaly unusabel, even setting a timezone manually in the settings does not bring the display back.
Comment 14 Martin Klapetek 2015-12-07 20:53:56 UTC
...you're welcome.

> ① The patch does not solve the problem, it is a workaround, because a correctly set TZ-Variable gets ignored if it uses the “:”-syntax.

No.

>    QByteArray ianaId = qgetenv("TZ");
>    if (!ianaId.isEmpty() && ianaId.at(0) == ':')
>        ianaId = ianaId.mid(1);

If you set TZ=":Europe/Berlin", it will correctly return "Europe/Berlin".
The patch will ignore TZ=":/etc/localtime" because the timezone name
will get read from /etc/timezone (which is what should be happening).

It will not work if you put an absolute path into your TZ env var. Which is
not what any guide/manual encourages you to do so, so, honestly, I'd close
such bugreport as invalid. There are 4 other ways to read a system timezone,
just use one of those.

Feel free to submit another patch reading an absolute path correctly however.

> ② digital-clock should fail more gracefully

Yes.
Comment 15 M G Berberich 2015-12-07 21:27:09 UTC
How about:

  time_t tt = time(0);
  struct tm *tm = localtime(&tt);
  char tz[20];
  strftime(tz, 19, "%Z", tm);
  QByteArray ianaId(tz);
Comment 16 Martin Klapetek 2015-12-07 21:32:20 UTC
I'd suggest following through with this: https://wiki.qt.io/Qt_Contribution_Guidelines