lozzd / octopus-energy-rates-card

This lovelace card for Home Assistant displays the Octopus Energy rate prices per each 30 minute slot
MIT License
60 stars 22 forks source link

Midnight as 0 instead of 24 #6

Closed mateuszdrab closed 1 year ago

mateuszdrab commented 1 year ago

Hey

Thanks for developing and maintaining the card, I've just installed it as I'm getting on the Octopus Agile tariff but there is one thing that bothers me about it.

I was wondering if you could implement a toggle to display midnight as hour 0 instead of 24? I don't know if it's just me, but 24 is an odd hour and just doesn't sound right, standard timestamps are always 0 hour based and so is the source of this sensor as shown below so it would make sense to have it display the time in the same way.

- from: '2023-03-11T00:00:00+00:00'
  to: '2023-03-11T00:30:00+00:00'
  rate: 34.27914

Thanks

lozzd commented 1 year ago

I noticed this as well and thought it was weird. I didn't write that bit of code originally but it seems to be using time formatting that comes from Home Assistant based on your locale.

For example, my phone actually does show 00 but my laptop shows 24. My phone is set to use 12 hour clock, but the card shows in 24 hour format.

I'd need to dig in a bit more to figure out if that's something that can be changed on the code side or if it's respecting some wider HA or browser setting.

Screenshot_20230311-235235

lozzd commented 1 year ago

https://github.com/lozzd/octopus-energy-rates-card/blob/5497fb37ba2d838ed7621db3dedfb36e858ea429/octopus-energy-rates-card.js#L128

lozzd commented 1 year ago

https://stackoverflow.com/questions/68646411/date-tolocalestringen-us-hour12-false-is-providing-midnight-as-24

Looks like there's a workaround I can add to fix this

mateuszdrab commented 1 year ago

It's a weird bug, I had a quick look through the code and noticed the date formatting is offloaded to the browser so tried changing language in Home Assistant but I think this probably is dependent on the browser language which might come from browser settings or the OS itself... Either way, would be great if you can work around it.

lozzd commented 1 year ago

Well, I tried and failed to fix this - I found https://stackoverflow.com/a/72920612 which says:

The hourCycle and hour12 options work as described in ECMA-402 §11.1.1 #40. The way they work in practice seems to be at odds with the specification.

Which is a bit annoying.

I've somewhat given up for now and added a new option, hour12 for showing the rates as a 12 hour clock instead, totally ignoring the problem instead. You can always put that back to false if you'd prefer your 24 hour clock, but with the hour as 24....

mateuszdrab commented 1 year ago

Well, I tried and failed to fix this - I found https://stackoverflow.com/a/72920612 which says:

The hourCycle and hour12 options work as described in ECMA-402 §11.1.1 #40. The way they work in practice seems to be at odds with the specification.

Which is a bit annoying.

I've somewhat given up for now and added a new option, hour12 for showing the rates as a 12 hour clock instead, totally ignoring the problem instead. You can always put that back to false if you'd prefer your 24 hour clock, but with the hour as 24....

Couldn't you just replace 24: for 00: in the string? It's weird that I never saw this formatting before.

Lots of other places in Home Assistant doing time formatting and this is the only card with this issue... Perhaps they do it using a different way?