GithubHelp home page GithubHelp logo

BUG gregorianToHT ?? about foxtrick HOT 4 CLOSED

akasolace avatar akasolace commented on June 6, 2024
BUG gregorianToHT ??

from foxtrick.

Comments (4)

akasolace avatar akasolace commented on June 6, 2024

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)

from foxtrick.

minj avatar minj commented on June 6, 2024
>>> 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?

from foxtrick.

minj avatar minj commented on June 6, 2024

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);

from foxtrick.

minj avatar minj commented on June 6, 2024

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

from foxtrick.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.