minj / foxtrick

FoxTrick is a browser extension for the Hattrick online football manager game, currently available for Firefox, Google Chrome, as well as for Opera.
https://www.foxtrick.org
GNU General Public License v3.0
69 stars 48 forks source link

Fix getPromotionDate computation for youth players joining at 16+ y.o. #1713

Open dominiquelee opened 11 months ago

dominiquelee commented 11 months ago

A player has to have been in a team for a full season (i.e. 112 full days) before being promoted. For players that joined at 16 y.o., the hour at which they were hired must be taken into account.

minj commented 11 months ago

If I recall correctly this has something to do with the hacky way we deal with dates, causing issues when daylight savings time (de)activates. Have you tested this scenario?

dominiquelee commented 10 months ago

I didn't think about it and it sure sounds like a lot of unfun to handle. I see addDaysToDate does ret.setDate(ret.getDate() + dayCt);, which, from some quick testing, should return the same hour when we pass a DST day, but with a different timezone. I wonder if the right call isn't this to drop the timezone in this (specific?) computation (or at least, directly realign it with the initial value) - though, dropping the timezone is probably not the greatest idea and is likely to have many random side-effects.

minj commented 10 months ago

Yes, I hate having to deal with time zones in browsers.

I thought there was an issue to use moment.js but I cannot for the life of me find it any more. IIRC Hattrick includes the library on the site, it would be good to reuse their code as much as possible as I do not feel like shipping time zone definitions in Foxtrick.

Other than that I hear there are new browser localization libraries available...