-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement year progress feature
Closes: #92
- Loading branch information
Showing
4 changed files
with
40 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ | |
pub mod agenda; | ||
pub mod calendar; | ||
pub mod date; | ||
pub mod yearprogress; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// SPDX-FileCopyrightText: 2021-2023 Birger Schacht <[email protected]> | ||
// | ||
// SPDX-License-Identifier: MIT | ||
|
||
use crate::Context; | ||
|
||
use chrono; | ||
use chrono::Datelike; | ||
use std::fmt; | ||
|
||
pub struct Yearprogress<'a> { | ||
pub ctx: &'a Context, | ||
} | ||
|
||
impl fmt::Display for Yearprogress<'_> { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
let year = self.ctx.usersetdate.year(); | ||
let day = self.ctx.usersetdate.ordinal(); | ||
let days_in_year: u32 = if self.ctx.usersetdate.leap_year() { | ||
366 | ||
} else { | ||
365 | ||
}; | ||
let days_in_year_left: u32 = days_in_year - day; | ||
let percentage: f32 = (day * 100) as f32 / days_in_year as f32; | ||
let mut ret = format!("{percentage:.3}% of the year {year}\n"); | ||
ret += format!("Day number {day} of {year}, {days_in_year_left} left").as_str(); | ||
write!(f, "{}", ret) | ||
} | ||
} |