shared-framework 0.0.17

Reusable building blocks for HTTP services — Hyper routing, SeaORM data layer, validation, OpenAPI docs, jobs, queues, cache.
Documentation
//! UTC date and time helpers.
//!
//! [`DateUtils`] returns the current UTC time and parses/formats RFC 3339 timestamps.
//!
//! ```ignore
//! let now = DateUtils::now();
//! let text = DateUtils::format_rfc3339(&now);
//! let parsed = DateUtils::parse_rfc3339(&text)?;
//! ```
use chrono::{DateTime, Utc};

/// Helpers for current time and RFC 3339 conversion in UTC.
pub struct DateUtils;

impl DateUtils {
    /// Returns the current UTC time.
    pub fn now() -> DateTime<Utc> { Utc::now() }
    /// Parses an RFC 3339 timestamp into UTC. Returns an error on invalid input.
    pub fn parse_rfc3339(s: &str) -> Result<DateTime<Utc>, chrono::ParseError> {
        s.parse::<DateTime<Utc>>()
    }
    /// Formats a UTC timestamp as RFC 3339.
    pub fn format_rfc3339(dt: &DateTime<Utc>) -> String { dt.to_rfc3339() }
}