Weave Code
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.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky