megacommerce_shared/utils/
time.rs

1use chrono::{NaiveDate, Utc};
2
3pub fn time_get_millis() -> u64 {
4  Utc::now().timestamp_millis().try_into().unwrap()
5}
6
7pub fn time_get_seconds() -> u64 {
8  Utc::now().timestamp().try_into().unwrap()
9}
10
11pub fn date_to_milliseconds(date_str: &str) -> Result<String, Box<dyn std::error::Error>> {
12  let naive_date = NaiveDate::parse_from_str(date_str, "%Y-%m-%d")?;
13  let naive_datetime = naive_date.and_hms_opt(0, 0, 0).ok_or("Invalid time")?;
14  Ok(naive_datetime.and_utc().timestamp_millis().to_string())
15}