df-helper 0.2.26

df helper tools db cache
Documentation
use chrono::prelude::*;

/// 年月日
pub fn date(utc: bool) -> String {
    let fmt = "%Y-%m-%d";
    return {
        if utc {
            Utc::now().format(fmt).to_string()
        } else {
            Local::now().format(fmt).to_string()
        }
    };
}

/// 年月日转时间戳
pub fn to_timestamp(date: &str, unit: &str) -> i64 {
    let fmt = "%Y-%m-%d %H:%M:%S";
    let timestamp = NaiveDateTime::parse_from_str(&*format!("{} 00:00:00", date), fmt).unwrap();
    let local = Local.timestamp(0, 0).offset().utc_minus_local() as i64;
    match unit {
        "ms" => {
            timestamp.timestamp_millis() + local * 1000
        }
        _ => {
            timestamp.timestamp() + local
        }
    }
}