Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Doctrine Timestamp Laravel Package

ursusarctosua/doctrine-timestamp

View on GitHub
Deep Wiki
Context7

About

This is MySQL timestamp type implementation for Doctrine ORM.

Using the datetime data type in MySQL may cause a problem when you make a DB connection with different timezones. Instead, the timestamp data type is recommended to make DB server recalculate date values due to timezone.

As far as Doctrine has no type for MySQL timestamp, this lib implements it. It generates timestamp columns when datetimetz column type is specified in entity configuration. Also, to exclude timezone mismatch in DateTime object and MySQL connection, unix timestamp is used to transfer DateTime data from PHP to MySQL and vice versa.

Installation

Use Composer:

composer require ursusarctosua/doctrine-timestamp

Configuration

Doctrine

Register this type with the Doctrine Type system and hook it into the database platform (see Dotrine Custom Mapping Types):

<?php
use Doctrine\DBAL\Types\Type;

Type::addType('datetimetz', 'UrsusArctosUA\DoctrineTimestamp\DBAL\Types\DateTimeTzType');
$conn->getDatabasePlatform()
     ->registerDoctrineTypeMapping('mysql_datetimetz', 'datetimetz');

Symfony

Register type in configuration:

# config/packages/doctrine.yaml

doctrine:
    dbal:
        types:
            datetimetz: UrsusArctosUA\DoctrineTimestamp\DBAL\Types\DateTimeTzType

Usage

Specify this type as a field type in mapping configuration:

<?php
use Doctrine\ORM\Mapping as ORM;
/**
 * @ORM\Entity()
 */
class MyPersistentClass
{
    /**
    * @var \DateTimeInterface
    * @ORM\Column(type="datetimetz")
    */
    private $field;
}

Known bugs

  • Doctrine schema generator generates requests this do nothing when field marked as not null. However, it works correctly for nullable fields.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
gmostafa/php-graphql-client
xeviant/paystack
snowsoft/faker
meditationsteps/blogetc
animalyoung/laravel-influxdb
onix-solutions/sms-telera
lonely-lights/prosetta
oxygen/data
oxygen/core
jengo/base
xiloryx/log-collector
a21ns1g4ts/filament-stripe
la-php/laravel-admin
artisan-build/community-prompts
vleroy/smart
ayles-software/laravel-australian-public-holidays
cboxdk/laravel-id-spatie
cboxdk/laravel-id-billing
cboxdk/laravel-id-billing-bridge
simple-as-fuck/php-performance-log