BreweryControlSystem/code/src/misc.rs

30 lines
749 B
Rust

use std::str::FromStr;
use bigdecimal::ToPrimitive;
use chrono::Datelike;
pub const ELEMENTS_PER_PAGE: i32 = 5;
pub fn naivedate_to_jiff(date: chrono::NaiveDate) -> jiff::civil::Date {
jiff::civil::Date::new(
date.year().to_i16().unwrap(),
date.month().to_i8().unwrap(),
date.day().to_i8().unwrap(),
)
.unwrap()
}
pub fn jiff_to_naivedate(date: jiff::civil::Date) -> chrono::NaiveDate {
chrono::NaiveDate::from_ymd_opt(
date.year().to_i32().unwrap(),
date.month().to_u32().unwrap(),
date.day().to_u32().unwrap(),
)
.unwrap()
}
pub fn is_date_okay(date: String) -> bool {
match chrono::NaiveDate::from_str(&date) {
Ok(_) => true,
Err(_) => false,
}
}