use chrono::{DateTime, Local, Utc};
use serde::{Deserialize, Serialize};
use crate::rubase::{BaseEntitySingle};
use crate::rubase::getself::GetSelf;
use crate::rubase::rutils::local_now;
#[derive(Debug, Serialize,Deserialize, Default, Clone)]
pub struct DateRange {
start: DateTime<Local>,
end: DateTime<Local>,
}
impl BaseEntitySingle for DateRange {}
impl GetSelf for DateRange {
}
impl DateRange {
pub fn newOf(start: DateTime<Local>, end: DateTime<Local>) -> DateRange {
Self { start, end }
}
pub fn new() -> Self {
Self {
..Default::default()
}
}
pub fn init(&self) -> DateRange {
Self {
start: local_now(),
end: local_now(),
}
}
pub fn local_now() -> DateTime<Local> {
Local::now()
}
pub fn utc_now() -> DateTime<Utc> {
Utc::now()
}
pub fn local_now2str() -> String {
Local::now().format("%Y-%m-%d %H:%M:%S").to_string()
}
pub fn utc_now2str() -> String {
Utc::now().format("%Y-%m-%d %H:%M:%S").to_string()
}
pub fn local_now2str_rfc3339() -> String {
Local::now().format("%Y-%m-%dT%H:%M:%S%z").to_string()
}
pub fn utc_now2str_rfc3339() -> String {
Utc::now().format("%Y-%m-%dT%H:%M:%S%z").to_string()
}
}