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").
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?
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),In your code you have this:
I changed it to:
And now the card displays the correct day. The
daily.datetime
fields are showing values like2019-02-22T00:00:00
, which seems to be correct. Is this issue specific to me or have others had this issue as well?