GithubHelp home page GithubHelp logo

Comments (2)

pitdicker avatar pitdicker commented on May 27, 2024 1

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.

truehumandesign avatar truehumandesign commented on May 27, 2024

@pitdicker thank you very much for the explanation and providing a solutions for that problem

from chrono.

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.