MediaTracker icon indicating copy to clipboard operation
MediaTracker copied to clipboard

Bug: Airtimes off by 24 hours.

Open SonomaGTS opened this issue 3 years ago • 13 comments

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.

SonomaGTS avatar Mar 24 '22 04:03 SonomaGTS

Funny… With my instance the notifications that I receive occur 24 hours before the actual air date.

saddle-gaudier-06 avatar Mar 29 '22 00:03 saddle-gaudier-06

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.

SonomaGTS avatar Apr 05 '22 02:04 SonomaGTS

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

bonukai avatar Apr 05 '22 13:04 bonukai

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. Screenshot 2022-04-05 094010 Screenshot 2022-04-05 094105 Screenshot 2022-04-05 094137 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"}}}

SonomaGTS avatar Apr 05 '22 14:04 SonomaGTS

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

bonukai avatar Apr 05 '22 16:04 bonukai

So the api returns the correct air date. Screenshot 2022-04-05 123509 However even your demo board shows me 24 hours behind the correct date. Screenshot 2022-04-05 123621 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?

SonomaGTS avatar Apr 05 '22 17:04 SonomaGTS

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.

SonomaGTS avatar Apr 06 '22 03:04 SonomaGTS

Found it, it's exactly what that stackoverflow page I linked above stated. it's the hyphens ( - ) in the source date. Screenshot 2022-04-05 231643 when replaced with slashes ( / ) the date shows accuratly. Screenshot 2022-04-05 231718

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

SonomaGTS avatar Apr 06 '22 04:04 SonomaGTS

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.!

SonomaGTS avatar Apr 12 '22 20:04 SonomaGTS

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

bonukai avatar Apr 12 '22 23:04 bonukai

Version bonukai/mediatracker:0.1.0-beta6 is now released, with lists, this bug fix, and more

bonukai avatar May 04 '22 21:05 bonukai

Can confirm this did indeed fix the date issue. Great work! 👍

SonomaGTS avatar May 04 '22 22:05 SonomaGTS

Agreed, this fixed the issue. Thanks for updating this!

saddle-gaudier-06 avatar May 05 '22 00:05 saddle-gaudier-06