DateTime formatting - Item is one hour off

Hi,

I have some challenges with a DateTime item carrying my timeleft of a 3D-Print. Ich get the value from Octoprint as a value in seconds and pass it to my datetime item:
DateTime TDP_Timeleft "Druckzeit übrig [%1$tR]{channel=“mqtt:topic:MQTT_octoprint:remaining”}

Which leads to:

2020-09-30 09:38:49.603 [vent.ItemStateChangedEvent] - TDP_Timeleft changed from 1970-01-01T00:01:38.000+0000 to 1970-01-01T00:00:00.000+0000

wich is correct.
The output formatting of the last value (1970-01-01T00:00:00.000+0000) shows “01:00” in Sitemap and HabPanel. Has this something to do with timezones?
I know I can solve it by using rules and dummy items - but I prefer to do simple things like that without rules.

My guess is Yes.
Is your system time running on UTC +01:00?

I would not use a DateTime item for that information, showing the same as a number would show the remaining time in seconds, for better readability you could use a small javascript and show the seconds converted to something like 1 houre(s) 24 minute(s) 10 second(s) as a text item.

1 Like

I stumbled on that possibility as well, here is my second item wich, unfortunately, does not work either… :slight_smile:
Number TDP_Timeleft2 "Druckzeit übrig [JS(uptime.js):%s]" {channel="mqtt:topic:MQTT_octoprint:timeleft"}
with the following JScript:

(function(s){ 
    var d=s/86400|0;
    var h=(s%=86400)/3600|0;
    var m=(s%=3600)/60|0; 
    return ('0'+h).substr(-2)+':'+('0'+m).substr(-2);
  })(input)

This just gives my seconds - so the transformation does not work, probably because of small variable mismatches… :slight_smile:

I use a number item with no transformation and do show it on a sitemap as a text with the transformation.
Can’t say anything to your code, however mine looks like this:

function(i) {
    if(isNaN(i)) return "NA";
    var days = Math.floor(i/1440)
    var hours = Math.floor((i-days*1440)/60);
    var min = Math.floor((i-hours*60-days*1440)/1);
    return days+ " Tag(e) " +hours+" Std "+min+" Min";
})(input)

Note that it takes minutes as the input, so you need to change that accordingly.
Note2 The .is script needs to be in the /transform folder!

1 Like

There is a Quantity Type for this, Number:Time.
I don’t think that saves you any formatting transforms though.

Hmm, what a dummy I am… :slight_smile:
My (and yours as well) JScipt was working already - I was just not aware that I will see the result of th script NOT in the log but only in the UI. doh

1 Like