Giter Site home page Giter Site logo

Comments (5)

pitdicker avatar pitdicker commented on June 8, 2024

We can get a sensible result if we create an intermediate value with the date of now and the time of base, picking the earliest datetime if ambiguous. Then we compare the times of the intermediate value and now. (This only has to happen if the month and day are the same.)

from chrono.

djc avatar djc commented on June 8, 2024

I have questions:

  • Why does this behavior happen? Because a DST transition happens on that day, and we pick one of the sides?
  • Do we use years_since() in other calculations inside chrono?
  • If so, how, and what would the correct expected results be for those?

from chrono.

pitdicker avatar pitdicker commented on June 8, 2024

I was just reading the implementation of DateTime::years_since and wondering how it dealt with differences in timezones. Does it work in local time or UTC? and if in local time, how does it behave if the two dates have different timezones?

Turns out it works in local time (sensible). The method signature requires the timezone to be the same. That only leaves the case of the offset from UTC changing within the same timezone as a potentially tricky case.

  • Why does this behavior happen? Because a DST transition happens on that day, and we pick one of the sides?

Because of a DST transition on that day, and we don't pick any side but naively use the local time.

  • Do we use years_since() in other calculations inside chrono?

No. It is used nowhere, we don't even seem to have tests. Actually I was in the process of deprecating it but couldn't come up with a usable alternative.

  • If so, how, and what would the correct expected results be for those?

I suppose from the moment month, day and time are equal it counts as a full year that has passed. If the clock turns backwards after that it should keep counting that full year.

Should we care about this issue?
I just consider this a minor bug that is fun to fix (I also know more normal ways to have fun 😄). Maybe even a good first issue with some mentoring.
More importantly the solution informs how to do correct calculations with a CalendarDuration on DateTimes.

from chrono.

djc avatar djc commented on June 8, 2024

It's probably worth fixing but also not very high priority? Could do something like comparing the months and if the difference is larger than 1 return, same for months and days, then convert both to Utc and compare that?

from chrono.

pitdicker avatar pitdicker commented on June 8, 2024

I can probably write the fix described in #1398 (comment) and a test in two hours.

The reason to open this issue is that I should get in the habit of making notes such as this public instead of keeping a single line somewhere on my PC with 'TODO'. It seemed low priority enough for me to not work on directly and discuss in a PR 🤣.

from chrono.

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.