pgorod / power-todoist-card

Improved Todoist card for Home Assistant Lovelace UI.
MIT License
20 stars 7 forks source link

[BUG] Timezone ignored, all due dates are 7 hours too early (Arizona) #16

Open arretx opened 2 weeks ago

arretx commented 2 weeks ago

In my powertodoist-card, due dates are off by 7 hours (Arizona). I looked through the powertodoist-card.js code and it looks like there's provision for time and date, but then I checked the data being served by Todoist through Postman and found that all of the due date timezones are set to null by default for the SYNC API, but not for the REST API. The REST API doesn't deliver the same information, however, so it would probably break the entire card if I switched the GET call to the REST API.

I suspect that since there's nothing in that timezone field, the default 0 time is being used which is rendering 7 hours off in my browser.

Todoist has a timezone setting in the app and on the website and I have it set correctly.

Is there code that I can add to the js file that will add 7 hours to the displayed time since it's not picking up the correct information?

arretx commented 2 weeks ago

I found a workaround by adding UTC: to the front of the mask in the dateFormat call on line 1005. Not sure if this is the best method, but it seems to work.

pgorod commented 2 weeks ago

There's a date_format option you can use in YAML. It defaults to "mmm dd H:mm"

Can you put the UTC in there? How, exactly?

I'm wondering if this would solve the problem (in which case we could just improve documentation), or maybe we need to work the code of that option a bit to make it effective.

arretx commented 2 weeks ago

The only place I see anything about date_format is in the variables in reference to submitting actions.

Looks like it's line 1002.

[this.myConfig.show_dates && item.due ? dateFormat(item.due.date, "UTC: 🗓 dd-mmm H'h'MM") : [],

...where I added UTC:

I don't quite understand how dates work in code, so the best I can do is screw around with it without knowing the ramifications. ;).

pgorod commented 2 weeks ago

Instead of changing it in the code, you can try a show_dates in the yaml configuration, with a value including "UTC".