Skip to content

Commit b9a2004

Browse files
committed
UNIX_TIMETAMP: Add support for zero timestamps
1 parent d52a923 commit b9a2004

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

src/Vectorface/MySQLite/MySQL/DateTime.php

+2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ public static function mysql_unix_timestamp($date = null)
4747
{
4848
if (!isset($date)) {
4949
return time();
50+
} elseif (count_chars(str_replace([":", "-", " "], "", $date), 3) === "0") {
51+
return 0; /* MySQL's implementation returns zero for 0000-00-00 00:00:00 and similar */
5052
}
5153

5254
return strtotime($date);

tests/Vectorface/Tests/MySQLite/MySQLiteTest.php

+2
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ public function testDateTimeFunctions()
4646
$this->assertEquals(718613, MySQLite::mysql_to_days("1967-07-01"));
4747
$this->assertEquals(735599, MySQLite::mysql_to_days("2014-01-01"));
4848
$this->assertEquals(time(), MySQLite::mysql_unix_timestamp());
49+
$this->assertEquals(0, MySQLite::mysql_unix_timestamp("0000-00-00 00:00:00"));
50+
$this->assertEquals(0, MySQLite::mysql_unix_timestamp("0000-00-00"));
4951
$time = time();
5052
$this->assertEquals($time, MySQLite::mysql_unix_timestamp(date("Y-m-d H:i:s")));
5153
}

0 commit comments

Comments
 (0)