pub use chrono::*;
pub const LOG_DATE_FORMAT: &'static str = "[%Y-%m-%d][%H:%M:%S]";
pub const LOG_FILE_DATE_FORMAT: &'static str = "%Y-%m-%d_%H-%M-%S";
pub const STANDARD_DATETIME_FORMAT: &'static str = "%Y-%m-%d %H:%M:%S";
pub fn now() -> DateTime<Utc> {
Utc::now()
}
pub fn parse_str(content: &str, fmt: &str) -> Option<DateTime<Utc>> {
Some(NaiveDateTime::parse_from_str(content, fmt).ok()?.and_utc())
}
pub fn parse_china_str(content: &str, fmt: &str) -> Option<DateTime<FixedOffset>> {
let shanghai_offset = FixedOffset::east_opt(8 * 3600)?; NaiveDateTime::parse_from_str(content, fmt)
.ok()?
.and_local_timezone(shanghai_offset)
.single()
}
pub fn china_now() -> Option<DateTime<FixedOffset>> {
let shanghai_offset = FixedOffset::east_opt(8 * 3600)?; Some(DateTime::from_naive_utc_and_offset(
Utc::now().naive_utc(),
shanghai_offset,
))
}