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

'CEST' or 'CET' timezone silently treated as UTC #52

Open
Jajcus opened this issue Jul 29, 2024 · 0 comments
Open

'CEST' or 'CET' timezone silently treated as UTC #52

Jajcus opened this issue Jul 29, 2024 · 0 comments

Comments

@Jajcus
Copy link

Jajcus commented Jul 29, 2024

When 'CEST' or 'CET' time zone name is used in parsed string it is treated as UTC.

It should either be properly interpreted as Central European (Summer) Time, or an error should be reported or, at least, it should be treated as no time zone provided (so the default from parse_with_timezone() can be used). Current behaviour is quite unexpected.

Test code:

use chrono::Local;
use dateparser::{parse, parse_with_timezone};

pub fn main() {
    check_date("2024-07-29 12:00:00 +02:00");
    check_date("2024-07-29 12:00:00 CEST");
    check_date("2024-07-29 12:00:00 CET");
    check_date("2024-07-29 12:00:00 PST");

    check_local_date("2024-07-29 12:00:00");
    check_local_date("2024-07-29 12:00:00 +02:00");
    check_local_date("2024-07-29 12:00:00 CEST");
}

fn check_date(value: &str) {
    println!("'{}' is: {}", value, parse(value).unwrap())
}

fn check_local_date(value: &str) {
    println!(
        "'{}' is: {} (with local timezone)",
        value,
        parse_with_timezone(value, &Local).unwrap()
    )
}

Output:

'2024-07-29 12:00:00 +02:00' is: 2024-07-29 10:00:00 UTC
'2024-07-29 12:00:00 CEST' is: 2024-07-29 12:00:00 UTC
'2024-07-29 12:00:00 CET' is: 2024-07-29 12:00:00 UTC
'2024-07-29 12:00:00 PST' is: 2024-07-29 20:00:00 UTC
'2024-07-29 12:00:00' is: 2024-07-29 10:00:00 UTC (with local timezone)
'2024-07-29 12:00:00 +02:00' is: 2024-07-29 10:00:00 UTC (with local timezone)
'2024-07-29 12:00:00 CEST' is: 2024-07-29 12:00:00 UTC (with local timezone)

The string is properly interpreted by the date command:

$ date --date="2024-07-29 12:00:00 CEST"
Mon 29 Jul 12:00:00 CEST 2024
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

1 participant