Comments (5)
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.
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.
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.
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.
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)
- ZonedDateTime with Zulu or GMT0 timezone is unparsable from string? HOT 1
- Zoneless Date from Instant in Docs HOT 2
- No mention of Instant in manual - intended? HOT 1
- `DateTimeFormatter.ofPattern` not working as expected with "zone-offset" HOT 4
- Parsing Examples Broken HOT 2
- DateTimeFormatterBuilder.appendValue() 3 arguments: undefined must not be null HOT 3
- `SYSTEM` timezone formatting HOT 2
- apparent rounding error in parse HOT 5
- YearQuarter.now(): now.getYear is not a function HOT 1
- Duplicate identifier 'ISO_OFFSET_TIME'
- Missing Requirement of @js-joda/timezone should throw error or give some message HOT 2
- Why does ZoneId.systemDefault() return SYSTEM? HOT 2
- Issue with WeekField docs HOT 3
- DateTimeFormatter missing typescript type definitions for withLocale method
- Can't use LocalDate in redux store HOT 2
- Using English locale packages results in error "cldrData: unknown path main/en/ca-gregorian.json" HOT 3
- Duration.plusDuration seems to be missing from type definitions HOT 2
- Adding a formatter for Period/Duration HOT 1
- Mexico stopped using DST last year, but time.ZonedDateTime.now() is still shifting the time by one hour. HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from js-joda.