Skip to content

Commit

Permalink
Merge branch 'release-0.7.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
nimaaskarian committed Mar 31, 2024
2 parents c9ee1b8 + aa63048 commit 72d8c51
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 23 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "c3"
version = "0.6.2"
version = "0.7.0"
edition = "2021"

[dependencies]
Expand Down
95 changes: 95 additions & 0 deletions patches/jalali-date.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
diff --git a/Cargo.lock b/Cargo.lock
index 71501d1..b96b543 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -124,6 +124,7 @@ dependencies = [
"clap",
"crossterm",
"home",
+ "jalali-date",
"ratatui",
"scanf",
"sha1",
@@ -350,6 +351,12 @@ dependencies = [
"either",
]

+[[package]]
+name = "jalali-date"
+version = "0.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d4de89bd2cecffc3235b702c93c504136ef8ebf3c2a934d34297032fb83dec07"
+
[[package]]
name = "js-sys"
version = "0.3.67"
diff --git a/Cargo.toml b/Cargo.toml
index 4bc6bd5..dec0986 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -12,6 +12,7 @@ crossterm = "0.27.0"
tui-textarea = "0.4.0"
chrono = "0.4.31"
clap = { version = "4.4.18", features = ["derive", "string"] }
+jalali-date = "0.2.0"

[profile.release]
codegen-units = 1
diff --git a/src/date.rs b/src/date.rs
index ffc7343..51aa610 100644
--- a/src/date.rs
+++ b/src/date.rs
@@ -1,5 +1,7 @@
-use chrono::{Local ,NaiveDate, Duration};
+use chrono::{Datelike, Duration, Local, NaiveDate};
use chrono::format::ParseError;
+use jalali_date::{jalali_to_gregorian, to_jalali};
+use scanf::sscanf;
const FORMAT: &str = "%Y-%m-%d";

pub type Type = NaiveDate;
@@ -9,9 +11,27 @@ pub fn parse(date_string: &String) -> Result<Type, ParseError> {
NaiveDate::parse_from_str(date_string.as_str(), FORMAT)
}

+fn jalali_to_georgian_naive(j_year: i32, j_month: i32, j_day: i32) -> Option<Type> {
+
+ let g_date = jalali_to_gregorian(j_year, j_month, j_day);
+ NaiveDate::from_ymd_opt(g_date.year , g_date.month as u32, g_date.day as u32)
+}
+
+#[derive(Debug)]
+pub enum Error {
+ ParseFailed,
+}
#[inline(always)]
-pub fn parse_user_input(date_string: &String) -> Result<Type, ParseError> {
- parse(date_string)
+pub fn parse_user_input(date_string: &String) -> Result<Type, Error> {
+ let mut j_year = 0;
+ let mut j_month = 0;
+ let mut j_day = 0;
+ if sscanf!(date_string,"{}-{}-{}", j_year, j_month, j_day).is_ok() {
+ if let Some(date) = jalali_to_georgian_naive(j_year, j_month, j_day) {
+ return Ok(date)
+ }
+ }
+ Err(Error::ParseFailed)
}

#[inline]
@@ -22,7 +42,13 @@ pub fn current() -> Type {
#[inline]
pub fn format(input: Option<Type>) -> String {
match input {
- Some(date)=> date.format(FORMAT).to_string(),
+ Some(date)=> {
+ if let Ok(j_date) = to_jalali(date.day() as u16, date.month() as u16, date.year() as u16) {
+ format!("{}-{:0>2}-{:0>2}", j_date.year, j_date.month, j_date.day)
+ } else {
+ String::new()
+ }
+ },
None => String::new(),
}
}
5 changes: 5 additions & 0 deletions src/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ pub fn parse(date_string: &String) -> Result<Type, ParseError> {
NaiveDate::parse_from_str(date_string.as_str(), FORMAT)
}

#[inline(always)]
pub fn parse_user_input(date_string: &String) -> Result<Type, ParseError> {
parse(date_string)
}

#[inline]
pub fn current() -> Type {
NaiveDate::from(Local::now().naive_local())
Expand Down
23 changes: 3 additions & 20 deletions src/todo_app/todo_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,23 +261,6 @@ impl TodoList {
self.undone.insert(0,todo);
}

#[inline]
pub fn all_dependent_files(&mut self, path: &PathBuf, output: &mut Vec<PathBuf>) -> Vec<PathBuf>{
for todo in self.all_todos_mut().iter_mut().flat_map(|v| v.iter_mut()) {
if todo.dependency.is_list() {
todo.dependency.todo_list.all_dependent_files(path, output);
}
}

output.clone()
}

#[inline]
pub fn todos_with_dependency<'a>() -> Vec<&'a Todo> {
let output = vec![];
output
}

#[inline]
pub fn fix_undone(&mut self) {
for index in 0..self.undone.todos.len() {
Expand Down Expand Up @@ -408,7 +391,7 @@ mod tests {
[-0] this one is 0 and done
";

remove_dir_all(&path.parent().unwrap());
remove_dir_all(&path.parent().unwrap()).expect("Remove test failed");
let _ = remove_file(path);
assert_eq!(contents, expected)
}
Expand All @@ -428,7 +411,7 @@ mod tests {
[-0] this one is 0 and done
";

remove_dir_all(&path.parent().unwrap());
remove_dir_all(&path.parent().unwrap()).expect("Remove test failed");
let _ = remove_file(path);
assert_eq!(contents, expected);
}
Expand Down Expand Up @@ -458,7 +441,7 @@ mod tests {
assert_eq!(contents, expected);

todo_list[0].remove_dependency();
let dependency_path = todo_list.write(&path, true)?;
todo_list.write(&path, true)?;
remove_dir_all(&path.parent().unwrap())?;
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion src/tui_app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ impl<'a>TuiApp<'a>{

#[inline]
fn on_reminder(&mut self,str:String) {
if let Ok(date) = date::parse(&str) {
if let Ok(date) = date::parse_user_input(&str) {
if let Some(todo) = self.todo_app.mut_todo() {
todo.schedule.enable_reminder(date);
}
Expand Down

0 comments on commit 72d8c51

Please sign in to comment.