britkat1980 / giv_tcp

TCP connection (from inverter) and MQTT implementation
78 stars 37 forks source link

AM/PM display is incorrect in Smart Home Display #113

Closed gmckeown closed 11 months ago

gmckeown commented 1 year ago

In the smart home display, 12 noon shows as 12am -- this should be 12 pm. The incorrect logic is in updateTimeStamp() in app.js.

A potential fix is to replace:

let suffix = 'am';

if (hours > 12) {
  hours -= 12;
  suffix = 'pm';
} else if (hours === 0) {
  hours = 12;
}

With:

const suffix = (hours < 12) ? 'am': 'pm';
hours = hours % 12;
hours = hours ? hours : 12;
minutes = minutes < 10 ? '0' + minutes : minutes;

Another way to pad the minutes:

minutes = minutes.toString().padStart(2, '0');

Haven't checked whether you've got any JS version constraints or style guidelines, so apologies if any of this doesn't fit in!

Also note that an alternative to the whole function might be to use date.toLocaleTimeString with hour12 = true.

gmckeown commented 1 year ago

Your repo came up first in a Google search for "givtcp github", so not sure if it was best to raise the issue here or the main givtcp repo... have raised against both.

britkat1980 commented 11 months ago

fixed in 2.4.0