aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cli/mod.rs2
-rw-r--r--src/db/events.rs10
-rw-r--r--src/gui/app.rs5
-rw-r--r--src/gui/calendar.rs3
-rw-r--r--src/main.rs12
-rw-r--r--src/model/repetition.rs15
6 files changed, 26 insertions, 21 deletions
diff --git a/src/cli/mod.rs b/src/cli/mod.rs
index 6ce50af..b952a75 100644
--- a/src/cli/mod.rs
+++ b/src/cli/mod.rs
@@ -5,7 +5,7 @@ use rusqlite::Connection;
use crate::{db, model::event};
pub fn today(conn: &Connection) -> Result<String> {
- let today = Local::today().naive_local();
+ let today = Local::now().date_naive();
let mut events = db::events::list_non_recurring_between(conn, today, today)?;
let recurring_events = db::events::list_recurring(conn)?;
let repetitions = event::repetitions_between(&recurring_events, today, today);
diff --git a/src/db/events.rs b/src/db/events.rs
index 86206bb..1721967 100644
--- a/src/db/events.rs
+++ b/src/db/events.rs
@@ -11,11 +11,11 @@ pub fn insert(conn: &Connection, event: &Event) -> Result<()> {
None => None,
};
- let category = event.category.map(|id| id.to_hyphenated().to_string());
+ let category = event.category.map(|id| id.hyphenated().to_string());
conn.execute(
"INSERT INTO events (id, date, start, end, name, repetition, category, created, updated) VALUES (?, ?, ?, ?, ?, ?, ?, datetime(), datetime())",
- params![event.id.to_hyphenated().to_string(), event.date, event.start, event.end, event.name, repetition, category]
+ params![event.id.hyphenated().to_string(), event.date, event.start, event.end, event.name, repetition, category]
)?;
Ok(())
@@ -27,11 +27,11 @@ pub fn update(conn: &Connection, event: &Event) -> Result<()> {
None => None,
};
- let category = event.category.map(|id| id.to_hyphenated().to_string());
+ let category = event.category.map(|id| id.hyphenated().to_string());
conn.execute(
"UPDATE events SET date = ?, start = ?, end = ?, name = ?, repetition = ?, category = ?, updated = datetime() WHERE id = ?",
- params![event.date, event.start, event.end, event.name, repetition, category, event.id.to_hyphenated().to_string()]
+ params![event.date, event.start, event.end, event.name, repetition, category, event.id.hyphenated().to_string()]
)?;
Ok(())
@@ -40,7 +40,7 @@ pub fn update(conn: &Connection, event: &Event) -> Result<()> {
pub fn delete(conn: &Connection, id: &Uuid) -> Result<()> {
conn.execute(
"DELETE FROM events WHERE id = ?",
- params![id.to_hyphenated().to_string()],
+ params![id.hyphenated().to_string()],
)?;
Ok(())
diff --git a/src/gui/app.rs b/src/gui/app.rs
index 4ed864b..c0fc038 100644
--- a/src/gui/app.rs
+++ b/src/gui/app.rs
@@ -41,9 +41,10 @@ impl App {
.build(),
);
- let today = chrono::offset::Local::today().naive_utc();
+ let today = chrono::offset::Local::now().naive_utc().date();
+ // TODO: error handling
let start_date =
- NaiveDate::from_isoywd(today.year(), today.iso_week().week(), Weekday::Mon);
+ NaiveDate::from_isoywd_opt(today.year(), today.iso_week().week(), Weekday::Mon).unwrap();
let end_date = start_date + Duration::days(7 * 4 - 1);
let events = db::events::list_non_recurring_between(&conn, start_date, end_date)?;
diff --git a/src/gui/calendar.rs b/src/gui/calendar.rs
index f5f9c10..c80efef 100644
--- a/src/gui/calendar.rs
+++ b/src/gui/calendar.rs
@@ -65,7 +65,8 @@ fn attach_days(
1,
1,
);
- d = d.succ();
+ // TODO: error handling
+ d = d.succ_opt().unwrap();
}
}
}
diff --git a/src/main.rs b/src/main.rs
index 56a499c..d3080ab 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -5,17 +5,17 @@ mod model;
mod validation;
use anyhow::Result;
-use structopt::StructOpt;
+use clap::Parser;
-#[derive(StructOpt)]
-#[structopt()]
+#[derive(Parser)]
+#[clap()]
struct Opt {
/// Path of SQLite database in which to store events
- #[structopt(long = "database", default_value = "database.sqlite3")]
+ #[clap(long = "database", default_value = "database.sqlite3")]
db_path: String,
/// List today’s events as plain text
- #[structopt(long = "list-today")]
+ #[clap(long = "list-today")]
list_today: bool,
}
@@ -23,7 +23,7 @@ fn main() -> Result<()> {
let Opt {
db_path,
list_today,
- } = Opt::from_args();
+ } = Opt::parse();
let conn = db::init(&db_path)?;
if list_today {
print!("{}", cli::today(&conn)?);
diff --git a/src/model/repetition.rs b/src/model/repetition.rs
index 155545f..6151cbf 100644
--- a/src/model/repetition.rs
+++ b/src/model/repetition.rs
@@ -80,8 +80,9 @@ impl Repetition {
Box::new(|d| first_weekday_of_month(next_month(d), weekday)),
),
Frequency::Yearly => repeat(
- NaiveDate::from_ymd(event.year(), event.month(), event.day()),
- Box::new(|d| NaiveDate::from_ymd(d.year() + 1, d.month(), d.day())),
+ // TODO: error handling
+ NaiveDate::from_ymd_opt(event.year(), event.month(), event.day()).unwrap(),
+ Box::new(|d| NaiveDate::from_ymd_opt(d.year() + 1, d.month(), d.day()).unwrap()),
),
}
}
@@ -97,14 +98,16 @@ impl Repetition {
}
fn first_weekday_of_month(date: NaiveDate, weekday: Weekday) -> NaiveDate {
- NaiveDate::from_weekday_of_month(date.year(), date.month(), weekday, 1)
+ // TODO: error handling
+ NaiveDate::from_weekday_of_month_opt(date.year(), date.month(), weekday, 1).unwrap()
}
fn next_month(date: NaiveDate) -> NaiveDate {
+ // TODO: error handling
if date.month() == 12 {
- NaiveDate::from_ymd(date.year() + 1, 1, date.day())
+ NaiveDate::from_ymd_opt(date.year() + 1, 1, date.day()).unwrap()
} else {
- NaiveDate::from_ymd(date.year(), date.month() + 1, date.day())
+ NaiveDate::from_ymd_opt(date.year(), date.month() + 1, date.day()).unwrap()
}
}
@@ -290,7 +293,7 @@ mod tests {
}
fn d(y: i32, m: u32, d: u32) -> NaiveDate {
- NaiveDate::from_ymd(y, m, d)
+ NaiveDate::from_ymd_opt(y, m, d)
}
fn from_freq(frequency: Frequency) -> Repetition {