sprintf/doctrine-datetime-bundle
A Symfony bundle that adds Doctrine DBAL datetime types and integration helpers, making it easier to map PHP DateTime values to database columns consistently. It wires custom types into Doctrine configuration so date and time handling stays predictable across entities.
This is a Symfony bundle, not a Laravel package — so a Laravel developer will only touch it inside a Symfony/Doctrine codebase (or a Laravel app using doctrine/dbal directly with a Symfony-style kernel). Treat it as a Doctrine DBAL type extension for PostgreSQL.
Minimal steps:
composer require sprintf/doctrine-datetime-bundle
config/bundles.php:
return [
Sprintf\DoctrineDatetimeBundle\SprintfDoctrineDatetimeBundle::class => ['all' => true],
];
config/packages/doctrine.yaml:
doctrine:
dbal:
types:
daterange: Sprintf\DoctrineDatetimeBundle\DBAL\Types\DateRangeType
datetime: Sprintf\DoctrineDatetimeBundle\DBAL\Types\DateTimeType
daterange column on an entity:
#[ORM\Column(type: 'daterange')]
private $availability;
Where to look first: the repository is tiny and effectively undocumented. Read src/DBAL/Types/ directly — the type classes are short and the only reliable source of truth for the value objects they return (if any) and the SQL they emit via getSQLDeclaration() / convertToDatabaseValue().
daterange type, so mapping Postgres range columns to PHP requires a custom type. Once registered, entity mappings, migrations and SchemaTool all work normally with type: 'daterange'.getSQLDeclaration(), doctrine:migrations:diff will emit DATERANGE columns correctly. Always review generated SQL — a hand-rolled type can produce a subtly wrong declaration.->setParameter() with the type instance to round-trip values, and for range predicates (&&, @>, <<) drop to NativeQuery or the DBAL Connection::executeQuery(). Don't expect the bundle to add DQL functions.daterange you need a real Postgres instance — SQLite/MySQL won't emulate range types. Use dama/doctrine-test-bundle with a Postgres container, and assert on SELECT ... WHERE daterange @> :date style predicates to verify the type round-trips.[lower, upper) semantics), convert the DBAL value to your own DTO at the repository boundary so the rest of the app isn't coupled to this bundle's return shape.DATERANGE, TIMESTAMPTZ). On any other driver the schema tool will fail or silently degrade. Guard your test matrix accordingly.date/timestamp in Doctrine. Registering a custom datetime type can clash with Doctrine's built-in datetime — override it deliberately or rename the mapping key, otherwise you'll get confusing conversion bugs.datetime type that maps to TIMESTAMPTZ will apply server/session timezone conversion. Verify whether the type stores UTC, and be explicit with DateTimeImmutable in mappings. Off-by-hours bugs here are common and silent.[)/(] bounds semantics that a naive PHP array/DTO won't capture. Check convertToPHPValue() for how it represents an empty or unbounded range ([2024-01-01,)) before coding against it.doctrine.yaml and that the bundle's compiler pass ran (bin/console debug:config doctrine or doctrine:dbal:debug equivalents). Clearing the container cache is often the fix after registering a type.How can I help you explore Laravel packages today?