Bug: Airtimes off by 24 hours.
I have only added like 5 tv shows to my lists so far but noticed all the air dates were off by a day, a day behind actual air date to be clear. I checked tmdb, imdb and both sources list the correct air date for shows but the date is inaccurate in Media Tracker. Noticed it was off by 24 hours on the demo as well. Server lang and Tmdb lang both set to en so not sure what could be causing this.
Funny… With my instance the notifications that I receive occur 24 hours before the actual air date.
I'm not JS savy and especially less so with Typescript but I believe maybe the issue has to do with this line in "items.ts"
const currentDateString = new Date().toISOString();
Apparently toISOString removes the TZ offset and the const gets used to carry the date to other parts such as the releaseDate.
I think it might be solved with changing it to something like,
const tzoffset = (new Date()).getTimezoneOffset() * 60000;
const currentDateString = (new Date(Date.now() - tzoffset)).toISOString();
but on that note, as I said I by no means any good with JS so this is a stab in the dark.
Date for notications is set here:
https://github.com/bonukai/MediaTracker/blob/0eabbd1c219ca8e92b892d09294c8929984ef87f/server/src/sendNotifications.ts#L85
Date.prototype.toISOString() converts date to UTC from your time zone. Maybe adding environment variable TZ to Docker may help, for example for New York TZ="America/New_York", this may be one part of the issue.
But main problem is that TMDB doesn't provide time zone for release date, see #115. There is regions argument in their API, but it doesn't seem to work.
For example, Euphoria S02E05 with US region has "air_date":"2022-02-06" and for UK is the same, but it should be 2022-02-07.
On Tv maze it's "airstamp":"2022-02-07T02:00:00+00:00", so this could be converted to your local time zone
Currently I pass time and timezone through volume binds into the container which when I use date inside the container shows the accurate time and timezone however when I pass TZ through an env into the container date spits out in UTC. I was going off the stamps in the logs which didn't seem to be impacted no matter what I did and I tried several different methods which lead me to think the .toISOString() was part of the culprit. I had ran across a Stackoverflow post made 10 years ago covering the very aspect of dates showing exactly 24 hours off using JS which lead me down this rabbit hole to begin with.
The fact that it shows 9 hours and counting makes me believe that timezone is being used but it's just exactly 24 hours off.
The Tv maze api shows what it looks like when no timezone is being used.
{"id":2304469,"url":"https://www.tvmaze.com/episodes/2304469/moon-knight-1x02-episode-2","name":"Episode 2","season":1,"number":2,"type":"regular","airdate":"2022-04-06","airtime":"","airstamp":"2022-04-06T12:00:00+00:00","runtime":47,"rating":{"average":null},"image":null,"summary":null,"_links":{"self":{"href":"https://api.tvmaze.com/episodes/2304469"}}}
The Tv maze api shows what it looks like when no timezone is being used.
{"id":2304469,"url":"https://www.tvmaze.com/episodes/2304469/moon-knight-1x02-episode-2","name":"Episode 2","season":1,"number":2,"type":"regular","airdate":"2022-04-06","airtime":"","airstamp":"2022-04-06T12:00:00+00:00","runtime":47,"rating":{"average":null},"image":null,"summary":null,"_links":{"self":{"href":"https://api.tvmaze.com/episodes/2304469"}}}
So for Moon Knight Tv maze does't have an airtime, but Trakt.tv has it. I wonder where did they get it from. TheTVDB also does't have an airtime.
.toISOString() is only used to filter aired dates. Release dates aren't transformed in any way on the server side, https://github.com/bonukai/MediaTracker/blob/0eabbd1c219ca8e92b892d09294c8929984ef87f/server/src/metadata/provider/tmdb.ts#L247 this is then saved in a database as is, and returned to the client
https://github.com/bonukai/MediaTracker/blob/0eabbd1c219ca8e92b892d09294c8929984ef87f/client/src/pages/Episodes.tsx#L57 and "Next episode in..." is also calculated on the client https://github.com/bonukai/MediaTracker/blob/0eabbd1c219ca8e92b892d09294c8929984ef87f/client/src/pages/Details.tsx#L545
What this returns to you, and what dates are displayed here
For me, in time zone Europe/London, TMDB returns 2022-03-30, and it's the same on demo page
So the api returns the correct air date.
However even your demo board shows me 24 hours behind the correct date.
which still leads me to believe this is a JS issue. I am America/Chicago, Can you force change your TZ and see if it will show you what I see?
Ok I am completely baffled so when I load up the demo board outside of my local network it shows the correct air date, however inside my local network it shows it as 24 hours behind. I have checked everything from browser time/tz, system, router the whole nine yards trying to figure out why it's doing that. Tried on different browsers as well.
Found it, it's exactly what that stackoverflow page I linked above stated. it's the hyphens ( - ) in the source date.
when replaced with slashes ( / ) the date shows accuratly.

that post may be 10 years old but still hold valid for some of us apparently. was pulling my hair out over this lol
Here's more on the matter. Exploring Unexpected Behavior With JavaScript Date Objects
I wanted to touch base on this issue. I have not had time to really mess around with it but I did check the demo board and the demo board shows the correct date for me now. Just as my statement above mentioned before my installed container as well as the demo board you host was both showing me the incorrect date while viewing within my own network, but showed the correct date if I was to view it from outside my internal network. NOW the demo board shows me the correct date from within my own internal network so whatever changes you made worked. can't wait till the next release to give it a try.!
You were right about parsing dates in ISO format with new Date(). I replaced it with parseISO from date-fns.
I will make a new release when I finish working on lists
Version bonukai/mediatracker:0.1.0-beta6 is now released, with lists, this bug fix, and more
Can confirm this did indeed fix the date issue. Great work! 👍
Agreed, this fixed the issue. Thanks for updating this!