Comments (2)
Hello, I believe it is because in most cases we always store UTC date so there's no need to bother with TZ then. With this type we can safely use TIMESTAMP
type in postgres.
from doctrine-utcdatetime.
Hi! I recently started using this library to ensure the stored dates in a MySQL/MariaDB database are stored in UTC, unlike Doctrine DBAL DateTimeTypeTz which stores dates in the timezone set for the DateTime object. FYI: MySQL doesn't support storing timezone information for dates.
Previously the dates in my application were stored in UTC+1 or UTC+2 (for Daylight Saving Time). This raised some issues (e.g. duplicate datetimes), since my application should show data in chronological order.
Using this library I can store the exact UTC date at which moment an event occurred. For some dates I store the original timezone in a separate field for display purposes only.
Eg. as entity:
<?php
/**
* @ORM\Entity
*/
class User {
/**
* The date of registration stored in UTC.
*
* @var \DateTime|null
*
* @ORM\Column(type="datetime", name="registration_date", nullable=true)
*/
private $registrationDate;
/**
* The timezone of the registration date (eg. Europe/Amsterdam).
*
* @var string|null
*
* @ORM\Column(type="string", name="registration_date_tz", length=32, nullable=true)
*/
private $registrationDateTimeZone;
/**
* @param \DateTimeInterface $registrationDate
*/
public function setRegistrationDate(DateTimeInterface $registrationDate): void
{
$this->registrationDate = $registrationDate;
$this->registrationDateTimeZone = $registrationDate->getTimezone()->getName();
}
/**
* @return \DateTime
*/
public function getRegistrationDate(): ?DateTime
{
if ($this->registrationDate === null) {
return null;
}
$tz = new DateTimeZone($this->registrationDateTimeZone);
return $this->registrationDate->setTimezone($tz);
}
}
from doctrine-utcdatetime.
Related Issues (3)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from doctrine-utcdatetime.