diff --git a/core/includes/common.inc b/core/includes/common.inc index 769b7f0..81aeded 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -5,7 +5,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Drupal\Component\Utility\NestedArray; use Drupal\Core\Cache\CacheBackendInterface; -use Drupal\Core\Datetime\DrupalDate; +use Drupal\Core\Datetime\DrupalDateTime; use Drupal\Core\Database\Database; use Drupal\Core\Template\Attribute; @@ -1976,8 +1976,8 @@ function format_date($timestamp, $type = 'medium', $format = '', $timezone = NUL break; } - // Create a DrupalDate object from the timestamp and timezone. - $date_time = new DrupalDate($timestamp, $timezones[$timezone]); + // Create a DrupalDateTime object from the timestamp and timezone. + $date_time = new DrupalDateTime($timestamp, $timezones[$timezone]); // Call date_format(). $settings = array('langcode' => $langcode); @@ -4961,7 +4961,7 @@ function drupal_page_set_cache($body) { $cache->data['headers'][$header_names[$name_lower]] = $value; if ($name_lower == 'expires') { // Use the actual timestamp from an Expires header if available. - $date = new DrupalDate($value); + $date = new DrupalDateTime($value); $cache->expire = $date->getTimestamp(); } } diff --git a/core/lib/Drupal/Component/Datetime/DateObject.php b/core/lib/Drupal/Component/Datetime/DateTimeBase.php similarity index 98% rename from core/lib/Drupal/Component/Datetime/DateObject.php rename to core/lib/Drupal/Component/Datetime/DateTimeBase.php index 543d49b..35f349c 100644 --- a/core/lib/Drupal/Component/Datetime/DateObject.php +++ b/core/lib/Drupal/Component/Datetime/DateTimeBase.php @@ -2,7 +2,7 @@ /** * @file - * Definition of Drupal\Component\Datetime\DateObject + * Definition of Drupal\Component\Datetime\DateTimeBase */ namespace Drupal\Component\Datetime; @@ -41,7 +41,7 @@ * messages are all in English. * */ -class DateObject extends \DateTime { +class DateTimeBase extends \DateTime { const FORMAT = 'Y-m-d H:i:s'; const CALENDAR = 'gregorian'; @@ -258,7 +258,7 @@ public function prepareTimezone($timezone) { // If the system timezone is missing, use 'UTC'. if (empty($timezone_adjusted) || !$timezone_adjusted instanceOf \DateTimezone) { $system_timezone = date_default_timezone_get(); - $timezone_name = !empty($system_timezone) ? $system_timezone: 'UTC'; + $timezone_name = !empty($system_timezone) ? $system_timezone : 'UTC'; $timezone_adjusted = new \DateTimeZone($timezone_name); } @@ -628,7 +628,7 @@ function canUseIntl() { * Which pattern is used by the format string. When using the * Intl formatter, the format string must use the Intl pattern, * which is different from the pattern used by the DateTime - * format function. Defaults to DateObject::PHP. + * format function. Defaults to DateTimeBase::PHP. * - string $locale * A locale name, using the format specified by the * intlDateFormatter class. Used to control the result of the @@ -670,7 +670,7 @@ function format($format, $settings = array()) { // If we have what we need to use the IntlDateFormatter, do so. if ($this->canUseIntl() && $format_string_type == self::INTL) { - $calendartype = \IntlDateFormatter::GREGORIAN; + $calendar_type = \IntlDateFormatter::GREGORIAN; // If we have information about a calendar and it's not already // in the locale, add it. @@ -680,12 +680,12 @@ function format($format, $settings = array()) { // If we're working with a non-gregorian calendar, indicate that. if (stristr($locale, '@calendar=') && !stristr($locale, '@calendar=' . SELF::CALENDAR)) { - $calendartype = \IntlDateFormatter::TRADITIONAL; + $calendar_type = \IntlDateFormatter::TRADITIONAL; } $datetype = !empty($settings['datetype']) ? $settings['datetype'] : \IntlDateFormatter::FULL; $timetype = !empty($settings['timetype']) ? $settings['timetype'] : \IntlDateFormatter::FULL; - $formatter = new \IntlDateFormatter($locale, $datetype, $timetype, $timezone, $calendartype); + $formatter = new \IntlDateFormatter($locale, $datetype, $timetype, $timezone, $calendar_type); $formatter->setLenient($lenient); $value = $formatter->format($format); } @@ -700,4 +700,4 @@ function format($format, $settings = array()) { } return $value; } -} \ No newline at end of file +} diff --git a/core/lib/Drupal/Core/Datetime/DrupalDate.php b/core/lib/Drupal/Core/Datetime/DrupalDateTime.php similarity index 95% rename from core/lib/Drupal/Core/Datetime/DrupalDate.php rename to core/lib/Drupal/Core/Datetime/DrupalDateTime.php index f13e8d3..e1ed41c 100644 --- a/core/lib/Drupal/Core/Datetime/DrupalDate.php +++ b/core/lib/Drupal/Core/Datetime/DrupalDateTime.php @@ -2,22 +2,22 @@ /** * @file - * Definition of DrupalDate. + * Definition of Drupal\Core\Datetime\DrupalDateTime. */ namespace Drupal\Core\Datetime; -use Drupal\Component\Datetime\DateObject; +use Drupal\Component\Datetime\DateTimeBase; /** - * This class is an extension of the Drupal DateObject class. + * This class is an extension of the Drupal DateTimeBase class. * * This class extends the basic component and adds in Drupal-specific * handling, like translation of the format() method and error * messages. * - * @see Drupal/Component/Datetime/DateObject.php + * @see Drupal/Component/Datetime/DateTimeBase.php */ -class DrupalDate extends DateObject { +class DrupalDateTime extends DateTimeBase { /** * The language code to use when formatting this date. @@ -91,7 +91,7 @@ public function __construct($time = 'now', $timezone = NULL, $format = NULL, $se * Which pattern is used by the format string. When using the * Intl formatter, the format string must use the Intl pattern, * which is different from the pattern used by the DateTime - * format function. Defaults to DateObject::PHP. + * format function. Defaults to DateTimeBase::PHP. * - string $locale * A locale name, using the format specified by the * intlDateFormatter class. Used to control the result of the diff --git a/core/lib/Drupal/Core/TypedData/Type/Date.php b/core/lib/Drupal/Core/TypedData/Type/Date.php index f081830..ae54856 100644 --- a/core/lib/Drupal/Core/TypedData/Type/Date.php +++ b/core/lib/Drupal/Core/TypedData/Type/Date.php @@ -7,15 +7,15 @@ namespace Drupal\Core\TypedData\Type; -use Drupal\Core\Datetime\DrupalDate; +use Drupal\Core\Datetime\DrupalDateTime; use Drupal\Core\TypedData\TypedDataInterface; use InvalidArgumentException; /** * The date data type. * - * The plain value of a date is an instance of the DrupalDate class. For setting - * the value any value supported by the __construct() of the DrupalDate + * The plain value of a date is an instance of the DrupalDateTime class. For setting + * the value any value supported by the __construct() of the DrupalDateTime * class will work, including a DateTime object, a timestamp, a string * date, or an array of date parts. */ @@ -39,7 +39,7 @@ public function setValue($value) { $this->value = $value; } else { - $this->value = $value instanceOf DrupalDate ? $value : new DrupalDate($value); + $this->value = $value instanceOf DrupalDateTime ? $value : new DrupalDateTime($value); if ($this->value->hasErrors()) { throw new InvalidArgumentException("Invalid date format given."); } diff --git a/core/modules/comment/lib/Drupal/comment/CommentFormController.php b/core/modules/comment/lib/Drupal/comment/CommentFormController.php index 9613320..3b9fa9b 100644 --- a/core/modules/comment/lib/Drupal/comment/CommentFormController.php +++ b/core/modules/comment/lib/Drupal/comment/CommentFormController.php @@ -7,7 +7,7 @@ namespace Drupal\comment; -use Drupal\Core\Datetime\DrupalDate; +use Drupal\Core\Datetime\DrupalDateTime; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityFormController; @@ -237,7 +237,7 @@ public function validate(array $form, array &$form_state) { $account = user_load_by_name($form_state['values']['name']); $form_state['values']['uid'] = $account ? $account->uid : 0; - $date = new DrupalDate($form_state['values']['date']); + $date = new DrupalDateTime($form_state['values']['date']); if ($date->hasErrors()) { form_set_error('date', t('You have to specify a valid date.')); } @@ -273,7 +273,7 @@ public function submit(array $form, array &$form_state) { if (empty($comment->date)) { $comment->date = 'now'; } - $date = new DrupalDate($comment->date); + $date = new DrupalDateTime($comment->date); $comment->created = $date->getTimestamp(); $comment->changed = REQUEST_TIME; diff --git a/core/modules/node/lib/Drupal/node/NodeFormController.php b/core/modules/node/lib/Drupal/node/NodeFormController.php index ff5ff6d..d9545ff 100644 --- a/core/modules/node/lib/Drupal/node/NodeFormController.php +++ b/core/modules/node/lib/Drupal/node/NodeFormController.php @@ -7,7 +7,7 @@ namespace Drupal\node; -use Drupal\Core\Datetime\DrupalDate; +use Drupal\Core\Datetime\DrupalDateTime; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityFormController; @@ -288,7 +288,7 @@ public function validate(array $form, array &$form_state) { } // Validate the "authored on" field. - $date = new DrupalDate($node->date); + $date = new DrupalDateTime($node->date); if ($date->hasErrors()) { form_set_error('date', t('You have to specify a valid date.')); } diff --git a/core/modules/node/node.module b/core/modules/node/node.module index ede29a1..59d9019 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -14,7 +14,7 @@ use Drupal\Core\Database\Query\AlterableInterface; use Drupal\Core\Database\Query\SelectExtender; use Drupal\Core\Database\Query\SelectInterface; -use Drupal\Core\Datetime\DrupalDate; +use Drupal\Core\Datetime\DrupalDateTime; use Drupal\Core\Template\Attribute; use Drupal\node\Node; use Drupal\file\File; @@ -1107,8 +1107,9 @@ function node_submit($node) { if (!empty($node->revision)) { $node->revision_uid = $user->uid; } - $date = new DrupalDate($node->date); - $node->created = $date->getTimestamp(); + + $node_created = new DrupalDateTime(!empty($node->date) ? $node->date : REQUEST_TIME); + $node->created = $node_created->getTimestamp(); $node->validated = TRUE; return $node; diff --git a/core/modules/system/lib/Drupal/system/Tests/Datetime/DateObjectTest.php b/core/modules/system/lib/Drupal/system/Tests/Datetime/DateTimeBaseTest.php similarity index 76% rename from core/modules/system/lib/Drupal/system/Tests/Datetime/DateObjectTest.php rename to core/modules/system/lib/Drupal/system/Tests/Datetime/DateTimeBaseTest.php index 9a6550b..f7625cd 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Datetime/DateObjectTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Datetime/DateTimeBaseTest.php @@ -2,16 +2,16 @@ /** * @file - * Definition of Drupal\system\Tests\Datetime\DateObjectTest. + * Definition of Drupal\system\Tests\Datetime\DateTimeBaseTest. */ namespace Drupal\system\Tests\Datetime; use Drupal\simpletest\WebTestBase; -use Drupal\Component\Datetime\DateObject; +use Drupal\Component\Datetime\DateTimeBase; use DateTimeZone; -class DateObjectTest extends WebTestBase { +class DateTimeBaseTest extends WebTestBase { /** * Test information. */ @@ -44,34 +44,34 @@ public function testDateStrings() { // Create date object from datetime string. $input = '2009-03-07 10:30'; $timezone = 'America/Chicago'; - $date = new DateObject($input, $timezone); + $date = new DateTimeBase($input, $timezone); $value = $date->format('c'); $expected = '2009-03-07T10:30:00-06:00'; - $this->assertEqual($expected, $value, "Test new DateObject($input, $timezone): should be $expected, found $value."); + $this->assertEqual($expected, $value, "Test new DateTimeBase($input, $timezone): should be $expected, found $value."); // Same during daylight savings time. $input = '2009-06-07 10:30'; $timezone = 'America/Chicago'; - $date = new DateObject($input, $timezone); + $date = new DateTimeBase($input, $timezone); $value = $date->format('c'); $expected = '2009-06-07T10:30:00-05:00'; - $this->assertEqual($expected, $value, "Test new DateObject($input, $timezone): should be $expected, found $value."); + $this->assertEqual($expected, $value, "Test new DateTimeBase($input, $timezone): should be $expected, found $value."); // Create date object from date string. $input = '2009-03-07'; $timezone = 'America/Chicago'; - $date = new DateObject($input, $timezone); + $date = new DateTimeBase($input, $timezone); $value = $date->format('c'); $expected = '2009-03-07T00:00:00-06:00'; - $this->assertEqual($expected, $value, "Test new DateObject($input, $timezone): should be $expected, found $value."); + $this->assertEqual($expected, $value, "Test new DateTimeBase($input, $timezone): should be $expected, found $value."); // Same during daylight savings time. $input = '2009-06-07'; $timezone = 'America/Chicago'; - $date = new DateObject($input, $timezone); + $date = new DateTimeBase($input, $timezone); $value = $date->format('c'); $expected = '2009-06-07T00:00:00-05:00'; - $this->assertEqual($expected, $value, "Test new DateObject($input, $timezone): should be $expected, found $value."); + $this->assertEqual($expected, $value, "Test new DateTimeBase($input, $timezone): should be $expected, found $value."); } /** @@ -82,18 +82,18 @@ function testDateArrays() { // Create date object from date array, date only. $input = array('year' => 2010, 'month' => 2, 'day' => 28); $timezone = 'America/Chicago'; - $date = new DateObject($input, $timezone); + $date = new DateTimeBase($input, $timezone); $value = $date->format('c'); $expected = '2010-02-28T00:00:00-06:00'; - $this->assertEqual($expected, $value, "Test new DateObject(array('year' => 2010, 'month' => 2, 'day' => 28), $timezone): should be $expected, found $value."); + $this->assertEqual($expected, $value, "Test new DateTimeBase(array('year' => 2010, 'month' => 2, 'day' => 28), $timezone): should be $expected, found $value."); // Create date object from date array with hour. $input = array('year' => 2010, 'month' => 2, 'day' => 28, 'hour' => 10); $timezone = 'America/Chicago'; - $date = new DateObject($input, $timezone); + $date = new DateTimeBase($input, $timezone); $value = $date->format('c'); $expected = '2010-02-28T10:00:00-06:00'; - $this->assertEqual($expected, $value, "Test new DateObject(array('year' => 2010, 'month' => 2, 'day' => 28, 'hour' => 10), $timezone): should be $expected, found $value."); + $this->assertEqual($expected, $value, "Test new DateTimeBase(array('year' => 2010, 'month' => 2, 'day' => 28, 'hour' => 10), $timezone): should be $expected, found $value."); } @@ -106,10 +106,10 @@ function testDateTimestamp() { // local time. $input = 0; $timezone = 'UTC'; - $date = new DateObject($input, $timezone); + $date = new DateTimeBase($input, $timezone); $value = $date->format('c'); $expected = '1970-01-01T00:00:00+00:00'; - $this->assertEqual($expected, $value, "Test new DateObject($input, $timezone): should be $expected, found $value."); + $this->assertEqual($expected, $value, "Test new DateTimeBase($input, $timezone): should be $expected, found $value."); $expected = 'UTC'; $value = $date->getTimeZone()->getName(); @@ -135,11 +135,11 @@ function testDateTimestamp() { // value both in UTC and the local timezone. $input = 0; $timezone = 'America/Los_Angeles'; - $date = new DateObject($input, $timezone); + $date = new DateTimeBase($input, $timezone); $offset = $date->getOffset(); $value = $date->format('c'); $expected = '1969-12-31T16:00:00-08:00'; - $this->assertEqual($expected, $value, "Test new DateObject($input, $timezone): should be $expected, found $value."); + $this->assertEqual($expected, $value, "Test new DateTimeBase($input, $timezone): should be $expected, found $value."); $expected = 'America/Los_Angeles'; $value = $date->getTimeZone()->getName(); @@ -171,10 +171,10 @@ function testTimezoneConversion() { // it to a local date. $input = '1970-01-01 00:00:00'; $timezone = 'UTC'; - $date = new DateObject($input, $timezone); + $date = new DateTimeBase($input, $timezone); $value = $date->format('c'); $expected = '1970-01-01T00:00:00+00:00'; - $this->assertEqual($expected, $value, "Test new DateObject('$input', '$timezone'): should be $expected, found $value."); + $this->assertEqual($expected, $value, "Test new DateTimeBase('$input', '$timezone'): should be $expected, found $value."); $expected = 'UTC'; $value = $date->getTimeZone()->getName(); @@ -199,11 +199,11 @@ function testTimezoneConversion() { // Convert the local time to UTC using string input. $input = '1969-12-31 16:00:00'; $timezone = 'America/Los_Angeles'; - $date = new DateObject($input, $timezone); + $date = new DateTimeBase($input, $timezone); $offset = $date->getOffset(); $value = $date->format('c'); $expected = '1969-12-31T16:00:00-08:00'; - $this->assertEqual($expected, $value, "Test new DateObject('$input', '$timezone'): should be $expected, found $value."); + $this->assertEqual($expected, $value, "Test new DateTimeBase('$input', '$timezone'): should be $expected, found $value."); $expected = 'America/Los_Angeles'; $value = $date->getTimeZone()->getName(); @@ -236,37 +236,37 @@ function testDateFormat() { $input = '2009'; $timezone = NULL; $format = 'Y'; - $date = new DateObject($input, $timezone, $format); + $date = new DateTimeBase($input, $timezone, $format); $value = $date->format('Y'); $expected = '2009'; - $this->assertEqual($expected, $value, "Test new DateObject($input, $timezone, $format): should be $expected, found $value."); + $this->assertEqual($expected, $value, "Test new DateTimeBase($input, $timezone, $format): should be $expected, found $value."); // Create a month and year-only date. $input = '2009-10'; $timezone = NULL; $format = 'Y-m'; - $date = new DateObject($input, $timezone, $format); + $date = new DateTimeBase($input, $timezone, $format); $value = $date->format('Y-m'); $expected = '2009-10'; - $this->assertEqual($expected, $value, "Test new DateObject($input, $timezone, $format): should be $expected, found $value."); + $this->assertEqual($expected, $value, "Test new DateTimeBase($input, $timezone, $format): should be $expected, found $value."); // Create a time-only date. $input = '0000-00-00T10:30:00'; $timezone = NULL; $format = 'Y-m-d\TH:i:s'; - $date = new DateObject($input, $timezone, $format); + $date = new DateTimeBase($input, $timezone, $format); $value = $date->format('H:i:s'); $expected = '10:30:00'; - $this->assertEqual($expected, $value, "Test new DateObject($input, $timezone, $format): should be $expected, found $value."); + $this->assertEqual($expected, $value, "Test new DateTimeBase($input, $timezone, $format): should be $expected, found $value."); // Create a time-only date. $input = '10:30:00'; $timezone = NULL; $format = 'H:i:s'; - $date = new DateObject($input, $timezone, $format); + $date = new DateTimeBase($input, $timezone, $format); $value = $date->format('H:i:s'); $expected = '10:30:00'; - $this->assertEqual($expected, $value, "Test new DateObject($input, $timezone, $format): should be $expected, found $value."); + $this->assertEqual($expected, $value, "Test new DateTimeBase($input, $timezone, $format): should be $expected, found $value."); } @@ -280,60 +280,60 @@ function testInvalidDates() { $input = '23 abc 2012'; $timezone = NULL; $format = 'd M Y'; - $date = new DateObject($input, $timezone, $format); + $date = new DateTimeBase($input, $timezone, $format); $this->assertNotEqual(count($date->errors), 0, "$input contains an invalid month name and produces errors."); // Test for invalid hour. $input = '0000-00-00T45:30:00'; $timezone = NULL; $format = 'Y-m-d\TH:i:s'; - $date = new DateObject($input, $timezone, $format); + $date = new DateTimeBase($input, $timezone, $format); $this->assertNotEqual(count($date->errors), 0, "$input contains an invalid hour and produces errors."); // Test for invalid day. $input = '0000-00-99T05:30:00'; $timezone = NULL; $format = 'Y-m-d\TH:i:s'; - $date = new DateObject($input, $timezone, $format); + $date = new DateTimeBase($input, $timezone, $format); $this->assertNotEqual(count($date->errors), 0, "$input contains an invalid day and produces errors."); // Test for invalid month. $input = '0000-75-00T15:30:00'; $timezone = NULL; $format = 'Y-m-d\TH:i:s'; - $date = new DateObject($input, $timezone, $format); + $date = new DateTimeBase($input, $timezone, $format); $this->assertNotEqual(count($date->errors), 0, "$input contains an invalid month and produces errors."); // Test for invalid year. $input = '11-08-01T15:30:00'; $timezone = NULL; $format = 'Y-m-d\TH:i:s'; - $date = new DateObject($input, $timezone, $format); + $date = new DateTimeBase($input, $timezone, $format); $this->assertNotEqual(count($date->errors), 0, "$input contains an invalid year and produces errors."); // Test for invalid year from date array. 10000 as a year will // create an exception error in the PHP DateTime object. $input = array('year' => 10000, 'month' => 7, 'day' => 8, 'hour' => 8, 'minute' => 0, 'second' => 0); $timezone = 'America/Chicago'; - $date = new DateObject($input, $timezone); + $date = new DateTimeBase($input, $timezone); $this->assertNotEqual(count($date->errors), 0, "array('year' => 10000, 'month' => 7, 'day' => 8, 'hour' => 8, 'minute' => 0, 'second' => 0) contains an invalid year and produces errors."); // Test for invalid month from date array. $input = array('year' => 2010, 'month' => 27, 'day' => 8, 'hour' => 8, 'minute' => 0, 'second' => 0); $timezone = 'America/Chicago'; - $date = new DateObject($input, $timezone); + $date = new DateTimeBase($input, $timezone); $this->assertNotEqual(count($date->errors), 0, "array('year' => 2010, 'month' => 27, 'day' => 8, 'hour' => 8, 'minute' => 0, 'second' => 0) contains an invalid month and produces errors."); // Test for invalid hour from date array. $input = array('year' => 2010, 'month' => 2, 'day' => 28, 'hour' => 80, 'minute' => 0, 'second' => 0); $timezone = 'America/Chicago'; - $date = new DateObject($input, $timezone); + $date = new DateTimeBase($input, $timezone); $this->assertNotEqual(count($date->errors), 0, "array('year' => 2010, 'month' => 2, 'day' => 28, 'hour' => 80, 'minute' => 0, 'second' => 0) contains an invalid hour and produces errors."); // Test for invalid minute from date array. $input = array('year' => 2010, 'month' => 7, 'day' => 8, 'hour' => 8, 'minute' => 88, 'second' => 0); $timezone = 'America/Chicago'; - $date = new DateObject($input, $timezone); + $date = new DateTimeBase($input, $timezone); $this->assertNotEqual(count($date->errors), 0, "array('year' => 2010, 'month' => 7, 'day' => 8, 'hour' => 8, 'minute' => 88, 'second' => 0) contains an invalid minute and produces errors."); } diff --git a/core/modules/system/lib/Drupal/system/Tests/TypedData/TypedDataTest.php b/core/modules/system/lib/Drupal/system/Tests/TypedData/TypedDataTest.php index bc3863b..00e4c95 100644 --- a/core/modules/system/lib/Drupal/system/Tests/TypedData/TypedDataTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/TypedData/TypedDataTest.php @@ -8,7 +8,7 @@ namespace Drupal\system\Tests\TypedData; use Drupal\simpletest\WebTestBase; -use Drupal\Core\Datetime\DrupalDate; +use Drupal\Core\Datetime\DrupalDateTime; use DateInterval; /** @@ -72,7 +72,7 @@ public function testGetAndSet() { $this->assertNull($wrapper->getValue(), 'Float wrapper is null-able.'); // Date type. - $value = new DrupalDate(REQUEST_TIME); + $value = new DrupalDateTime(REQUEST_TIME); $wrapper = $this->createTypedData(array('type' => 'date'), $value); $this->assertTrue($wrapper->getValue() === $value, 'Date value was fetched.'); $new_value = REQUEST_TIME + 1;