From 07b654dd2c432394f9e6d135c85c59bf7a992218 Mon Sep 17 00:00:00 2001 From: simivar Date: Mon, 26 Feb 2018 11:42:59 +0100 Subject: Update error message in API/UI if date is before 1992 (#12559) (#12561) * Update error message in API/UI if date is before 1992 (#12559) * Fix test for dates * Fix test for dates * Move creation of $dateOfFirstWebsite object to if block --- core/Date.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'core/Date.php') diff --git a/core/Date.php b/core/Date.php index c33c0ed188..d7b2053910 100644 --- a/core/Date.php +++ b/core/Date.php @@ -41,6 +41,9 @@ class Date /** The default date time string format. */ const DATE_TIME_FORMAT = 'Y-m-d H:i:s'; + + /** Timestamp when first website came online - Tue, 06 Aug 1991 00:00:00 GMT. */ + const FIRST_WEBSITE_TIMESTAMP = 681436800; const DATETIME_FORMAT_LONG = DateTimeFormatProvider::DATE_FORMAT_LONG; const DATETIME_FORMAT_SHORT = DateTimeFormatProvider::DATETIME_FORMAT_SHORT; @@ -141,11 +144,17 @@ class Date $date = new Date($dateString); } $timestamp = $date->getTimestamp(); - // can't be doing web analytics before the 1st website - // Tue, 06 Aug 1991 00:00:00 GMT - if ($timestamp < 681436800) { - throw self::getInvalidDateFormatException($dateString); + + if ($timestamp < self::FIRST_WEBSITE_TIMESTAMP) { + $dateOfFirstWebsite = new self(self::FIRST_WEBSITE_TIMESTAMP); + $message = Piwik::translate('General_ExceptionInvalidDateBeforeFirstWebsite', array( + $date->toString(), + $dateOfFirstWebsite->getLocalized(self::DATE_FORMAT_SHORT), + $dateOfFirstWebsite->getTimestamp() + )); + throw new Exception($message . ": $dateString"); } + if (empty($timezone)) { return $date; } -- cgit v1.2.3