Use an enum for dialect (#80)
This commit is contained in:
parent
19bd00f620
commit
a04865d9d8
2 changed files with 22 additions and 6 deletions
|
@ -19,9 +19,28 @@ pub enum SearchMode {
|
|||
FullText,
|
||||
}
|
||||
|
||||
// FIXME: Can use upstream Dialect enum if https://github.com/stevedonovan/chrono-english/pull/16 is merged
|
||||
#[derive(Clone, Debug, Deserialize, Copy)]
|
||||
pub enum Dialect {
|
||||
#[serde(rename = "us")]
|
||||
Us,
|
||||
|
||||
#[serde(rename = "uk")]
|
||||
Uk,
|
||||
}
|
||||
|
||||
impl From<Dialect> for chrono_english::Dialect {
|
||||
fn from(d: Dialect) -> chrono_english::Dialect {
|
||||
match d {
|
||||
Dialect::Uk => chrono_english::Dialect::Uk,
|
||||
Dialect::Us => chrono_english::Dialect::Us,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize)]
|
||||
pub struct Settings {
|
||||
pub dialect: String,
|
||||
pub dialect: Dialect,
|
||||
pub auto_sync: bool,
|
||||
pub sync_address: String,
|
||||
pub sync_frequency: String,
|
||||
|
|
|
@ -2,7 +2,7 @@ use std::collections::HashMap;
|
|||
|
||||
use chrono::prelude::*;
|
||||
use chrono::Duration;
|
||||
use chrono_english::{parse_date_string, Dialect};
|
||||
use chrono_english::parse_date_string;
|
||||
|
||||
use cli_table::{format::Justify, print_stdout, Cell, Style, Table};
|
||||
use eyre::{eyre, Result};
|
||||
|
@ -84,10 +84,7 @@ impl Cmd {
|
|||
words.join(" ")
|
||||
};
|
||||
|
||||
let start = match settings.dialect.to_lowercase().as_str() {
|
||||
"uk" => parse_date_string(&words, Local::now(), Dialect::Uk)?,
|
||||
_ => parse_date_string(&words, Local::now(), Dialect::Us)?,
|
||||
};
|
||||
let start = parse_date_string(&words, Local::now(), settings.dialect.into())?;
|
||||
let end = start + Duration::days(1);
|
||||
|
||||
let history = db.range(start.into(), end.into()).await?;
|
||||
|
|
Loading…
Reference in a new issue