Comments (5)
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.
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.
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 DateTime
s.
from chrono.
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.
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)
- 0.5: Consider using smaller types for arguments
- Make Weekday::num_days_from public HOT 2
- Add a method to the `Offset` trait to return DST info HOT 5
- 0.5: Add a `LocalOffset` type HOT 4
- Verification of published packages HOT 2
- `gh-pages` branch HOT 3
- Releases has problematic naming of 0.4.8 release which puts it at the top HOT 3
- 0.4.37 semver-incompatibly removes trait bounds on `DateTime` HOT 10
- How do I get the raw underlying bytes of a `NaiveDate` HOT 4
- Parsing from string to DateTime - input is not enough for unique date and time HOT 3
- TimeDelta always returning a PT in seconds HOT 2
- NaiveDate::years_since wrong documentation
- Saturating operations HOT 9
- Datetime Parse Error when converting rfc2822 date to chrono Datetime HOT 2
- Extra slow Utc to Local conversion HOT 6
- Wasm support for NaiveTime, NaiveDate and alike HOT 2
- Bincode 2.0.0 support HOT 2
- Need Duration to Represent Time in Months/Years HOT 1
- DelayedFormat: Panic in rendering HOT 5
- Err(ParseError(TooShort)) when parsing datetime with trailing 0 HOT 4
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 chrono.