A DESCRIPTION OF THE PROBLEM :
Long story short: There is no period equal to one year(P1Y) if the starting date is 02-29-YYYY.
const start = LocalDate.parse('2024-02-29')
const end = start.plusYears(1); // '2025-02-28'
start.until(end) // P11M30D
I strongly belive answer must be "P1Y"
*An explanation*
Lets describe some defenitions to be on a same page.
Calendar Year - a period of 365 or 366 days, starting on January 1st and ending on December 31st. (pls pay attention it's not a week year);
One year period - period expires in the corresponding month and date of the last calendar year of the term.
If there is no corresponding day in the month in which the period expires (for example, it falls on February 30), the expiration date is the last day of the calendar month.
I believe there is an issue with period calculation when start date = "02-29-YYYY" AND period between [1; 3] years;
*example*
// Less P1Y
const start = LocalDate.parse('2024-02-29')
const end = start.plusYears(1); // '2025-02-28'
start.until(end) // P11M30D
// More P1Y
const start = LocalDate.parse('2024-02-29')
const end = LocalDate.parse('2024-03-01')
start.until(end) // P1Y1D
As you can see according to the calculation, there is no "P1Y" when the start date is "02-29".
But it works totally fine for any other date.
const start = LocalDate.parse('2024-02-28')
const end = start.plusYears(1); // '2025-02-28'
start.until(end) // P1Y
// More P1Y
const start = LocalDate.parse('2024-03-01')
const end = LocalDate.parse('2024-03-01')
start.until(end) // P1Y
Why I do believe that is a mistake.
Statements
1. Any date in the calendar has a next date. (Consider it as an axiom)
2. Based on statement 1, we can easily prove that any date has 365th and 366th days after it.
3. Based on 2: NO matter how many days in the year, we can find any period as long as the period can be represented in whole days.
Assumption
1. The number of days in a year is expressed as a natural number.
Problem
1. According to calculation, there is no P1Y from '02-29'.
I can draw two separate conclusions:
1. Calculation contains a misstake.
2. The number of days in a year is NOT expressed as a natural number.
I'm not going to prove the assumption, even more I probably can't.
But I suppose no one will argue that are remarkable abstractions that allow us to perform simple arithmetic operations with dates.
Imho, The simplest explanation is the right one.
I'd rather to believe there is a mistake in the given calculation, than start calculate years using fractional numbers to calculate whole years.
Thanks for your attention, please point out misstakes in my reasoning if there are any.
Long story short: There is no period equal to one year(P1Y) if the starting date is 02-29-YYYY.
const start = LocalDate.parse('2024-02-29')
const end = start.plusYears(1); // '2025-02-28'
start.until(end) // P11M30D
I strongly belive answer must be "P1Y"
*An explanation*
Lets describe some defenitions to be on a same page.
Calendar Year - a period of 365 or 366 days, starting on January 1st and ending on December 31st. (pls pay attention it's not a week year);
One year period - period expires in the corresponding month and date of the last calendar year of the term.
If there is no corresponding day in the month in which the period expires (for example, it falls on February 30), the expiration date is the last day of the calendar month.
I believe there is an issue with period calculation when start date = "02-29-YYYY" AND period between [1; 3] years;
*example*
// Less P1Y
const start = LocalDate.parse('2024-02-29')
const end = start.plusYears(1); // '2025-02-28'
start.until(end) // P11M30D
// More P1Y
const start = LocalDate.parse('2024-02-29')
const end = LocalDate.parse('2024-03-01')
start.until(end) // P1Y1D
As you can see according to the calculation, there is no "P1Y" when the start date is "02-29".
But it works totally fine for any other date.
const start = LocalDate.parse('2024-02-28')
const end = start.plusYears(1); // '2025-02-28'
start.until(end) // P1Y
// More P1Y
const start = LocalDate.parse('2024-03-01')
const end = LocalDate.parse('2024-03-01')
start.until(end) // P1Y
Why I do believe that is a mistake.
Statements
1. Any date in the calendar has a next date. (Consider it as an axiom)
2. Based on statement 1, we can easily prove that any date has 365th and 366th days after it.
3. Based on 2: NO matter how many days in the year, we can find any period as long as the period can be represented in whole days.
Assumption
1. The number of days in a year is expressed as a natural number.
Problem
1. According to calculation, there is no P1Y from '02-29'.
I can draw two separate conclusions:
1. Calculation contains a misstake.
2. The number of days in a year is NOT expressed as a natural number.
I'm not going to prove the assumption, even more I probably can't.
But I suppose no one will argue that are remarkable abstractions that allow us to perform simple arithmetic operations with dates.
Imho, The simplest explanation is the right one.
I'd rather to believe there is a mistake in the given calculation, than start calculate years using fractional numbers to calculate whole years.
Thanks for your attention, please point out misstakes in my reasoning if there are any.