diff options
Diffstat (limited to 'src/ui/tasks_page.rs')
-rwxr-xr-x | src/ui/tasks_page.rs | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/src/ui/tasks_page.rs b/src/ui/tasks_page.rs index 911b005..192a309 100755 --- a/src/ui/tasks_page.rs +++ b/src/ui/tasks_page.rs @@ -17,9 +17,11 @@ use adw::prelude::{PreferencesGroupExt, PreferencesPageExt}; use adw::subclass::prelude::*; use chrono::{DateTime, Duration, Local}; +use chrono_locale::LocaleDate; use gettextrs::*; use gtk::subclass::prelude::*; use gtk::{glib, prelude::*}; +use std::env; use crate::database::{self, SortOrder, TaskSort}; use crate::settings_manager; @@ -87,6 +89,17 @@ impl FurTasksPage { pub fn build_task_list(&self) { let imp = imp::FurTasksPage::from_instance(&self); + // Get user's locale for date formatting + let locale_env = env::var("LANG"); + let user_locale: String; + if let Err(_) = locale_env { + user_locale = "en_US".to_string(); + } else { + let locale_env = locale_env.unwrap(); + let split_locale: Vec<&str> = locale_env.split(".").collect(); + user_locale = split_locale[0].to_string(); + } + let tasks_list = database::retrieve(TaskSort::StartTime, SortOrder::Descending).unwrap(); let mut uniq_date_list: Vec<String> = Vec::new(); @@ -99,7 +112,7 @@ impl FurTasksPage { for task in tasks_list { let task_clone = task.clone(); let date = DateTime::parse_from_rfc3339(&task.start_time).unwrap(); - let date = date.format("%h %e").to_string(); + let date = date.formatl("%h %e", &user_locale).to_string(); if !uniq_date_list.contains(&date) { // if same_date_list is empty, push "date" to it // if it is not empty, push it to a vec of vecs, and then clear it @@ -135,8 +148,8 @@ impl FurTasksPage { // Create FurTasksGroups for all unique days let now = Local::now(); let yesterday = now - Duration::days(1); - let yesterday = yesterday.format("%h %e").to_string(); - let today = now.format("%h %e").to_string(); + let yesterday = yesterday.formatl("%h %e", &user_locale).to_string(); + let today = now.formatl("%h %e", &user_locale).to_string(); for i in 0..uniq_date_list.len() { let group = FurTasksGroup::new(); if uniq_date_list[i] == today { |