Kodi display Current time and duration in hour, minutes and seconds

Hi

How do i change so Kodi display current time and duration in hours, minutes and seconds instead of seconds in Basic UI?
The code is default “Current Time [%d %unit%]” and “Duration [%d %unit%]”

/Jerry

1 Like

Yup me too, dont like the seconds for the time.

/Jerry

Thanks to @cweitkamp as I looked for something like this not long ago and it helped me today. :smile: Nevertheless I would like to further elaborate the topic by adding a few details:

First of all, install the Javascript Transformation via Paper UI.

kodi.items

Number:Time myKodi_currenttime      "Current Time [JS(uptime.js):%s]"  { channel="kodi:kodi:myKodi:currenttime" }
Number:Time myKodi_duration         "Duration [JS(uptime.js):%s]"      { channel="kodi:kodi:myKodi:duration" }

uptime.js
(put into transform folder; all credits go to @KjetilA for his code; I have added the missing seconds to it and simplified it a bit :wink:)

(function(seconds) {
  var retval = "";
  var days = Math.floor(seconds / (24 * 60 * 60));
  seconds = seconds % (24 * 60 * 60);
  var hours = Math.floor(seconds / (60 * 60));
  seconds = seconds % (60 * 60);
  var minutes = Math.floor(seconds / 60);
  seconds = seconds % 60;

  if (days > 0) {
    retval += days + " day";
    if (days > 1) {
      retval += "s";
    }
    retval += " ";
  }

  retval += hours + ":";

  if (minutes < 10) {
    retval += "0";
  }
  retval += minutes + ":";

  if (seconds < 10) {
    retval += "0";
  }
  retval += seconds;

  return retval;
})(input);

I hope this helps. Of course there is a quite compact version of it as well (thanks to @Olymp; also without seconds).

1 Like

Miba, there are some very long seconds on this .js, can it be redused to 2 digits?

/Jerry

I am not sure if I understand you right. The original value is the total number of seconds which will be converted to something like DD days HH:MM:SS or HH:MM:SS if it is below 1 day.

Nevermind, my bad. Works just i wanted it.

/Jerry

Great solution. Thank for posting your results. This will help until we will get a solution inside the framework.

You’re welcome. As mentioned it was your first reply that pushed me in the right direction.

It’s not working for me

In the panel I see NaN:NaN:NaN for both the Current time and Duration.

My items:

Number:Time KodiCurrentTime      "Current Time [JS(uptime.js):%s]"  { channel="kodi:kodi:KodiLivingRoom:currenttime" }
Number:Time KodiDuration         "Duration [JS(uptime.js):%s]"      { channel="kodi:kodi:KodiLivingRoom:duration" }

And I’ve copied the java code to uptime.js in the transformation folder;

I’m seeing this in the event.log when I start a movie in Kodi

2019-05-16 22:46:10.669 [vent.ItemStateChangedEvent] - KodiDuration changed from -1 s to 0 s

2019-05-16 22:46:19.653 [vent.ItemStateChangedEvent] - KodiCurrentTime changed from 0 s to 1848 s

2019-05-16 22:46:19.654 [vent.ItemStateChangedEvent] - KodiDuration changed from 0 s to 7338 s

2019-05-16 22:46:29.663 [vent.ItemStateChangedEvent] - KodiCurrentTime changed from 1848 s to 1858 s

2019-05-16 22:46:39.711 [vent.ItemStateChangedEvent] - KodiCurrentTime changed from 1858 s to 1868 s

What could I be missing?