/* This file is part of DarkFi (https://dark.fi)
*
* Copyright (C) 2020-2024 Dyne.org foundation
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*/
use std::{
env,
fs::{self, File},
io::Write,
process::Command,
};
use chrono::{Datelike, Local, NaiveDate};
use log::error;
use darkfi::{util::time::Timestamp, Result};
use crate::{
primitives::TaskInfo,
view::{comments_table, events_table, taskinfo_table},
};
/// Parse due date (e.g. "1503" for 15 March) as i64 timestamp.
pub fn due_as_timestamp(due: &str) -> Option {
if due.len() != 4 || due.parse::().is_err() {
error!("Due date must be digits of length 4 (e.g. \"1503\" for 15 March)");
return None
}
let (day, month) = (due[..2].parse::().unwrap(), due[2..].parse::().unwrap());
if day > 31 || month > 12 {
error!("Invalid or out-of-range date");
return None
}
let mut year = Local::now().year();
// Ensure the due date is in future
if month < Local::now().month() {
year += 1;
}
if month == Local::now().month() && day < Local::now().day() {
year += 1;
}
let dt = NaiveDate::from_ymd_opt(year, month, day).unwrap().and_hms_opt(12, 0, 0).unwrap();
dt.timestamp().try_into().ok()
}
/// Start up the preferred editor to edit a task's description.
pub fn prompt_text(task_info: TaskInfo, what: &str) -> Result