This forum has been archived. All content is frozen. Please use KDE Discuss instead.

time format

Tags: None
(comma "," separated)
glupie
Registered Member
Posts
67
Karma
0
OS

time format

Wed Jul 20, 2016 12:14 am
Recently upgrading from KDE 4 to KDE 5 (far less painful that past major upgrades, and I have to say that it looks really good).

The are annoyances of course, and one that is on my mind now is the time format of the system clock widget. I want a simple clock with nothing but the time in %H:%M:%S format, which was what I had with KDE4 (formats are from 'man date').

With KDE 5, the format is %k:%M:%S - which means that twice a day the number of digits displayed changes. UGH! I would really like some way to return the the KDE 4 behavior. Is there some way of doing that, and if there is no easy fix, can someone point me to the file that controls that widget, I might be able to patch it (no guarantee of success - I am not a programmer, but I am certainly going to try).
User avatar
Rog131
Registered Member
Posts
828
Karma
10

Re: time format

Wed Jul 20, 2016 9:55 am
KDE Brainstorm: Improve Locale Configuration in Plasma 5 - viewtopic.php?f=83&t=124741

At here, editing the digital clock qml scripts to get what I want.

My Digital Clock
(This is with the plasma 5.7.2.)

Plasma 5 is using qml to draw the clocks. QML date and time formats can be found from the http://doc.qt.io/qt-5/qml-qtqml-date.html .

date:

Image

time:

Image


The plasma digital clock qml scripts are at the /usr/share/plasma/plasmoids/org.kde.plasma.digitalclock/. The user can edit the codes at the /usr/share/plasma/plasmoids/org.kde.plasma.digitalclock/ but the plasma updates will overwrite the edits.

A bit better way is to copy the scripts to the users home and rename the digital clock.

Copying the /usr/share/plasma/plasmoids/org.kde.plasma.digitalclock/ to the ~/.local/share/plasma/plasmoids/org.kde.plasma.mydigitalclock/.

Editing the ~/.local/share/plasma/plasmoids/org.kde.plasma.mydigitalclock/metadata.desktop:

Code: Select all
[Desktop Entry]
Encoding=UTF-8
Name=My Digital Clock
Name[x-test]=xxMy Digital Clockxx

Comment=Time displayed in an advanced digital format
Comment[x-test]=xxTime displayed in an advanced digital formatxx

Icon=preferences-system-time
Type=Service
X-KDE-ParentApp=
X-KDE-PluginInfo-Author=
X-KDE-PluginInfo-Email=
X-KDE-PluginInfo-License=GPL
X-KDE-PluginInfo-Name=org.kde.plasma.mydigitalclock
X-KDE-PluginInfo-Version=3.0
X-KDE-PluginInfo-Website=plasma.kde.org
X-KDE-ServiceTypes=Plasma/Applet
X-Plasma-API=declarativeappletscript
X-KDE-PluginInfo-Category=Date and Time
X-Plasma-Provides=org.kde.plasma.time,org.kde.plasma.date

X-Plasma-MainScript=ui/main.qml
X-Plasma-RemoteLocation=


Editing ~/.local/share/plasma/plasmoids/org.kde.plasma.mydigitalclock/contents/ui/DigitalClock.qml

Time format:

line 422
Changing
Code: Select all
return Qt.formatTime(currentTime, main.timeFormat);

to
Code: Select all
return Qt.formatTime(currentTime, "hh:mm");


Date format:

line 537
Changing
Code: Select all
dateLabelLeft.text = Qt.formatDate(main.currentTime, main.dateFormat);

to
Code: Select all
dateLabelLeft.text = Qt.formatDate(main.currentTime, "MM/dd");


line 539
Changing
Code: Select all
dateLabel.text = Qt.formatDate(main.currentTime, main.dateFormat);

to
Code: Select all
dateLabel.text = Qt.formatDate(main.currentTime, "MM/dd");



Restarting the plasmashell or log out - log in.

Adding the My Digital clock to the panel:

Image

Image

My Digital Clock can be added to the My Panel: viewtopic.php?f=66&t=133073&hilit=panel#p357392


More of time&date formats:
- Wrong time format in plasma5 lock screen: viewtopic.php?f=289&t=130484
- How to set Monday as the first day of calendar widget?: viewtopic.php?f=66&t=131758


Calendar background

The digitalclock calendar qml code is at CalendarView.qml

A picture can be slipped to the calendar by adding a picture and few code lines ( http://doc.qt.io/qt-5/qml-qtquick-image.html ):

Code: Select all
       Image {
        source: "Background.jpg"
    }


That is:

Code: Select all
...
    onIsExpandedChanged: {
        if (!isExpanded) {
            // clear all the selections when the plasmoid is hiding
            monthView.resetToToday();
        }
    }

       Image {
        source: "Background.jpg"
    }


    Item {
        id: agenda
...


After plasmashell restart:
Image


Monthly calendar background image

Monthly background images can be added by

Code: Select all
    Image {
        source: "images/" + monthView.currentDate.getMonth()
    }


That is:
Code: Select all
....
    onIsExpandedChanged: {
        if (!isExpanded) {
            // clear all the selections when the plasmoid is hiding
            monthView.resetToToday();
        }
    }
   
    Image {
        fillMode: Image.Stretch
        anchors.fill: parent
        source: "images/" + monthView.currentDate.getMonth()
    }
       Image {
        fillMode: Image.Stretch
        anchors.fill: parent
        source: "images/Matte.png"
    }


    Item {
        id: agenda
...


Monthly pictures are at Images subdirectory:

Image

and the names are 0,1,2,..11.

Image

To get a bit better readability there is a matte image:

Image

After plasmashell restart:

Image


------------------------EDIT-------------------------------


With the Plasma 5.11.

The KOrganizer starting with the mouse middle click: https://youtu.be/j2gslAS8tFI

Code of .../contents/ui/CalendarView.qml: https://pastebin.com/M15CZXSv


------------------------EDIT #2-------------------------------


With the Plasma 5.14

Digital clock time is
Code: Select all
return Qt.formatTime(currentTime, main.timeFormat);

My Digital clock time is:
Code: Select all
return Qt.formatTime(currentTime, "hh:mm");


Digital clock date is
Code: Select all
dateLabel.text = Qt.formatDate(main.currentTime, main.dateFormat);

My Digital clock date is
Code: Select all
dateLabel.text = Qt.formatDate(main.currentTime, "MM/dd");


i.e:
Code: Select all
--- /usr/share/plasma/plasmoids/org.kde.plasma.digitalclock/contents/ui/DigitalClock.qml   2018-11-27 19:50:44.000000000 +0200
+++ /home/rog131/.local/share/plasma/plasmoids/org.kde.plasma.mydigitalclock/contents/ui/DigitalClock.qml   2019-01-09 12:26:26.786016739 +0200
@@ -498,7 +498,8 @@
                     var currentTime = new Date(msUTC + (dataSource.data[plasmoid.configuration.lastSelectedTimezone]["Offset"] * 1000));
 
                     main.currentTime = currentTime;
-                    return Qt.formatTime(currentTime, main.timeFormat);
+                    //return Qt.formatTime(currentTime, main.timeFormat);
+                    return Qt.formatTime(currentTime, "hh:mm");
                 }
 
                 verticalAlignment: Text.AlignVCenter
@@ -610,7 +611,8 @@
 
 
         if (main.showDate) {
-            dateLabel.text = Qt.formatDate(main.currentTime, main.dateFormat);
+            //dateLabel.text = Qt.formatDate(main.currentTime, main.dateFormat);
+            dateLabel.text = Qt.formatDate(main.currentTime, "MM/dd");
         } else {
             // clear it so it doesn't take space in the layout
             dateLabel.text = "";


Result:

Image

Last edited by Rog131 on Wed Jan 09, 2019 11:16 am, edited 3 times in total.
User avatar
RodJ
Registered Member
Posts
3
Karma
0
OS

Re: time format

Fri May 26, 2017 1:08 pm
Thanks Rog131 for figuring this all out.

However, I tried this in Kubuntu 16.04, Plasma 5.8.6 (backported PPA) but could not get it to work. The "My Digital Clock" widget didn't even appear in the Add Widgets dialog. After double checking everything I had a hunch that the metadata.json file in the same folder as the metadata.desktop file needed to be edited in a similar manner so they matched. I edited lines 10, 19, 51, 55 (I think this was the key line), 57, 140.

After editing metadata.json and restarting, the "My Digital Clock" widget did appear in the Add Widgets dialog and it is working perfectly. I have my time displayed now as "12.05 am" (lowercase am/pm) and my date as "Sat, 27 May 2017" (abbreviated day string) ... exactly what I wanted. ;D
User avatar
RodJ
Registered Member
Posts
3
Karma
0
OS

Re: time format

Tue Jul 30, 2019 12:45 pm
Hi DrPsyche,

I abandoned this fiddly approach to getting a more flexible time/date display some time ago. I now use an excellent Plasma widget called "Event Calendar" to replace the standard time/date display. This widget has a wealth of configuration options including displaying the time/date in different colours if you want. It also has weather/calendar information too.

To install the widget just click on the "Get new widgets" box at the bottom of the add widgets dialog and search for "Event Calendar".

Hope this helps.


Bookmarks



Who is online

Registered users: Bing [Bot], claydoh, Google [Bot], Yahoo [Bot]