forked from Roflin/gamenight
44 lines
1.1 KiB
Rust
44 lines
1.1 KiB
Rust
|
|
use chrono::DateTime;
|
|
use gamenight_api_client_rs::models::Gamenight;
|
|
|
|
use super::*;
|
|
|
|
#[derive(Clone)]
|
|
pub struct ViewGamenight {
|
|
gamenight: Gamenight
|
|
}
|
|
|
|
impl ViewGamenight {
|
|
pub fn new(gamenight: Gamenight) -> Self {
|
|
Self {
|
|
gamenight
|
|
}
|
|
}
|
|
|
|
pub fn gamenight_localtime(&self) -> Result<String, FlowError> {
|
|
let datetime = DateTime::parse_from_rfc3339(&self.gamenight.datetime)?;
|
|
let offset = *chrono::offset::Local::now().offset();
|
|
Ok(format!("{}", datetime.naive_local().checked_add_offset(offset).unwrap().format("%d-%m-%Y %H:%M")))
|
|
}
|
|
}
|
|
|
|
#[async_trait]
|
|
impl<'a> Flow<'a> for ViewGamenight {
|
|
async fn run(&self, state: &'a mut GamenightState) -> FlowResult<'a> {
|
|
println!("Name: {}", self.gamenight.name);
|
|
println!("When: {}", self.gamenight_localtime()?);
|
|
|
|
|
|
|
|
Ok((FlowOutcome::Successful, state))
|
|
}
|
|
}
|
|
|
|
impl Display for ViewGamenight {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
write!(f, "{} {}", self.gamenight.name, self.gamenight.datetime)
|
|
}
|
|
}
|
|
|