From 2798ff02ebdd314ad531398d5e52834ee31baeea Mon Sep 17 00:00:00 2001 From: Oscar Cortez Date: Tue, 9 Aug 2022 13:28:26 -0600 Subject: [PATCH 1/2] Add support for set timezone - Refs #1 Now we can return the events in a specific timezone format as follows: - via cli argument neocal --timezone America/Los_Angeles - via calendar config [work] endpoint = timezone = America/Los_Angeles - via neocal config [neocal] default = work timezone = America/Los_Angeles --- src/main.rs | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index 7ab3a0e..4a3f9a1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -40,6 +40,10 @@ struct Args { /// Word to search in the calendar #[clap(short, long, value_parser, forbid_empty_values = true, validator = validate_option_value)] search: Option, + + /// Name of the Time Zone to return the events + #[clap(short, long, value_parser, forbid_empty_values = true, validator = validate_option_value)] + timezone: Option, } fn validate_option_value(name: &str) -> Result<(), String> { @@ -130,11 +134,22 @@ async fn main() -> Result<(), Box> { .calendar .unwrap_or(config.get("neocal", "default").unwrap()); let view_to_use = args.view.unwrap_or(config.get("neocal", "mode").unwrap()); - + let timezone = args.timezone.unwrap_or( + config + .get(&calendar_to_use, "timezone") + .unwrap_or(config.get("neocal", "timezone").unwrap_or("".to_string())), + ); let mut endpoint = Url::parse(&config.get(&calendar_to_use, "endpoint").unwrap())?; - if &args.search.as_ref().unwrap().to_string().len() > &0 { - let query = format!("q={}", &args.search.as_ref().unwrap().to_string()); - endpoint.set_query(Some(&query)); + + if args.search.is_none() == false { + endpoint + .query_pairs_mut() + .append_pair("q", &args.search.as_ref().unwrap().to_string()); + }; + if timezone.to_string().len() > 0 { + endpoint + .query_pairs_mut() + .append_pair("timeZone", &timezone.to_string()); }; let request = client From 17a985a3a6b5490404844f06256952027ff1a071 Mon Sep 17 00:00:00 2001 From: Oscar Cortez Date: Tue, 9 Aug 2022 13:32:14 -0600 Subject: [PATCH 2/2] Bump package version --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 2a576a7..7ed8c4f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "neocal" -version = "0.2.0" +version = "0.3.0" edition = "2021" authors = ["Oscar Cortez "] license-file = "LICENSE"