chronos-x 0.1.0

A CLI tool to generate a timestamp with an optional offset
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
use chrono::{DateTime, Local, TimeZone, SecondsFormat};

pub fn generate_timestamp(offset_seconds: i64, format: &str) -> Result<String, String> {
    let now = Local::now();
    let target_time = now + chrono::Duration::seconds(offset_seconds);

    match format.to_lowercase().as_str() {
        "rfc3339" => Ok(target_time.to_rfc3339_opts(SecondsFormat::Secs, true)),
        "default" => Ok(target_time.format("%Y-%m-%d %H:%M:%S").to_string()),
        other => Err(format!("Unsupported format: {}", other)),
    }
}