Giter Site home page Giter Site logo

Comments (5)

pithu avatar pithu commented on June 2, 2024

Isn't that more a theoretical discussion ? Period of one year can be 365 or 366 days. From 2024-02-28 to 2025-02-28 is one year and from 2024-02-29 to 2025-03-01 its one year and one day. IMHO the result is correct. Nevertheless our upstream project threeten and in the java api you get the same results. So this probably more a discussion for the java community.

from js-joda.

Vashev-S avatar Vashev-S commented on June 2, 2024

You gave me some thought , thanks.

But for me it is not just theoretical. I want to find whole year form 2024-02-29.
The result looks strange, Isn't it?

// Very strange result 
const start = LocalDate.parse('2024-02-29')
const end = start.plusYears(1); // '2025-02-28'
start.until(end) // P11M30D

// Another example
const start = LocalDate.parse('2024-02-29')
const end =  LocalDate.parse('2024-03-01')
start.until(end) // P1Y1D

//This one is 100% accurate
const start = LocalDate.parse('2024-02-28')
const end = start.plusYears(1); // '2024-02-28'
start.until(end) // P1Y

Perhaps I missunderstund how leap years calculation works, but where is P1Y if we start counting from 02.29 ?

from js-joda.

pithu avatar pithu commented on June 2, 2024

Indeed, i agree that Period and Date calculation can produce strange results in case of leap years. Especially your first example looks weird. But the second makes sense imo. Eg LocalDate.parse('2024-02-29').until(LocalDate.parse('2028-02-29')).toString() is P4Y and LocalDate.parse('2024-02-29').until(LocalDate.parse('2028-03-01')).toString() is P4Y1D.
In general i would say its impossible to map an amount of days to a consistent period of years, month and days of month, because years and month do not have a fixed amount of days.

from js-joda.

Vashev-S avatar Vashev-S commented on June 2, 2024

I totaly agree that second example make sense.

But I still belive in bug in the first example.

Next condition must be equal with any X and Z
"X + (Z - Z) = X"

const start = LocalDate.parse(X)
const end =  start.plusYears(Z);

const reclaculatedStart = end.plusYears(-Z);

checkEqualty(start , reclaculatedStart ); // Must be true in any case

But somehow it doesn't work with "X = '02-29-....'" and "1 <= Z < 4"

const start = LocalDate.parse('2024-02-29')
const end = start.plusYears(1); // '2025-02-28'

const recalcedStart = end.plusYears(-1);  // '2024-02-28'

I would be REALY happy if you will find misstake in my thoughts.

from js-joda.

github-actions avatar github-actions commented on June 2, 2024

This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 14 days.

from js-joda.

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.