Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: support for daylight savings time #120

Closed
kybishop opened this issue Jan 25, 2017 · 5 comments
Closed

Feature request: support for daylight savings time #120

kybishop opened this issue Jan 25, 2017 · 5 comments

Comments

@kybishop
Copy link

I went investigating DST support in chrono after needing it for an app. I stumbled on this issue, but it looks like DST support is still a ways off. I was hoping to bring the status of DST support into a single issue for better tracking, and to see if there is anything I/the community could do to help out.

Thanks!

@djzin
Copy link

djzin commented Feb 11, 2017

Does chrono-tz solve your problem?

@kybishop
Copy link
Author

@djzin yes! Thanks a bunch for the lib!

@vertexua
Copy link

vertexua commented Oct 31, 2018

I am not pro in dates and time, but it feel inconsistent. This code works

extern crate chrono;
extern crate chrono_tz;
extern crate time;

use chrono::prelude::*;
use chrono_tz::Europe::Berlin;

fn main() {
    let mut d = Berlin.ymd(2018, 10, 28).and_hms(1, 30, 0);
    for _ in 0 .. 10 {
        println!("{:?}", d);
        d = d + time::Duration::minutes(30);
    }
}

But let me change this to "and_hms(2, 30, 0)" and chrono_tz explicitly panics as it is invalid date. At the same time gradually adding 30 minutes works fine and prints a non-interrupted sequence of time with "CEST" as a timezone. Can you comment pls? One library allows creation of certain time, another explicitly prohibits. Is this expected?

@vertexua
Copy link

Am I understanding this right, that it is a matter of printing, but while we switch from CEST to CET, it is still possible to print the time in CEST, if it was hypothetically the current timezone. And this is what the framework does, because the "+" operation does not want to mutate the timezone. The selection of the sub-timezone (or whatever is the term) is only happening at creation time, but not refreshed at "+". It is up to the user to trigger the refresh of the sub-timezone (is there an API? For example that does not require to specify CET explicitly, but will somehow derive it from Berlin again for a new time)

This has it's own sense and certainly helps performance, but this is incredibly unexpected. I can imagine times appearing at the weird timezones just because they came from from an obscure formula and had a different initial sub-timezone at the be beginning.

@pitdicker
Copy link
Collaborator

Sorry for the late reply, I am going through old issues...

I am not pro in dates and time, but it feel inconsistent. This code works

extern crate chrono;
extern crate chrono_tz;
extern crate time;

use chrono::prelude::*;
use chrono_tz::Europe::Berlin;

fn main() {
    let mut d = Berlin.ymd(2018, 10, 28).and_hms(1, 30, 0);
    for _ in 0 .. 10 {
        println!("{:?}", d);
        d = d + time::Duration::minutes(30);
    }
}

But let me change this to "and_hms(2, 30, 0)" and chrono_tz explicitly panics as it is invalid date. At the same time gradually adding 30 minutes works fine and prints a non-interrupted sequence of time with "CEST" as a timezone. Can you comment pls? One library allows creation of certain time, another explicitly prohibits. Is this expected?

Good example. In more recent versions of chrono you would write this as:

use chrono::{Duration, TimeZone};
use chrono_tz::Europe::Berlin;

fn main() {
    let mut d = Berlin.with_ymd_and_hms(2018, 10, 28, 1, 30, 0).unwrap(); // This returns a `LocalResult`
    for _ in 0 .. 10 {
        println!("{:?}", d);
        d = d + Duration::minutes(30);
    }
}

Notice the place where a LocalResult is returned. If you change the time to 2:30 it will return LocalResult::Ambiguous, and unwrapping gives the panic:

thread 'main' panicked at 'Ambiguous local time, ranging from 2018-10-28T02:30:00CEST to 2018-10-28T02:30:00CET', src/main.rs:5:65
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

You can use the methods earliest() and latest() to pick which one to use.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants