Skip to content

Conversation

@Himmelschmidt
Copy link
Contributor

Adds feature flags for chrono (default) and time crate support in apalis-sql.

See https://github.com/orgs/apalis-dev/discussions/649

Changes

  • SqlDateTime type alias that resolves based on enabled feature
  • SqlDateTimeExt trait with now(), to_unix_timestamp(), from_unix_timestamp()
  • No conditional compilation needed in downstream crates

Usage

use apalis_sql::{SqlDateTime, SqlDateTimeExt};

let now = SqlDateTime::now();
let ts = now.to_unix_timestamp();
let dt = SqlDateTime::from_unix_timestamp(ts);

Himmelschmidt added a commit to Himmelschmidt/apalis-postgres that referenced this pull request Dec 26, 2025
- Add chrono/time feature flags for datetime library selection
- Replace direct chrono usage with SqlDateTime and SqlDateTimeExt
- Remove hardcoded chrono dependency in favor of feature-gated support
- Update to apalis-sql path dependency for datetime abstraction

Related to apalis-dev/apalis#655
Himmelschmidt added a commit to Himmelschmidt/apalis-mysql that referenced this pull request Dec 26, 2025
Migrate to SqlDateTime/SqlDateTimeExt from apalis-sql instead of direct
chrono/time usage. Adds migration to convert DATETIME columns to TIMESTAMP
for proper UTC handling.

Related to: apalis-dev/apalis#655
Copy link
Member

@geofmureithi geofmureithi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TBH This looks neat 🚀

Just the small change to move it to its own module
You could also add some module level docs to explain the logic behind it.

@geofmureithi
Copy link
Member

@Himmelschmidt
I have some minor changes + it needs a rebase. It would be nice to get this over ASAP and then the other PRs.

@Himmelschmidt
Copy link
Contributor Author

I'll try to get this done over the next day or two

Make chrono optional (still default) and add time crate as alternative
datetime backend via feature flags.
Aligns with sqlx behavior. Updates CI to require at least one datetime feature.
Adds SqlDateTimeExt extension trait that provides:
- now() - returns current UTC datetime
- to_unix_timestamp() - returns Unix timestamp

This allows downstream crates to use `SqlDateTime::now()` without
any conditional compilation, abstracting over chrono/time.
Adds from_unix_timestamp() method to convert Unix timestamps
back to SqlDateTime, completing the bidirectional conversion API.
Address PR review feedback:
- Rename sql_datetime module to datetime
- Update module doc comment to "DateTime abstraction for unified time handling"
- Remove unnecessary ignore from doc test
- Fix clippy use_self warnings
Copy link
Member

@geofmureithi geofmureithi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@geofmureithi
Copy link
Member

@Himmelschmidt

  1. Add a changelog entry
  2. Run cargo vet regenerate exemptions

@Himmelschmidt
Copy link
Contributor Author

@Himmelschmidt

  1. Add a changelog entry
  2. Run cargo vet regenerate exemptions

I ran cargo vet regenerate exemptions but didn't see any changes

@geofmureithi geofmureithi merged commit 82670cf into apalis-dev:main Dec 29, 2025
8 of 9 checks passed
geofmureithi pushed a commit to apalis-dev/apalis-postgres that referenced this pull request Jan 8, 2026
* feat: use SqlDateTime abstraction from apalis-sql

- Add chrono/time feature flags for datetime library selection
- Replace direct chrono usage with SqlDateTime and SqlDateTimeExt
- Remove hardcoded chrono dependency in favor of feature-gated support
- Update to apalis-sql path dependency for datetime abstraction

Related to apalis-dev/apalis#655

* chore: update apalis deps to git and add get_queue impl

* bump: update apalis deps to rc.2

* chore: use crates.io deps instead of git

* refactor: simplify get_queue impl

* chore: update deps and changelog

* revert: get_queue change

* fix: use PgPool for PgContext type alias
Himmelschmidt added a commit to Himmelschmidt/apalis-sqlite that referenced this pull request Jan 8, 2026
Replace direct chrono dependency with DateTime/DateTimeExt from apalis-sql,
enabling support for both chrono and time datetime libraries via feature flags.

Changes:
- Add `chrono` (default) and `time` feature flags
- Use DateTimeExt::from_unix_timestamp instead of chrono::Utc.timestamp_opt
- Update apalis dependencies to 0.7.0-rc.2
- Move chrono to dev-dependencies (only needed for tests/examples)

Related: apalis-dev/apalis#655
Himmelschmidt added a commit to Himmelschmidt/apalis-mysql that referenced this pull request Jan 8, 2026
Replace direct chrono dependency with DateTime/DateTimeExt from apalis-sql,
enabling support for both chrono and time datetime libraries via feature flags.

Changes:
- Add `chrono` (default) and `time` feature flags
- Use DateTimeExt::from_unix_timestamp instead of chrono::Utc.timestamp_opt
- Update apalis dependencies to 0.7.0-rc.2
- Add migration to convert datetime columns to TIMESTAMP
- Move chrono to dev-dependencies (only needed for tests/examples)

Related: apalis-dev/apalis#655
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants