From 77c9c66a6c3def49bfcecd155d95391da5b63a7d Mon Sep 17 00:00:00 2001 From: Antonio Yang Date: Mon, 30 Sep 2024 23:14:30 +0800 Subject: [PATCH] support timezone abbreviation --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/lib.rs | 51 ++++++++++++++++++++++++++------------------------- 3 files changed, 28 insertions(+), 27 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a88d180..0a486ba 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1631,7 +1631,7 @@ dependencies = [ [[package]] name = "test-with" -version = "0.14.1" +version = "0.14.2" dependencies = [ "byte-unit", "chrono", diff --git a/Cargo.toml b/Cargo.toml index 1e7b9c9..529b063 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "test-with" -version = "0.14.1" +version = "0.14.2" authors = ["Antonio Yang "] edition = "2021" license = "MIT" diff --git a/src/lib.rs b/src/lib.rs index 1b958d1..577ef28 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2928,33 +2928,34 @@ fn check_timezone(attr_str: &String) -> (bool, Vec<&str>) { for tz in attr_str.split(',') { let parsed_tz = match tz { - "NZDT" => Ok(13), - "NZST" => Ok(12), - "AEDT" => Ok(11), - // "ACDT" => Ok(10.5) - "AEST" => Ok(10), - // "ACST" => Ok(9.5) - "KST" | "JST" => Ok(9), - "HKT" | "WITA" | "AWST" => Ok(8), // Duplicate PST + "NZDT" => Ok(13 * 60), + "NZST" => Ok(12 * 60), + "AEDT" => Ok(11 * 60), + "ACDT" => Ok(10 * 60 + 30), + "AEST" => Ok(10 * 60), + "ACST" => Ok(9 * 60 + 30), + "KST" | "JST" => Ok(9 * 60), + "HKT" | "WITA" | "AWST" => Ok(8 * 60), + "PST" => abort_call_site!("PST can be GMT+8 or GMT-8, please use +8 or -8 instead"), "WIB" => Ok(7), - // "CST" => Ok(8), // Duplicate CST - // "IST" => Ok(5.5) - "PKT" => Ok(5), - "EAT" | "EEST" | "IDT" | "MSK" => Ok(3), - "CAT" | "EET" | "CEST" | "SAST" => Ok(2), // Duplicate IST - "CET" | "WAT" | "WEST" | "BST" => Ok(1), + "CST" => abort_call_site!("PST can be GMT+8 or GMT-6, please use +8 or -6 instead"), + "IST" => Ok(5 * 60 + 30), + "PKT" => Ok(5 * 60), + "EAT" | "EEST" | "IDT" | "MSK" => Ok(3 * 60), + "CAT" | "EET" | "CEST" | "SAST" => Ok(2 * 60), + "CET" | "WAT" | "WEST" | "BST" => Ok(1 * 60), "UTC" | "GMT" | "WET" => Ok(0), - // "NDT" => Ok(-2.5) - // "NST" => Ok(-3.5) - "ADT" => Ok(-3), - "AST" | "EDT" => Ok(-4), - "EST" | "CDT" => Ok(-5), - "MDT" => Ok(-6), // Another CST here - "MST" | "PDT" => Ok(-7), - "AKDT" => Ok(-8), // Another PST here - "HDT" | "AKST" => Ok(-9), - "HST" => Ok(-10), - _ => tz.parse::(), + "NDT" => Ok(-2 * 60 - 30), + "NST" => Ok(-3 * 60 - 30), + "ADT" => Ok(-3 * 60), + "AST" | "EDT" => Ok(-4 * 60), + "EST" | "CDT" => Ok(-5 * 60), + "MDT" => Ok(-6 * 60), + "MST" | "PDT" => Ok(-7 * 60), + "AKDT" => Ok(-8 * 60), + "HDT" | "AKST" => Ok(-9 * 60), + "HST" => Ok(-10 * 60), + _ => tz.parse::().map(|tz| tz * 60), }; if let Ok(parsed_tz) = parsed_tz { match_tz |= current_tz == parsed_tz;