diff --git a/project/src/parser.rs b/project/src/parser.rs index 6e36c62..3dd839d 100644 --- a/project/src/parser.rs +++ b/project/src/parser.rs @@ -14,6 +14,7 @@ pub struct Parser { mode: ParserModes, paused: bool, + year: String, content: String, } @@ -27,6 +28,7 @@ impl Parser { mode: ParserModes::None, paused: false, + year: String::new(), content, } } @@ -59,6 +61,10 @@ impl Parser { self.mode = ParserModes::Debit; } else if line == "Deposits, credits and interest" { self.mode = ParserModes::Credit; + } else if line.contains("For") { + let mut parts = line.split('/').last().unwrap().split_whitespace(); + let year_part = parts.nth(0).unwrap().to_string(); + self.year = year_part; } } fn transaction(&mut self, t_type: ParserModes, line: &str) { @@ -73,7 +79,7 @@ impl Parser { // Collecting based on Parts let description = parts[2..parts.len() - 1].join(" "); let mut amount: f64 = parts.last().unwrap().parse().unwrap_or(0.0); - let date = parts[0].to_owned(); + let date = format!("{}/{}", parts[0], &self.year); // Is it a debit? match t_type {