Git Product home page Git Product logo

Comments (5)

keithchew avatar keithchew commented on June 11, 2024 1

Hi @GuyAv46 great work!! I have also tested your implementation on my instances, and it works like a charm.

from redisearch.

keithchew avatar keithchew commented on June 11, 2024

Yes, just looking at the fast_timegm() function, the issue might be here:

tdays = tdays + (tyears * 365) + leaps;

Because 2024 is a leap year, and leap year day happens on the 29th Feb. However, the algorithm is very crude and just adds a day for the year, which means the output will be incorrect from Jan 1 to Feb 28, then presumably correct again after Mar 1.

from redisearch.

keithchew avatar keithchew commented on June 11, 2024

As a quick test, I made this patch:

...
  tdays += ltm->tm_mday - 1;  // days of month passed.

  if ((tyears + 2) % 4 == 0) {
    if (tdays <= (31 + 29)) {
      tdays -= 1;
    }
  }

  tdays = tdays + (tyears * 365) + leaps;
...

Ie, it will only add the leap year's day from Mar 1 onwards. Seems to fix the issue for my case above, but needs further testing for Feb 29 and Mar 1.

from redisearch.

GuyAv46 avatar GuyAv46 commented on June 11, 2024

Nice catch! Thanks for reporting.
I think a faster and simpler solution would be not to include the current year if it is a leap year, and to use tm_yday which counts the number of days from the beginning of the year including a leap day if there was one.
here is a correction check for my solution, compared to the existing implementation. Notice that I use leaps = (tyears + 1) / 4; to not include the current year, instead of leaps = (tyears + 2) / 4;
And here is a performance comparison of the fix, and here compared to the standard function

from redisearch.

GuyAv46 avatar GuyAv46 commented on June 11, 2024

Fixed. Available on master and version branches.
Will be part of v2.6.16 and v2.8.12

from redisearch.

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.