From 76a6e78ccbea125ab5b8c06ff254260759d3140c Mon Sep 17 00:00:00 2001 From: Akshay Date: Tue, 21 Jul 2020 11:24:42 +0530 Subject: switch to local time over utc time --- src/app/impl_self.rs | 4 ++-- src/views.rs | 18 +++++++++++++----- 2 files changed, 15 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/app/impl_self.rs b/src/app/impl_self.rs index 744f906..2450bff 100644 --- a/src/app/impl_self.rs +++ b/src/app/impl_self.rs @@ -118,7 +118,7 @@ impl App { } pub fn status(&self) -> StatusLine { - let today = chrono::Local::now().naive_utc().date(); + let today = chrono::Local::now().naive_local().date(); let remaining = self.habits.iter().map(|h| h.remaining(today)).sum::(); let total = self.habits.iter().map(|h| h.goal()).sum::(); let completed = total - remaining; @@ -207,7 +207,7 @@ impl App { .iter_mut() .find(|x| x.name() == name && x.is_auto()); if let Some(h) = target_habit { - h.modify(Local::now().naive_utc().date(), event); + h.modify(Local::now().naive_local().date(), event); } }; match result { diff --git a/src/views.rs b/src/views.rs index 24c8a4d..da077ac 100644 --- a/src/views.rs +++ b/src/views.rs @@ -43,7 +43,7 @@ where let strikethrough = Style::from(Effect::Strikethrough); let goal_status = - self.view_month_offset() == 0 && self.reached_goal(Local::now().naive_utc().date()); + self.view_month_offset() == 0 && self.reached_goal(Local::now().naive_local().date()); printer.with_style( Style::merge(&[ @@ -77,12 +77,20 @@ where .collect::>(); for (week, line_nr) in days.chunks(7).zip(2..) { let weekly_goal = self.goal() * week.len() as u32; - let is_this_week = week.contains(&Local::now().naive_utc().date()); + let is_this_week = week.contains(&Local::now().naive_local().date()); let remaining = week.iter().map(|&i| self.remaining(i)).sum::(); let completions = weekly_goal - remaining; let full = CONFIGURATION.view_width - 8; - let bars_to_fill = if weekly_goal > 0 {(completions * full as u32) / weekly_goal} else {0}; - let percentage = if weekly_goal > 0 {(completions as f64 * 100.) / weekly_goal as f64} else {0.0}; + let bars_to_fill = if weekly_goal > 0 { + (completions * full as u32) / weekly_goal + } else { + 0 + }; + let percentage = if weekly_goal > 0 { + (completions as f64 * 100.) / weekly_goal as f64 + } else { + 0.0 + }; printer.with_style(future_style, |p| { p.print((4, line_nr), &"─".repeat(full)); }); @@ -141,7 +149,7 @@ where } fn on_event(&mut self, e: Event) -> EventResult { - let now = Local::now().naive_utc().date(); + let now = Local::now().naive_local().date(); if self.is_auto() { return EventResult::Ignored; } -- cgit v1.2.3