PHPackages                             janklan/simple-date-time-for-doctrine - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. janklan/simple-date-time-for-doctrine

ActiveLibrary[Database &amp; ORM](/categories/database)

janklan/simple-date-time-for-doctrine
=====================================

Doctrine DBAL types for simple-date-time value objects

00[1 PRs](https://github.com/janklan/simple-date-time-for-doctrine/pulls)PHPCI passing

Since Dec 9Pushed 4mo agoCompare

[ Source](https://github.com/janklan/simple-date-time-for-doctrine)[ Packagist](https://packagist.org/packages/janklan/simple-date-time-for-doctrine)[ RSS](/packages/janklan-simple-date-time-for-doctrine/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (2)Used By (0)

Simple Date Time for Doctrine
=============================

[](#simple-date-time-for-doctrine)

[![Packagist Version](https://camo.githubusercontent.com/c978928439ebc678e24703490fcb80b0beb4b5aa09d18cfb356ce64f108fdf4a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6a616e6b6c616e2f73696d706c652d646174652d74696d652d666f722d646f637472696e65)](https://camo.githubusercontent.com/c978928439ebc678e24703490fcb80b0beb4b5aa09d18cfb356ce64f108fdf4a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6a616e6b6c616e2f73696d706c652d646174652d74696d652d666f722d646f637472696e65)[![CI](https://github.com/janklan/simple-date-time-for-doctrine/actions/workflows/ci.yml/badge.svg)](https://github.com/janklan/simple-date-time-for-doctrine/actions/workflows/ci.yml)[![codecov](https://camo.githubusercontent.com/5030dd52a160f6af4d0543eba130020904b1991dd208f7443457b05415464b64/68747470733a2f2f636f6465636f762e696f2f67682f6a616e6b6c616e2f73696d706c652d646174652d74696d652d666f722d646f637472696e652f67726170682f62616467652e737667)](https://codecov.io/gh/janklan/simple-date-time-for-doctrine)[![License: MIT](https://camo.githubusercontent.com/fdf2982b9f5d7489dcf44570e714e3a15fce6253e0cc6b5aa61a075aac2ff71b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e737667)](https://opensource.org/licenses/MIT)

A Doctrine integration of [janklan/simple-date-time](https://github.com/janklan/simple-date-time).

Why?
----

[](#why)

Databases Doctrine integrates with support `DATE` and `TIME` data types, but Doctrine converts those values to a PHP's native \\DateTimeImmutable objects, forcing additional complexity onto you when you don't want it: time zones, and a *date* when you only want to work with *time* and vice versa.

For example:

- **Birthdays**: A birthday is January 15th, not "January 15th in UTC-5"
- **Special Days**: The Australia Day is on January 26th, The Independence Day is on July 4th - regardless of which time zone in Australia or the U.S. you are
- **Business hours**: Standard business hours across a global enterprise could be 9am to 5pm, regardless of where on Earth do you work for the business: you have to rock up at 9am for work, wherever you are.

[janklan/simple-date-time](https://github.com/janklan/simple-date-time) provides a solution at a PHP level, and this package provides the connecting dots between that solution and Doctrine.

Installation
------------

[](#installation)

```
composer require janklan/simple-date-time-for-doctrine
```

Configuration
-------------

[](#configuration)

This package provides four Doctrine DBAL types:

Type NameDoctrine TypePHP Type`simple_date_immutable``SimpleDateImmutableType``SimpleDateImmutable``simple_date``SimpleDateType``SimpleDate``simple_time_immutable``SimpleTimeImmutableType``SimpleTimeImmutable``simple_time``SimpleTimeType``SimpleTime`### Doctrine (standalone)

[](#doctrine-standalone)

Register the types before using them:

```
use Doctrine\DBAL\Types\Type;
use JanKlan\SimpleDateTimeForDoctrine\SimpleDateImmutableType;
use JanKlan\SimpleDateTimeForDoctrine\SimpleTimeImmutableType;

Type::addType('simple_date_immutable', SimpleDateImmutableType::class);
Type::addType('simple_time_immutable', SimpleTimeImmutableType::class);
```

### Symfony

[](#symfony)

Add to `config/packages/doctrine.yaml`:

```
doctrine:
    dbal:
        types:
            simple_date_immutable: JanKlan\SimpleDateTimeForDoctrine\SimpleDateImmutableType
            simple_date: JanKlan\SimpleDateTimeForDoctrine\SimpleDateType
            simple_time_immutable: JanKlan\SimpleDateTimeForDoctrine\SimpleTimeImmutableType
            simple_time: JanKlan\SimpleDateTimeForDoctrine\SimpleTimeType
```

Usage
-----

[](#usage)

Once configured, use the types in your entity mappings:

```
use Doctrine\ORM\Mapping as ORM;
use JanKlan\SimpleDateTime\SimpleDate;
use JanKlan\SimpleDateTime\SimpleDateImmutable;
use JanKlan\SimpleDateTime\SimpleTime;
use JanKlan\SimpleDateTime\SimpleTimeImmutable;

#[ORM\Entity]
class Employee
{
    #[ORM\Column(type: 'simple_date_immutable')]
    public SimpleDateImmutable $immutableBirthday;

    #[ORM\Column(type: 'simple_time_immutable')]
    public SimpleTimeImmutable $immutableShiftStart;

    #[ORM\Column(type: 'simple_date')]
    public SimpleDate $mutableBirthday;

    #[ORM\Column(type: 'simple_time')]
    public SimpleTime $mutableShiftStart;
}
```

### A warning about object comparison

[](#a-warning-about-object-comparison)

PHP will let you compare the `Simple(Date|Time)(Immutable|)` classes with native `\DateTimeInterface` objects, but doing so is risky and discouraged. All classes offer a custom `isSame`, `isBefore` and `isAfter` methods that should be used for comparison - they will ignore the time zone in the object you're comparing the other side with.

[janklan/simple-date-time](https://github.com/janklan/simple-date-time) provides a [PHPStan rule](https://github.com/janklan/simple-date-time?tab=readme-ov-file#phpstan-integration) that you should add to your PHPStan configuration to get warnings about unsafe comparisons.

Contributing
------------

[](#contributing)

PR are welcome. All you need to do to get started is to check out the repository, run `composer install` and you're done.

Several shorthand commands are configured in Composer: `cs`, `phpstan`, `rector`, `test`, and `preflight`. See `composer.json` to find out what they do.

Run `composer preflight` at least at the end of your work, before you create a pull request.

Testing
-------

[](#testing)

The test suite is split into two categories: **Unit** and **Functional** tests.

### Running all tests

[](#running-all-tests)

By default, PHPUnit runs both unit and functional tests:

```
./vendor/bin/paratest
```

Note: Functional tests require database containers to be running (see below).

### Unit Tests

[](#unit-tests)

Unit tests verify type conversion logic without requiring a database connection:

```
composer test:unit
```

### Functional Tests

[](#functional-tests)

Functional tests verify actual database round-trips (PHP -&gt; DB -&gt; PHP) against real PostgreSQL and MySQL databases.

#### Starting the databases

[](#starting-the-databases)

Start the Docker containers before running functional tests:

```
docker compose up -d
```

This starts:

- **PostgreSQL** on port 15432 (default version: 18)
- **MySQL** on port 13306 (default version: 9)

#### Running functional tests

[](#running-functional-tests)

Run all functional tests:

```
composer test:functional
```

Run only PostgreSQL tests:

```
composer test:functional -- --group postgres
```

Run only MySQL tests:

```
composer test:functional -- --group mysql
```

#### Stopping the databases

[](#stopping-the-databases)

```
docker compose down
```

### Code Coverage

[](#code-coverage)

Generate coverage reports in `./coverage`:

```
composer test:cc
```

License
-------

[](#license)

MIT

###  Health Score

18

—

LowBetter than 8% of packages

Maintenance50

Moderate activity, may be stable

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity14

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/a32d26426a5a46eb135149043845f075a5c1ff65c9436217b2a54d8e50de4e04?d=identicon)[janklan](/maintainers/janklan)

---

Top Contributors

[![janklan](https://avatars.githubusercontent.com/u/5463371?v=4)](https://github.com/janklan "janklan (1 commits)")

### Embed Badge

![Health badge](/badges/janklan-simple-date-time-for-doctrine/health.svg)

```
[![Health](https://phpackages.com/badges/janklan-simple-date-time-for-doctrine/health.svg)](https://phpackages.com/packages/janklan-simple-date-time-for-doctrine)
```

###  Alternatives

[doctrine/orm

Object-Relational-Mapper for PHP

10.2k285.3M6.2k](/packages/doctrine-orm)[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k115.1M102](/packages/jdorn-sql-formatter)[illuminate/database

The Illuminate Database package.

2.8k52.4M9.4k](/packages/illuminate-database)[mongodb/mongodb

MongoDB driver library

1.6k64.0M546](/packages/mongodb-mongodb)[ramsey/uuid-doctrine

Use ramsey/uuid as a Doctrine field type.

90340.3M211](/packages/ramsey-uuid-doctrine)[reliese/laravel

Reliese Components for Laravel Framework code generation.

1.7k3.4M16](/packages/reliese-laravel)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
