1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
//! 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
//!
//! ```rust
//! 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);
//! ```
/// DateTime type alias that uses either chrono or time depending on enabled features.
///
/// When the `time` feature is enabled, this is `time::OffsetDateTime`.
/// When the `chrono` feature is enabled (and `time` is not), this is `chrono::DateTime<Utc>`.
pub type DateTime = DateTime;
/// DateTime type alias that uses either chrono or time depending on enabled features.
///
/// When the `time` feature is enabled, this is `time::OffsetDateTime`.
/// When the `chrono` feature is enabled (and `time` is not), this is `chrono::DateTime<Utc>`.
pub type DateTime = OffsetDateTime;
/// Extension trait for SQL datetime operations.
///
/// This trait provides a unified API for datetime operations regardless of
/// whether `chrono` or `time` feature is enabled.