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>> {
parse_datetime_offset(NaiveDateTime::parse_from_str(content, fmt).ok()?, FixedOffset::east_opt(8 * 3600)?)
}
pub fn parse_timestamp(timestamp: i64) -> Option<DateTime<FixedOffset>> {
parse_datetime_offset(DateTime::from_timestamp(timestamp, 0)?.naive_utc(), FixedOffset::east_opt(8 * 3600)?)
}
pub fn parse_datetime_offset(datetime: NaiveDateTime, fixed_offset: FixedOffset) -> Option<DateTime<FixedOffset>> {
Some(DateTime::from_naive_utc_and_offset(datetime, fixed_offset))
}
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))
}