Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
gmckeown opened this issue Sep 8, 2023 · 0 comments
Open

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

gmckeown opened this issue Sep 8, 2023 · 0 comments

Comments

@gmckeown
Copy link

gmckeown commented Sep 8, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant