feat: add cargo today command (#43)
This commit is contained in:
@@ -2,6 +2,9 @@ use std::error::Error;
|
||||
use std::fmt::Display;
|
||||
use std::str::FromStr;
|
||||
|
||||
#[cfg(feature = "today")]
|
||||
use chrono::{Datelike, Local};
|
||||
|
||||
/// A valid day number of advent (i.e. an integer in range 1 to 25).
|
||||
///
|
||||
/// # Display
|
||||
@@ -37,6 +40,19 @@ impl Day {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "today")]
|
||||
impl Day {
|
||||
/// Returns the current day if it's between the 1st and the 25th of december, `None` otherwise.
|
||||
pub fn today() -> Option<Self> {
|
||||
let today = Local::now();
|
||||
if today.month() == 12 && today.day() <= 25 {
|
||||
Self::new(u8::try_from(today.day()).ok()?)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for Day {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "{:02}", self.0)
|
||||
|
||||
Reference in New Issue
Block a user