Module datetime

Module datetime 

Source
Expand description

DateTime abstraction for unified time handling DateTime abstraction for unified time handling.

This module provides a unified API for datetime operations in the SQL backends, abstracting over the differences between the chrono and time crates.

§Feature Flags

The datetime implementation is selected based on enabled features:

  • time feature enabled: Uses time::OffsetDateTime as the underlying type. This takes precedence even if chrono is also enabled.
  • chrono feature enabled (without time): Uses chrono::DateTime<Utc>.

§Why This Abstraction?

Different SQL database drivers have varying levels of support for datetime crates. Some work better with chrono, others with time. This module allows users to choose the datetime crate that best fits their database driver and application needs, while the rest of the codebase uses a consistent API through the DateTimeExt trait.

§Usage

use apalis_sql::{DateTime, DateTimeExt};

// Get current time (works with either feature)
let now = DateTime::now();

// Convert to Unix timestamp
let timestamp = now.to_unix_timestamp();

// Create from Unix timestamp
let dt = DateTime::from_unix_timestamp(timestamp);

Traits§

DateTimeExt
Extension trait for SQL datetime operations.

Type Aliases§

DateTime
DateTime type alias that uses either chrono or time depending on enabled features.