Add CSV column mapping and reconstruction of basic information
This commit is contained in:
parent
8b2f0102c4
commit
82d9cf5c87
45
src/csv_parser.rs
Normal file
45
src/csv_parser.rs
Normal file
@ -0,0 +1,45 @@
|
||||
use chrono::{NaiveDate, NaiveTime};
|
||||
use csv::StringRecord;
|
||||
use crate::utils::Result;
|
||||
|
||||
mod headings {
|
||||
pub const USER: usize = 1;
|
||||
pub const USER_EMAIL: usize = 2;
|
||||
pub const CLIENT_NAME: usize = 3;
|
||||
pub const PROJECT_NAME: usize = 4;
|
||||
pub const TASK_NAME: usize = 5;
|
||||
pub const DESCRIPTION: usize = 6;
|
||||
pub const BILLABLE: usize = 7;
|
||||
pub const START_DATE: usize = 8;
|
||||
pub const END_DATE: usize = 9;
|
||||
pub const START_TIME: usize = 10;
|
||||
pub const END_TIME: usize = 11;
|
||||
pub const DURATION: usize = 12;
|
||||
pub const TAGS: usize = 13;
|
||||
}
|
||||
|
||||
fn parse_csv_row(row: StringRecord) -> Result<crate::entity::time_entry::Model> {
|
||||
let start_date = row.get(headings::START_DATE).unwrap();
|
||||
let start_time = row.get(headings::START_TIME).unwrap();
|
||||
let end_date = row.get(headings::END_DATE).unwrap();
|
||||
let end_time = row.get(headings::END_TIME).unwrap();
|
||||
|
||||
let start_time = NaiveTime::parse_from_str(start_time, "%H:%M:%S")?;
|
||||
let end_time = NaiveTime::parse_from_str(end_time, "%H:%M:%S")?;
|
||||
let start_date = NaiveDate::parse_from_str(start_date, "%Y-%m-%d")?;
|
||||
let end_date = NaiveDate::parse_from_str(end_date, "%Y-%m-%d")?;
|
||||
|
||||
let start = start_date.and_time(start_time);
|
||||
let end = end_date.and_time(end_time);
|
||||
|
||||
let description = row.get(headings::DESCRIPTION)?;
|
||||
let project_name = row.get(headings::PROJECT_NAME)?;
|
||||
let client_name = row.get(headings::CLIENT_NAME)?;
|
||||
let tags = row.get(headings::TAGS)?;
|
||||
let task_name = row.get(headings::TASK_NAME)?;
|
||||
let billable = match row.get(headings::BILLABLE)? {
|
||||
"Yes" => true,
|
||||
"No" => false,
|
||||
_ => unimplemented!("Unknown billable value")
|
||||
};
|
||||
}
|
||||
@ -31,6 +31,7 @@ mod entity;
|
||||
mod poll;
|
||||
mod types;
|
||||
mod utils;
|
||||
mod csv_parser;
|
||||
|
||||
#[derive(Debug, Clone, Parser)]
|
||||
struct Config {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user