Skip to content

Commit

Permalink
refactor: add some error handle for process data to json
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Dec 9, 2021
1 parent 17fed45 commit d376351
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion examples/entries-define.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ entries:
display: "Onenote"
fields:
- title: Title
- created_date: String
- created_date: Date
- updated_date: Date
- category: String
- notebook: String
Expand Down
3 changes: 3 additions & 0 deletions quake_core/src/helper/quake_time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ mod tests {

let filter4 = "created_date > 2021.12.09";
assert_eq!(replace_to_unix(filter4), "created_date > 1639008000");
//
// let filter2 = "created_date > 2021-08-20 06:32:28.537346";
// assert_eq!(replace_to_unix(filter2), "created_date > 1586729457");
}

#[test]
Expand Down
14 changes: 10 additions & 4 deletions quake_core/src/usecases/entrysets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,22 @@ impl Entrysets {
let string = fs::read_to_string(&file)?;

let mut entry_file = EntryFile::from(&*string, index)?;
entry_file.name = format!("{}", file.file_name().unwrap().to_str().unwrap());
entry_file.name = format!("{}", &file.file_name().unwrap().to_str().unwrap());

for (k, v) in &entry_file.fields {
// convert for time
if let Some(field_type) = type_maps.get(k) {
if let MetaField::Date(_date) = field_type {
let value = quake_time::replace_to_unix(v);
let time: usize = value.parse().expect("cannot convert time");
element[k.clone()] = time.into();
continue;
match value.parse::<usize>() {
Ok(time) => {
element[k.clone()] = time.into();
continue;
}
Err(err) => {
println!("parse {:?} error:{:?}", file, err);
}
}
}
}

Expand Down

0 comments on commit d376351

Please sign in to comment.