2022-04-10 22:21:45 +00:00
|
|
|
use std::fmt;
|
2022-05-02 15:53:10 +00:00
|
|
|
|
|
|
|
use chrono::{DateTime, Datelike, NaiveDateTime, Timelike, Utc};
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
|
2022-04-10 22:21:45 +00:00
|
|
|
use crate::to_animal_names;
|
|
|
|
|
2022-05-02 15:53:10 +00:00
|
|
|
#[derive(Serialize, Deserialize)]
|
2022-04-10 22:21:45 +00:00
|
|
|
pub struct Pasta {
|
2022-05-02 15:53:10 +00:00
|
|
|
pub id: u64,
|
|
|
|
pub content: String,
|
|
|
|
pub file: String,
|
|
|
|
pub created: i64,
|
|
|
|
pub expiration: i64,
|
|
|
|
pub pasta_type: String,
|
2022-04-10 22:21:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Pasta {
|
2022-05-02 15:53:10 +00:00
|
|
|
pub fn id_as_animals(&self) -> String {
|
|
|
|
to_animal_names(self.id)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn created_as_string(&self) -> String {
|
|
|
|
let date = DateTime::<Utc>::from_utc(NaiveDateTime::from_timestamp(self.created, 0), Utc);
|
|
|
|
format!(
|
|
|
|
"{:02}-{:02} {}:{}",
|
|
|
|
date.month(),
|
|
|
|
date.day(),
|
|
|
|
date.hour(),
|
|
|
|
date.minute(),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn expiration_as_string(&self) -> String {
|
|
|
|
let date =
|
|
|
|
DateTime::<Utc>::from_utc(NaiveDateTime::from_timestamp(self.expiration, 0), Utc);
|
|
|
|
format!(
|
|
|
|
"{:02}-{:02} {}:{}",
|
|
|
|
date.month(),
|
|
|
|
date.day(),
|
|
|
|
date.hour(),
|
|
|
|
date.minute(),
|
|
|
|
)
|
|
|
|
}
|
2022-04-10 22:21:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl fmt::Display for Pasta {
|
2022-05-02 15:53:10 +00:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
|
|
write!(f, "{}", self.content)
|
|
|
|
}
|
2022-04-10 22:21:45 +00:00
|
|
|
}
|