cakephp: CakeTime::format return wrong date on windows

This is a (multiple allowed):

  • bug
  • enhancement
  • feature-discussion (RFC)
  • CakePHP Version: 2.8.5
  • Platform and Target: windows , PHP Version 5.5.19

from unit test:

public function testCakeTimeVsDateTime() {
        $seconds = 1000;
        $interval = new DateInterval('PT' . $seconds . 'S');
        $nowObj = new DateTime('2099-06-18 09:01:23');
        $dateObj = date_add($nowObj, $interval);
        $expected = date_format($dateObj, "Y-m-d H:i:s");
        $result = CakeTime::format($dateObj, "%Y-%m-%d %H:%M:%S");
        $this->assertEquals($expected, $result);
    }

test fail:

1) OpeningsComponentTest::testCakeTimeVsDateTime
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'2099-06-18 09:18:03'
+'2038-01-19 04:14:07'

another test:

public function testStrtotimeVsDateTime() {
        $seconds = 1000;
        $interval = new DateInterval('PT' . $seconds . 'S');
        $nowObj = new DateTime('2099-06-18 09:01:23');
        $expected = date_format(date_add($nowObj, $interval), "Y-m-d H:i:s");
        $result = date("Y-m-d H:i:s", strtotime("2099-06-18 09:01:23 +$seconds seconds"));
        $this->assertEquals($expected, $result);
    }

test fail:

2) OpeningsComponentTest::testStrtotimeVsDateTime
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'2099-06-18 09:18:03'
+'1970-01-01 01:00:00'

Expected Behavior

CakeTime::format returns wrong date in second test function strtotime returns wrong time

Actual Behavior

CakeTime::format accepts DateTime objects from CakePHP version 2.2 but it’s returns wrong date.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 15 (9 by maintainers)

Most upvoted comments

One could use Chronos, a CakePHP 3.x component. It has no conflicting dependencies, so it can be used in CakePHP 2.x applications, too.

We’re already using IntlDateFormatter exclusively in 3.x. I don’t have much interest in adding new dependencies for 2.x at this stage in its lifetime.