bramkragten / custom-ui

Lovelace custom-ui
177 stars 69 forks source link

Card day names are one day behind #28

Open hawkeye217 opened 5 years ago

hawkeye217 commented 5 years ago

I'm using weather-card with Dark Sky, and all is working correctly except the day names are one day behind (for example, on Friday, the first entry on the card is "THU").

According to the docs for Date.parse here, (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parse),

Differences in assumed time zone

Given a date string of "March 7, 2014", parse() assumes a local time zone, but given an ISO format such as "2014-03-07" it will assume a time zone of UTC. Therefore Date objects produced using those strings will represent different moments in time unless the system is set with a local time zone of UTC. This means that two date strings that appear equivalent may result in two different values depending on the format of the string that is being converted (this behavior is changed in ECMAScript ed 6 so that both will be treated as local).

In your code you have this:

                              new Date(daily.datetime).toLocaleDateString(
                                lang,
                                {
                                  weekday: "short"
                                }
                              )

I changed it to:

                              new Date(daily.datetime).toLocaleDateString(
                                lang,
                                {
                                  timeZone: "UTC",
                                  weekday: "short"
                                }
                              )

And now the card displays the correct day. The daily.datetime fields are showing values like 2019-02-22T00:00:00, which seems to be correct. Is this issue specific to me or have others had this issue as well?

bbrendon commented 5 years ago

I've noticed this too. Right now the first day shown on my phone (ios) is "sat" and on my desktop computer it's "sun". Today is Easter Sunday.