-
-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rationale of this project #6
Comments
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 |
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);
}
} |
Hello ! I just found this project. After reading the code, I understand that it take a datetime with any timezone and convert it to an utc datetime. But I don't understand why do this this way instead of simply using datetimetz? I guess if this lib exists, it's because the need exists but really I can't figure it 😃
The text was updated successfully, but these errors were encountered: