Comments (2)
If your local timezone is in Europe (like me) then the result should be 2023-10-29 01:04:43. That is right in the transition from summer to winter time, which is documented to return None
.
I don't think checked_sub_months
has a very sane API. It falls back to another day when the target month is shorter than the source month. Yet it returns None
on something less significant such as a DST transition 😞. Hopefully something we can fix with chrono 0.5.
If you want to get a LocalResult
instead of Option
you can try:
#[test]
fn test_unwrap_naive_local_now() {
let datetime = Utc.with_ymd_and_hms(2023, 11, 29, 01, 04, 43).unwrap();
// Local Timezone is UTC+1
let local_now = datetime.with_timezone(&Local);
let naive_now = local_now.naive_local();
let naive_last_month = naive_now.checked_sub_months(Months::new(1)).unwrap();
let local_last_month = Local.from_local_datetime(&naive_last_month);
assert!(matches!(local_last_month, LocalResult::Ambiguous(_, _)));
}
from chrono.
@pitdicker thank you very much for the explanation and providing a solutions for that problem
from chrono.
Related Issues (20)
- Split `clock` feature into `clock-now` and `clock-tz` HOT 6
- CI failures in MSRV jobs failing to pick up ahash version
- Operations on NaiveDate are not commutative. HOT 10
- Add `subsec` methods to `Duration` HOT 1
- Time formatting on en_US locale with '%X' not expected HOT 1
- FrameworkNotFound error when building for Apple using maturin HOT 1
- format paniced HOT 11
- panic with_timezone Jan 1, 1601 00:00 UTC HOT 32
- Add methods for float multiplication/division HOT 1
- rfc HOT 1
- This API seems very complicated HOT 2
- Times before Unix epoch
- Truncating a timestamp close to EPOCH fails HOT 6
- Uhm build fails? HOT 14
- confusing deprecation notice for `chrono::TimeZone::datetime_from_str` HOT 7
- Minimum year changed in 0.4.32 HOT 15
- Breaking change in chrono 0.4.32 (Accepted MAX date changed) HOT 4
- RFC: Bring some of the Rubedo extensions for Chrono into Chrono HOT 23
- `DateTime::years_since` is tricky during ambiguous local time HOT 5
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.