Problem

The problem with $date->getTimestamp() is that if the date is before 1901-12-13, it will return null on 32bit system. $datetimeplus will then be erroneously set to 1970-01-01. This is a major issue whenever an application is handling dates far in the past or future.

This is evident during the unit test of Drupal\Tests\Component\Datetime\DateTimePlusTest::testValidateFormat() when it attempted to put in date as "11-03-31 17:44:00" and expects the return value from DateTimePlus to be "0011-03-31 17:44:00". On a 32-bit, it will return "1970-01-01 00:00:00" instead.

======Output of Unit Test======

Drupal\Tests\Component\Datetime\DateTimePlusTest::testValidateFormat
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'0011-03-31 17:44:00'
+'1970-01-01 00:00:00'

========================

The system I'm testing on:
PHP 7.1.4 32bit
Apache 2.4.25
Windows 7
Drupal 8.3.7

Proposed resolution

I have submitted a pull request on Github.
https://github.com/drupal/core-datetime/pull/1

The propose change will detect if the timestamp is beyond the scope of a 32bit integer and create the datetimeplus differently. Otherwise, it will create the datetimeplus like previously coded.

Comments

ProFire created an issue. See original summary.

ProFire’s picture

Issue summary: View changes