about summary refs log tree commit diff
path: root/src/ui/tasks_page.rs
diff options
context:
space:
mode:
authorRicky Kresslein <rk@lakoliu.com>2022-06-16 14:33:21 +0300
committerRicky Kresslein <rk@lakoliu.com>2022-06-16 14:35:36 +0300
commitd994355b5d69e6baaf1705a90b631be1c238f1dc (patch)
treef37eefc0e5fc19ca46d95c17de0f878a30401d30 /src/ui/tasks_page.rs
parent5d10ae6499350617e853c77382ae1775535c3646 (diff)
downloadFurtherance-d994355b5d69e6baaf1705a90b631be1c238f1dc.tar.zst
Localize date headings (Issue #54)
Diffstat (limited to 'src/ui/tasks_page.rs')
-rwxr-xr-xsrc/ui/tasks_page.rs19
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 {