Cactus/time/
mod.rs

1use chrono::{DateTime, Local, Utc};
2use time::format_description::well_known::Iso8601;
3use time::OffsetDateTime;
4
5/// Returns a formatted time string.
6pub fn get_formatted_time() -> String {
7    let now = Utc::now();
8    let local_time: DateTime<Local> = now.with_timezone(&Local); // Convert to local machine time
9    local_time.format("%a %b %d %H:%M:%S %Y").to_string() // Format time
10}
11//returns a none formatted time.
12pub fn get_time() -> DateTime<Local> {
13    let now = Utc::now();
14    now.with_timezone(&Local) // Convert to local machine time
15}
16
17/// Returns the current time formatted using the ISO-8601 standard.
18pub fn get_time_iso() -> Result<String, Box<dyn std::error::Error>> {
19    // Local time in ISO-8601 with numeric offset, e.g. 2025-08-21T14:34:56+02:00
20    let local = OffsetDateTime::now_local()?;
21    Ok(local.format(&Iso8601::DEFAULT)?)
22}