Skip to content

Commit

Permalink
Merge pull request #8 from oscarmcm/timezone_filter
Browse files Browse the repository at this point in the history
Add support for set timezone filter
  • Loading branch information
oscarmcm authored Aug 9, 2022
2 parents 8d1683d + 17a985a commit c7a261a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "neocal"
version = "0.2.0"
version = "0.3.0"
edition = "2021"
authors = ["Oscar Cortez <[email protected]>"]
license-file = "LICENSE"
Expand Down
23 changes: 19 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,

/// Name of the Time Zone to return the events
#[clap(short, long, value_parser, forbid_empty_values = true, validator = validate_option_value)]
timezone: Option<String>,
}

fn validate_option_value(name: &str) -> Result<(), String> {
Expand Down Expand Up @@ -130,11 +134,22 @@ async fn main() -> Result<(), Box<dyn Error>> {
.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
Expand Down

0 comments on commit c7a261a

Please sign in to comment.