simrail / EDR

EDR timetable & driver view for Simrail
https://edr.simrail.app
GNU General Public License v3.0
25 stars 12 forks source link

In different timezones, the arrival and departure times are not correct #102

Closed Loikas closed 4 months ago

Loikas commented 7 months ago

image

See the image above, i am in a different when compared to the server, this is not an issue except i am currently in gmt + 1 which in turn also adds one hour to the scheduled arrival and departure times.

This should be easily fixable by changing the constructor in the station.ts file from new Date() to new Date(Date.UTC()) and then deducting the server timezone.

Hope this helps

DKFN commented 7 months ago

I am not reproducing the issue on my end. Specifically from your screenshot it seems like and the description of your issue.

It seems the fix you are proposing is already implemented in the time utils, but rather being calculated on the backend, the offset is calculated on the frontend here.

export const nowUTC = (serverTime: number | undefined) => {
    let now: Date;
    if (serverTime === undefined) {
        now = new Date();
    } else {
        now = new Date(serverTime);
    }

    return utcToZonedTime(Date.UTC(now.getUTCFullYear(),now.getUTCMonth(), now.getUTCDate(),
            now.getUTCHours(), now.getUTCMinutes(), now.getUTCSeconds(), now.getUTCMilliseconds()), "GMT");
}

However, based on the time shown anorther issue is indeed there, it looks like around midnight the trains have a day more than what is calculated on your end!

Due to timezone differences it is quite hard to reproduce, we have unit tests in place to find the specific error however it seems we are missing one edge case when the day switch.

Let me know if my assumptions looks wrong, and thanks for reporting the issue :)

Loikas commented 7 months ago

Thanks for your response. I understand that it is difficult to reproduce and I didn't know about the backend solution. However even if it is a problem on my end, im not really sure how I should go about fixing it as im just loading the browser page without altering anything. It does seem to be fixed now. Which is weird, maybe it does indeed have to do with if it is almost the next day.

DKFN commented 7 months ago

@Loikas I beleive because you will have this issue again around midnight, you indeed have a bug but a different one I suspect. Let me know if you stil have the problem when you play around at midnight. Thanks :)

ChrisClownie commented 5 months ago

image I have the same issue here, happens all of the time. All train schedule times on the website are an hour behind.

MrDj200 commented 4 months ago

Can confirm it happened for a friend on this link: https://edr.simrail.app/en2/station/GW However the time were correct on https://edr.simrail.app/en1/station/GW

He's in GMT+3 and it was around 23:00 irl for him. On the server (EN2) it was 08:00

Tallyrald commented 4 months ago

Thanks everyone for your reports, I hope I finally fixed this in this commit. Will be included in the next patch.