Closed akasolace closed 3 years ago
in case it helps this is what I came up with (in python) that seems to do the job:
def gregorianToHT(_date, useLocal = False, iLeagueID=None):
ORIGIN = date(1997, 6, 2)
dayDiff = (_date-ORIGIN).days
season = dayDiff // 112
week = (dayDiff % 112 // 7) + 1
if useLocal:
assert iLeagueID is not None, "if useLocal = True, iLeagueID should be provided"
season += dSeasonOffset[iLeagueID]
return season, week
# some tests ======
assert gregorianToHT(date(2020, 6, 27)) == (75, 4)
assert gregorianToHT(date(2018, 5, 10)) == (68, 5)
assert gregorianToHT(date(2009, 5, 28)) == (39, 2)
assert gregorianToHT(date(2020, 8, 31), True, 52) == (60, 14)
>>> str(date(2020, 8, 31))
'2020-08-31'
new Date(2020,8,31).toString()
"Thu Oct 01 2020 00:00:00 GMT+0200 (Central European Summer Time)"
Does that answer your question?
To be specific, this passes no problem:
gregorianToHT = (...args) => { let {season, week} = Foxtrick.util.time.gregorianToHT(...args); return season*16 + week; };
console.assert(gregorianToHT(new Date(2020, 5, 27)) == 75*16+4);
console.assert(gregorianToHT(new Date(2018, 4, 10)) == 68*16+5);
console.assert(gregorianToHT(new Date(2009, 4, 28)) == 39*16+2);
For JS weirdness see MDN docs. I.e. month starts from 0. I know, I know.
Keep in mind, that local season is specific to the running user, and we also (sometimes) take into account HTDateFormat settings.
The sometimes part should probably be fixed. But I don't think this issue itself is valid
I just tried to call gregorianToHT(new Date(2020,8,31)) and it returns { season: 76, week: 2 } Am I doing something wrong because I imagine this function has been tested quite a lot Should you not have ORIGIN = new Date(1997, 6, 2) ?