From c06d5c51734c30e149baca484525c20082c03772 Mon Sep 17 00:00:00 2001 From: raghavt3 Date: Thu, 7 Mar 2024 11:50:27 -0600 Subject: [PATCH] bug fix for weekdays on auto feature --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/main.rs | 68 ++++++++++++++++++++++++++++++++++++++++++++++------- tasks.txt | 1 + 4 files changed, 63 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ef0b675..6136967 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -671,7 +671,7 @@ checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" [[package]] name = "vayu" -version = "0.1.6" +version = "0.1.8" dependencies = [ "chrono", "clap", diff --git a/Cargo.toml b/Cargo.toml index 3c09062..dd9af51 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "vayu" -version = "0.1.7" +version = "0.1.8" edition = "2021" authors = ["Raghav Tirumale raghav.tirumale@gmail.com"] license = "MIT" diff --git a/src/main.rs b/src/main.rs index a2f18a1..7317d1e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -583,15 +583,67 @@ fn add_auto(tasks: &mut Vec, next_id: i32, arg1: String) { //set the due date to now in the format YYYY-MM-DD let last_day = now.format("%Y-%m-%d").to_string(); + let mut task_desc = arg1; + //remove the day of the week from the arg1 string (try removing anything from mon to monday) + let mut remmon: String = "monday".to_string(); + while remmon.len() > 2{ + if task_desc.contains(&remmon){ + task_desc = task_desc.replace(&remmon, ""); + + } + remmon.pop(); + } + let mut remtues: String = "tuesday".to_string(); + while remtues.len() > 2{ + if task_desc.contains(&remtues){ + task_desc = task_desc.replace(&remtues, ""); + + } + remtues.pop(); + } + let mut remwed: String = "wednesday".to_string(); + while remwed.len() > 2{ + if task_desc.contains(&remwed){ + task_desc = task_desc.replace(&remwed, ""); + + } + remwed.pop(); + } + let mut remthurs: String = "thursday".to_string(); + while remthurs.len() > 2{ + if task_desc.contains(&remthurs){ + task_desc = task_desc.replace(&remthurs, ""); + + } + remthurs.pop(); + } + let mut remfri: String = "friday".to_string(); + while remfri.len() > 2{ + if task_desc.contains(&remfri){ + task_desc = task_desc.replace(&remfri, ""); + + } + remfri.pop(); + } + let mut remsat: String = "saturday".to_string(); + while remsat.len() > 2{ + if task_desc.contains(&remsat){ + task_desc = task_desc.replace(&remsat, ""); + + } + remsat.pop(); + } + let mut remsun: String = "sunday".to_string(); + while remsun.len() > 2{ + if task_desc.contains(&remsun){ + task_desc = task_desc.replace(&remsun, ""); + + } + remsun.pop(); + } + + - //remove the day of the week from the arg1 string - let mut task_desc = arg1.replace("mon", ""); - task_desc = task_desc.replace("tue", ""); - task_desc = task_desc.replace("wed", ""); - task_desc = task_desc.replace("thu", ""); - task_desc = task_desc.replace("fri", ""); - task_desc = task_desc.replace("sat", ""); - task_desc = task_desc.replace("sun", ""); //while the task description has a last word of "by", "at", "of" or "on", remove the last word let mut task_desc_vec : Vec<&str> = task_desc.split(" ").collect(); diff --git a/tasks.txt b/tasks.txt index d166345..5d03c14 100644 --- a/tasks.txt +++ b/tasks.txt @@ -1,3 +1,4 @@ +example test %2024-03-07%false%5 meditation%2024-03-10%false%1 test at the %2024-03-31%false%2 test%2024-03-31%false%3