diff --git a/core/core.services.yml b/core/core.services.yml index 83ab73201f8f4c63a9b070d747534ebb24dbb120..f18c3f3214f42a0277e469ff059e392ad0ebae8d 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -787,8 +787,8 @@ services: country_manager: class: Drupal\Core\Locale\CountryManager arguments: ['@module_handler'] - date: - class: Drupal\Core\Datetime\Date + date.formatter: + class: Drupal\Core\Datetime\DateFormatter arguments: ['@entity.manager', '@language_manager', '@string_translation', '@config.factory'] feed.bridge.reader: class: Drupal\Component\Bridge\ZfExtensionManagerSfContainer diff --git a/core/includes/batch.inc b/core/includes/batch.inc index 81f0654dc6b4a9878f75ca648a43d64d7bb3d39a..11362208c91aa8a5685aadfea2703d1bcce1dac4 100644 --- a/core/includes/batch.inc +++ b/core/includes/batch.inc @@ -320,9 +320,9 @@ function _batch_process() { '@total' => $total, '@current' => floor($current), '@percentage' => $percentage, - '@elapsed' => \Drupal::service('date')->formatInterval($elapsed / 1000), + '@elapsed' => \Drupal::service('date.formatter')->formatInterval($elapsed / 1000), // If possible, estimate remaining processing time. - '@estimate' => ($current > 0) ? \Drupal::service('date')->formatInterval(($elapsed * ($total - $current) / $current) / 1000) : '-', + '@estimate' => ($current > 0) ? \Drupal::service('date.formatter')->formatInterval(($elapsed * ($total - $current) / $current) / 1000) : '-', ); $message = strtr($progress_message, $values); if (!empty($task_message)) { @@ -411,7 +411,7 @@ function _batch_finished() { if (is_callable($batch_set['finished'])) { $queue = _batch_queue($batch_set); $operations = $queue->getAllItems(); - call_user_func_array($batch_set['finished'], array($batch_set['success'], $batch_set['results'], $operations, \Drupal::service('date')->formatInterval($batch_set['elapsed'] / 1000))); + call_user_func_array($batch_set['finished'], array($batch_set['success'], $batch_set['results'], $operations, \Drupal::service('date.formatter')->formatInterval($batch_set['elapsed'] / 1000))); } } } diff --git a/core/includes/common.inc b/core/includes/common.inc index acb3fe15b9015574874ba5e893273060482d563e..8b241ab37006f5f72a0ef60d450063c714a89600 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -611,10 +611,10 @@ function format_size($size, $langcode = NULL) { * @return * A translated date string in the requested format. * - * @see \Drupal\Component\Datetime\Date::format() + * @see \Drupal\Component\Datetime\DateFormatter::format() */ function format_date($timestamp, $type = 'medium', $format = '', $timezone = NULL, $langcode = NULL) { - return \Drupal::service('date')->format($timestamp, $type, $format, $timezone, $langcode); + return \Drupal::service('date.formatter')->format($timestamp, $type, $format, $timezone, $langcode); } /** diff --git a/core/lib/Drupal/Core/Datetime/Date.php b/core/lib/Drupal/Core/Datetime/DateFormatter.php similarity index 99% rename from core/lib/Drupal/Core/Datetime/Date.php rename to core/lib/Drupal/Core/Datetime/DateFormatter.php index aeae7f81344eae0db8776b6b35bf35adb24df455..6c9108718ff85e434a41fb1347202d8f301063c8 100644 --- a/core/lib/Drupal/Core/Datetime/Date.php +++ b/core/lib/Drupal/Core/Datetime/DateFormatter.php @@ -21,7 +21,7 @@ * * @ingroup i18n */ -class Date { +class DateFormatter { use StringTranslationTrait; /** diff --git a/core/lib/Drupal/Core/Test/TestRunnerKernel.php b/core/lib/Drupal/Core/Test/TestRunnerKernel.php index 7b04673c3fd500a69a1d897230bdc8ebd55c532e..d56841de6f932607d9b8db5920c1fff099a13683 100644 --- a/core/lib/Drupal/Core/Test/TestRunnerKernel.php +++ b/core/lib/Drupal/Core/Test/TestRunnerKernel.php @@ -33,9 +33,10 @@ public function __construct($environment, ClassLoader $class_loader) { parent::__construct($environment, $class_loader, FALSE); // Prime the module list and corresponding Extension objects. - // @todo Remove System module. Needed because \Drupal\Core\Datetime\Date - // has a (needless) dependency on the 'date_format' entity, so calls to - // format_date()/format_interval() cause a plugin not found exception. + // @todo Remove System module. Needed because + // \Drupal\Core\Datetime\DateFormatter has a (needless) dependency on the + // 'date_format' entity, so calls to format_date()/format_interval() cause + // a plugin not found exception. $this->moduleList = array( 'system' => 0, 'simpletest' => 0, diff --git a/core/modules/aggregator/aggregator.theme.inc b/core/modules/aggregator/aggregator.theme.inc index 9282b78a0c4835ec5a9a9bd225e75d5e0fa798ab..1335ee61b8efd6636e9f50b074c8d4c3e5d61d30 100644 --- a/core/modules/aggregator/aggregator.theme.inc +++ b/core/modules/aggregator/aggregator.theme.inc @@ -33,7 +33,7 @@ function template_preprocess_aggregator_item(&$variables) { $variables['source_title'] = String::checkPlain($item->ftitle); } if (date('Ymd', $item->getPostedTime()) == date('Ymd')) { - $variables['source_date'] = t('%ago ago', array('%ago' => \Drupal::service('date')->formatInterval(REQUEST_TIME - $item->getPostedTime()))); + $variables['source_date'] = t('%ago ago', array('%ago' => \Drupal::service('date.formatter')->formatInterval(REQUEST_TIME - $item->getPostedTime()))); } else { $variables['source_date'] = format_date($item->getPostedTime(), 'medium'); @@ -121,7 +121,7 @@ function template_preprocess_aggregator_summary_item(&$variables) { 'datetime' => format_date($item->getPostedTime(), 'html_datetime', '', 'UTC'), 'class' => array('feed-item-age',), ), - '#text' => t('%age old', array('%age' => \Drupal::service('date')->formatInterval(REQUEST_TIME - $item->getPostedTime()))), + '#text' => t('%age old', array('%age' => \Drupal::service('date.formatter')->formatInterval(REQUEST_TIME - $item->getPostedTime()))), '#html' => TRUE, ); } @@ -161,7 +161,7 @@ function template_preprocess_aggregator_feed_source(&$variables) { $variables['source_url'] = check_url(url($feed->getWebsiteUrl(), array('absolute' => TRUE))); if ($feed->checked) { - $variables['last_checked'] = t('@time ago', array('@time' => \Drupal::service('date')->formatInterval(REQUEST_TIME - $feed->getLastCheckedTime()))); + $variables['last_checked'] = t('@time ago', array('@time' => \Drupal::service('date.formatter')->formatInterval(REQUEST_TIME - $feed->getLastCheckedTime()))); } else { $variables['last_checked'] = t('never'); diff --git a/core/modules/aggregator/src/Controller/AggregatorController.php b/core/modules/aggregator/src/Controller/AggregatorController.php index d4e0fcd06e1e9c7fa75127fa93ed0ec3c034e664..1cedb04b39d598ea4c9d7c5f935654587d8dd9b7 100644 --- a/core/modules/aggregator/src/Controller/AggregatorController.php +++ b/core/modules/aggregator/src/Controller/AggregatorController.php @@ -9,7 +9,7 @@ use Drupal\Component\Utility\Xss; use Drupal\Core\Controller\ControllerBase; -use Drupal\Core\Datetime\Date as DateFormatter; +use Drupal\Core\Datetime\DateFormatter; use Drupal\aggregator\FeedInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -23,14 +23,14 @@ class AggregatorController extends ControllerBase { /** * The date formatter service. * - * @var \Drupal\Core\Datetime\Date + * @var \Drupal\Core\Datetime\DateFormatter */ protected $dateFormatter; /** * Constructs a \Drupal\aggregator\Controller\AggregatorController object. * - * @param \Drupal\Core\Datetime\Date $date_formatter + * @param \Drupal\Core\Datetime\DateFormatter $date_formatter * The date formatter service. */ public function __construct(DateFormatter $date_formatter) { @@ -42,7 +42,7 @@ public function __construct(DateFormatter $date_formatter) { */ public static function create(ContainerInterface $container) { return new static( - $container->get('date') + $container->get('date.formatter') ); } diff --git a/core/modules/aggregator/src/Entity/Feed.php b/core/modules/aggregator/src/Entity/Feed.php index fc531b5b0e468137dd9759bb061836fc229aefa0..542b47c10d720992c9b003fb3bfbaf2570d8acce 100644 --- a/core/modules/aggregator/src/Entity/Feed.php +++ b/core/modules/aggregator/src/Entity/Feed.php @@ -162,7 +162,7 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { )); $intervals = array(900, 1800, 3600, 7200, 10800, 21600, 32400, 43200, 64800, 86400, 172800, 259200, 604800, 1209600, 2419200); - $period = array_map(array(\Drupal::service('date'), 'formatInterval'), array_combine($intervals, $intervals)); + $period = array_map(array(\Drupal::service('date.formatter'), 'formatInterval'), array_combine($intervals, $intervals)); $period[AGGREGATOR_CLEAR_NEVER] = t('Never'); $fields['refresh'] = FieldDefinition::create('list_integer') diff --git a/core/modules/aggregator/src/Form/OpmlFeedAdd.php b/core/modules/aggregator/src/Form/OpmlFeedAdd.php index 2adce58c718763c2c4dee5345d92c5c38cd29bfd..104dd3a00f5392c6cbaa83c67e2d83af185745a0 100644 --- a/core/modules/aggregator/src/Form/OpmlFeedAdd.php +++ b/core/modules/aggregator/src/Form/OpmlFeedAdd.php @@ -69,7 +69,7 @@ public function getFormId() { */ public function buildForm(array $form, FormStateInterface $form_state) { $intervals = array(900, 1800, 3600, 7200, 10800, 21600, 32400, 43200, 64800, 86400, 172800, 259200, 604800, 1209600, 2419200); - $period = array_map(array(\Drupal::service('date'), 'formatInterval'), array_combine($intervals, $intervals)); + $period = array_map(array(\Drupal::service('date.formatter'), 'formatInterval'), array_combine($intervals, $intervals)); $form['upload'] = array( '#type' => 'file', diff --git a/core/modules/aggregator/src/Plugin/aggregator/processor/DefaultProcessor.php b/core/modules/aggregator/src/Plugin/aggregator/processor/DefaultProcessor.php index c97c04d7bc40b50e1bb5adf20a28063105aa4860..816b4c042851e298174c9246be2e9b85a2c59ea6 100644 --- a/core/modules/aggregator/src/Plugin/aggregator/processor/DefaultProcessor.php +++ b/core/modules/aggregator/src/Plugin/aggregator/processor/DefaultProcessor.php @@ -13,7 +13,7 @@ use Drupal\aggregator\FeedInterface; use Drupal\Core\Database\Database; use Drupal\Core\Config\ConfigFactoryInterface; -use Drupal\Core\Datetime\Date as DateFormatter; +use Drupal\Core\Datetime\DateFormatter; use Drupal\Core\Entity\Query\QueryInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; @@ -56,7 +56,7 @@ class DefaultProcessor extends AggregatorPluginSettingsBase implements Processor /** * The date formatter service. * - * @var \Drupal\Core\Datetime\Date + * @var \Drupal\Core\Datetime\DateFormatter */ protected $dateFormatter; @@ -75,7 +75,7 @@ class DefaultProcessor extends AggregatorPluginSettingsBase implements Processor * The entity query object for feed items. * @param \Drupal\aggregator\ItemStorageInterface $item_storage * The entity storage for feed items. - * @param \Drupal\Core\Datetime\Date $date_formatter + * @param \Drupal\Core\Datetime\DateFormatter $date_formatter * The date formatter service. */ public function __construct(array $configuration, $plugin_id, $plugin_definition, ConfigFactoryInterface $config, QueryInterface $item_query, ItemStorageInterface $item_storage, DateFormatter $date_formatter) { @@ -99,7 +99,7 @@ public static function create(ContainerInterface $container, array $configuratio $container->get('config.factory'), $container->get('entity.query')->get('aggregator_item'), $container->get('entity.manager')->getStorage('aggregator_item'), - $container->get('date') + $container->get('date.formatter') ); } diff --git a/core/modules/block/src/BlockBase.php b/core/modules/block/src/BlockBase.php index ca94ba075845bf56293cefbc54b40104f75e61db..b18591ad22811df07ada30d30e1dd94d3905b06b 100644 --- a/core/modules/block/src/BlockBase.php +++ b/core/modules/block/src/BlockBase.php @@ -228,7 +228,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta // Identical options to the ones for page caching. // @see \Drupal\system\Form\PerformanceForm::buildForm() $period = array(0, 60, 180, 300, 600, 900, 1800, 2700, 3600, 10800, 21600, 32400, 43200, 86400); - $period = array_map(array(\Drupal::service('date'), 'formatInterval'), array_combine($period, $period)); + $period = array_map(array(\Drupal::service('date.formatter'), 'formatInterval'), array_combine($period, $period)); $period[0] = '<' . t('no caching') . '>'; $period[\Drupal\Core\Cache\Cache::PERMANENT] = t('Forever'); $form['cache'] = array( diff --git a/core/modules/block/src/Tests/BlockInterfaceTest.php b/core/modules/block/src/Tests/BlockInterfaceTest.php index 29097e55d471b3f9a9597a30dc14bf01d9c165b2..ed70a2fd54a0143db2da2087969e4dff98f4f754 100644 --- a/core/modules/block/src/Tests/BlockInterfaceTest.php +++ b/core/modules/block/src/Tests/BlockInterfaceTest.php @@ -62,7 +62,7 @@ public function testBlockInterface() { $definition = $display_block->getPluginDefinition(); $period = array(0, 60, 180, 300, 600, 900, 1800, 2700, 3600, 10800, 21600, 32400, 43200, 86400); - $period = array_map(array(\Drupal::service('date'), 'formatInterval'), array_combine($period, $period)); + $period = array_map(array(\Drupal::service('date.formatter'), 'formatInterval'), array_combine($period, $period)); $period[0] = '<' . t('no caching') . '>'; $period[\Drupal\Core\Cache\Cache::PERMANENT] = t('Forever'); $contexts = \Drupal::service("cache_contexts")->getLabels(); diff --git a/core/modules/comment/src/Form/CommentAdminOverview.php b/core/modules/comment/src/Form/CommentAdminOverview.php index 0a83fd5891b25e4f06257d8dde7d8fe6f65c5779..3876e7cb6470f4edcff4a0e4cde13f3742aff842 100644 --- a/core/modules/comment/src/Form/CommentAdminOverview.php +++ b/core/modules/comment/src/Form/CommentAdminOverview.php @@ -10,7 +10,7 @@ use Drupal\comment\CommentInterface; use Drupal\comment\CommentStorageInterface; use Drupal\Component\Utility\Unicode; -use Drupal\Core\Datetime\Date as DateFormatter; +use Drupal\Core\Datetime\DateFormatter; use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Form\FormBase; @@ -39,7 +39,7 @@ class CommentAdminOverview extends FormBase { /** * The date formatter service. * - * @var \Drupal\Core\Datetime\Date + * @var \Drupal\Core\Datetime\DateFormatter */ protected $dateFormatter; @@ -57,7 +57,7 @@ class CommentAdminOverview extends FormBase { * The entity manager service. * @param \Drupal\comment\CommentStorageInterface $comment_storage * The comment storage. - * @param \Drupal\Core\Datetime\Date $date_formatter + * @param \Drupal\Core\Datetime\DateFormatter $date_formatter * The date formatter service. * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler * The module handler. @@ -76,7 +76,7 @@ public static function create(ContainerInterface $container) { return new static( $container->get('entity.manager'), $container->get('entity.manager')->getStorage('comment'), - $container->get('date'), + $container->get('date.formatter'), $container->get('module_handler') ); } diff --git a/core/modules/comment/src/Tests/CommentTokenReplaceTest.php b/core/modules/comment/src/Tests/CommentTokenReplaceTest.php index 27b6e3943fcdabf976cd7aa85a063758ca7d4d7a..805f91a9e4760fe758120348bda748d8d9a14c0b 100644 --- a/core/modules/comment/src/Tests/CommentTokenReplaceTest.php +++ b/core/modules/comment/src/Tests/CommentTokenReplaceTest.php @@ -59,8 +59,8 @@ function testCommentTokenReplacement() { $tests['[comment:body]'] = $comment->comment_body->processed; $tests['[comment:url]'] = url('comment/' . $comment->id(), $url_options + array('fragment' => 'comment-' . $comment->id())); $tests['[comment:edit-url]'] = url('comment/' . $comment->id() . '/edit', $url_options); - $tests['[comment:created:since]'] = \Drupal::service('date')->formatInterval(REQUEST_TIME - $comment->getCreatedTime(), 2, $language_interface->id); - $tests['[comment:changed:since]'] = \Drupal::service('date')->formatInterval(REQUEST_TIME - $comment->getChangedTime(), 2, $language_interface->id); + $tests['[comment:created:since]'] = \Drupal::service('date.formatter')->formatInterval(REQUEST_TIME - $comment->getCreatedTime(), 2, $language_interface->id); + $tests['[comment:changed:since]'] = \Drupal::service('date.formatter')->formatInterval(REQUEST_TIME - $comment->getChangedTime(), 2, $language_interface->id); $tests['[comment:parent:cid]'] = $comment->hasParentComment() ? $comment->getParentComment()->id() : NULL; $tests['[comment:parent:title]'] = String::checkPlain($parent_comment->getSubject()); $tests['[comment:node:nid]'] = $comment->getCommentedEntityId(); diff --git a/core/modules/config_translation/src/FormElement/DateFormat.php b/core/modules/config_translation/src/FormElement/DateFormat.php index d00a71e575dae11d5621bfbb31e3f023d2353a19..0e7cd83f87ef82ac0d0af2a21c4c00eee79fafec 100644 --- a/core/modules/config_translation/src/FormElement/DateFormat.php +++ b/core/modules/config_translation/src/FormElement/DateFormat.php @@ -26,7 +26,7 @@ class DateFormat implements ElementInterface { */ public function getFormElement(DataDefinitionInterface $definition, LanguageInterface $language, $value) { $description = $this->t('A user-defined date format. See the <a href="@url">PHP manual</a> for available options.', array('@url' => 'http://php.net/manual/function.date.php')); - $format = $this->t('Displayed as %date_format', array('%date_format' => \Drupal::service('date')->format(REQUEST_TIME, 'custom', $value))); + $format = $this->t('Displayed as %date_format', array('%date_format' => \Drupal::service('date.formatter')->format(REQUEST_TIME, 'custom', $value))); return array( '#type' => 'textfield', '#title' => $this->t($definition->getLabel()) . '<span class="visually-hidden"> (' . $language->name . ')</span>', @@ -63,7 +63,7 @@ public static function ajaxSample(array $form, FormStateInterface $form_state) { // Format the date with a custom date format with the given pattern. // The object is not instantiated in an Ajax context, so $this->t() // cannot be used here. - $format = t('Displayed as %date_format', array('%date_format' => \Drupal::service('date')->format(REQUEST_TIME, 'custom', $format_value))); + $format = t('Displayed as %date_format', array('%date_format' => \Drupal::service('date.formatter')->format(REQUEST_TIME, 'custom', $format_value))); // Return a command instead of a string, since the Ajax framework // automatically prepends an additional empty DIV element for a string, diff --git a/core/modules/contact/src/Controller/ContactController.php b/core/modules/contact/src/Controller/ContactController.php index b257ade0804df7ee0d600879175b38f01e58cd36..307989a3ba30697cf78ea0e42ee5bc83d1e76860 100644 --- a/core/modules/contact/src/Controller/ContactController.php +++ b/core/modules/contact/src/Controller/ContactController.php @@ -8,7 +8,7 @@ namespace Drupal\contact\Controller; use Drupal\Core\Controller\ControllerBase; -use Drupal\Core\Datetime\Date as DateFormatter; +use Drupal\Core\Datetime\DateFormatter; use Drupal\Core\Flood\FloodInterface; use Drupal\contact\CategoryInterface; use Drupal\user\UserInterface; @@ -32,7 +32,7 @@ class ContactController extends ControllerBase { /** * The date formatter service. * - * @var \Drupal\Core\Datetime\Date + * @var \Drupal\Core\Datetime\DateFormatter */ protected $dateFormatter; @@ -41,7 +41,7 @@ class ContactController extends ControllerBase { * * @param \Drupal\Core\Flood\FloodInterface $flood * The flood service. - * @param \Drupal\Core\Datetime\Date $date_formatter + * @param \Drupal\Core\Datetime\DateFormatter $date_formatter * The date service. */ public function __construct(FloodInterface $flood, DateFormatter $date_formatter) { @@ -55,7 +55,7 @@ public function __construct(FloodInterface $flood, DateFormatter $date_formatter public static function create(ContainerInterface $container) { return new static( $container->get('flood'), - $container->get('date') + $container->get('date.formatter') ); } diff --git a/core/modules/contact/src/Tests/ContactPersonalTest.php b/core/modules/contact/src/Tests/ContactPersonalTest.php index f004d390cba74548220bbafee1cc7b79f106755a..521899bf16a6d515ea0dc6fdd370a79cc79cc9aa 100644 --- a/core/modules/contact/src/Tests/ContactPersonalTest.php +++ b/core/modules/contact/src/Tests/ContactPersonalTest.php @@ -209,7 +209,7 @@ function testPersonalContactFlood() { // Submit contact form one over limit. $this->drupalGet('user/' . $this->contact_user->id(). '/contact'); - $this->assertRaw(t('You cannot send more than %number messages in @interval. Try again later.', array('%number' => $flood_limit, '@interval' => \Drupal::service('date')->formatInterval(\Drupal::config('contact.settings')->get('flood.interval')))), 'Normal user denied access to flooded contact form.'); + $this->assertRaw(t('You cannot send more than %number messages in @interval. Try again later.', array('%number' => $flood_limit, '@interval' => \Drupal::service('date.formatter')->formatInterval(\Drupal::config('contact.settings')->get('flood.interval')))), 'Normal user denied access to flooded contact form.'); // Test that the admin user can still access the contact form even though // the flood limit was reached. diff --git a/core/modules/contact/src/Tests/ContactSitewideTest.php b/core/modules/contact/src/Tests/ContactSitewideTest.php index 8321c4402a67f3820a9ec5d1f93ab6a30b9c51a5..27ef1dde3857883a2d6bc19b81700e4d88945a7b 100644 --- a/core/modules/contact/src/Tests/ContactSitewideTest.php +++ b/core/modules/contact/src/Tests/ContactSitewideTest.php @@ -212,7 +212,7 @@ function testSiteWideContact() { // Submit contact form one over limit. $this->drupalGet('contact'); $this->assertResponse(403); - $this->assertRaw(t('You cannot send more than %number messages in @interval. Try again later.', array('%number' => \Drupal::config('contact.settings')->get('flood.limit'), '@interval' => \Drupal::service('date')->formatInterval(600)))); + $this->assertRaw(t('You cannot send more than %number messages in @interval. Try again later.', array('%number' => \Drupal::config('contact.settings')->get('flood.limit'), '@interval' => \Drupal::service('date.formatter')->formatInterval(600)))); // Test listing controller. $this->drupalLogin($admin_user); diff --git a/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimeDefaultFormatter.php b/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimeDefaultFormatter.php index 5bff36f326c9071a53f8141aabee760250e3ef74..65167b34178f5a6d0f41de1af2343ff0ecd54d53 100644 --- a/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimeDefaultFormatter.php +++ b/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimeDefaultFormatter.php @@ -7,7 +7,7 @@ namespace Drupal\datetime\Plugin\Field\FieldFormatter; -use Drupal\Core\Datetime\Date as DateFormatter; +use Drupal\Core\Datetime\DateFormatter; use Drupal\Core\Datetime\DrupalDateTime; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Field\FieldDefinitionInterface; @@ -42,7 +42,7 @@ public static function defaultSettings() { /** * The date formatter service. * - * @var \Drupal\Core\Datetime\Date + * @var \Drupal\Core\Datetime\DateFormatter */ protected $dateFormatter; @@ -70,7 +70,7 @@ public static function defaultSettings() { * The view mode. * @param array $third_party_settings * Third party settings. - * @param \Drupal\Core\Datetime\Date $date_formatter + * @param \Drupal\Core\Datetime\DateFormatter $date_formatter * The date formatter service. * @param \Drupal\Core\Entity\EntityStorageInterface $date_storage * The date storage. @@ -94,7 +94,7 @@ public static function create(ContainerInterface $container, array $configuratio $configuration['label'], $configuration['view_mode'], $configuration['third_party_settings'], - $container->get('date'), + $container->get('date.formatter'), $container->get('entity.manager')->getStorage('date_format') ); } diff --git a/core/modules/dblog/src/Controller/DbLogController.php b/core/modules/dblog/src/Controller/DbLogController.php index e6fa3ef524c3153cfbf279633e4a09e209f114a0..1af360acc0e3af25b329a30a3cce0cf875a05a64 100644 --- a/core/modules/dblog/src/Controller/DbLogController.php +++ b/core/modules/dblog/src/Controller/DbLogController.php @@ -12,7 +12,7 @@ use Drupal\Component\Utility\Xss; use Drupal\Core\Controller\ControllerBase; use Drupal\Core\Database\Connection; -use Drupal\Core\Datetime\Date as DateFormatter; +use Drupal\Core\Datetime\DateFormatter; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Form\FormBuilderInterface; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -39,7 +39,7 @@ class DbLogController extends ControllerBase { /** * The date formatter service. * - * @var \Drupal\Core\Datetime\Date + * @var \Drupal\Core\Datetime\DateFormatter */ protected $dateFormatter; @@ -57,7 +57,7 @@ public static function create(ContainerInterface $container) { return new static( $container->get('database'), $container->get('module_handler'), - $container->get('date'), + $container->get('date.formatter'), $container->get('form_builder') ); } @@ -69,7 +69,7 @@ public static function create(ContainerInterface $container) { * A database connection. * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler * A module handler. - * @param \Drupal\Core\Datetime\Date $date_formatter + * @param \Drupal\Core\Datetime\DateFormatter $date_formatter * The date formatter service. * @param \Drupal\Core\Form\FormBuilderInterface $form_builder * The form builder service. diff --git a/core/modules/forum/forum.module b/core/modules/forum/forum.module index 425b597bbfa74d4a8bb00bcc9e1676639aeb2a42..51b98a62256b5b081a1ecb7cecfcade38cb2f86c 100644 --- a/core/modules/forum/forum.module +++ b/core/modules/forum/forum.module @@ -735,5 +735,5 @@ function template_preprocess_forum_submitted(&$variables) { $username = array('#theme' => 'username', '#account' => user_load($variables['topic']->uid)); $variables['author'] = drupal_render($username); } - $variables['time'] = isset($variables['topic']->created) ? \Drupal::service('date')->formatInterval(REQUEST_TIME - $variables['topic']->created) : ''; + $variables['time'] = isset($variables['topic']->created) ? \Drupal::service('date.formatter')->formatInterval(REQUEST_TIME - $variables['topic']->created) : ''; } diff --git a/core/modules/locale/locale.pages.inc b/core/modules/locale/locale.pages.inc index 681b19a8676c83d75d3a3b86907a344564cead38..dc6043bed3347e6b88011ed0f5e8de33ad3c0124 100644 --- a/core/modules/locale/locale.pages.inc +++ b/core/modules/locale/locale.pages.inc @@ -156,6 +156,6 @@ function template_preprocess_locale_translation_update_info(&$variables) { function template_preprocess_locale_translation_last_check(&$variables) { $last = $variables['last']; $variables['last_checked'] = ($last != NULL); - $variables['time'] = \Drupal::service('date')->formatInterval(REQUEST_TIME - $last); + $variables['time'] = \Drupal::service('date.formatter')->formatInterval(REQUEST_TIME - $last); $variables['link'] = l(t('Check manually'), 'admin/reports/translations/check', array('query' => drupal_get_destination())); } diff --git a/core/modules/node/src/Controller/NodeController.php b/core/modules/node/src/Controller/NodeController.php index b09a3a747cb6791921ecdbcf9b12a8d110c77e72..d98ec00858af79452af01a7bfa297c5e7319475c 100644 --- a/core/modules/node/src/Controller/NodeController.php +++ b/core/modules/node/src/Controller/NodeController.php @@ -10,7 +10,7 @@ use Drupal\Component\Utility\String; use Drupal\Component\Utility\Xss; use Drupal\Core\Controller\ControllerBase; -use Drupal\Core\Datetime\Date as DateFormatter; +use Drupal\Core\Datetime\DateFormatter; use Drupal\Core\DependencyInjection\ContainerInjectionInterface; use Drupal\node\NodeTypeInterface; use Drupal\node\NodeInterface; @@ -24,14 +24,14 @@ class NodeController extends ControllerBase implements ContainerInjectionInterfa /** * The date formatter service. * - * @var \Drupal\Core\Datetime\Date + * @var \Drupal\Core\Datetime\DateFormatter */ protected $dateFormatter; /** * Constructs a NodeController object. * - * @param \Drupal\Core\Datetime\Date $date_formatter + * @param \Drupal\Core\Datetime\DateFormatter $date_formatter * The date formatter service. */ public function __construct(DateFormatter $date_formatter) { @@ -42,7 +42,7 @@ public function __construct(DateFormatter $date_formatter) { * {@inheritdoc} */ public static function create(ContainerInterface $container) { - return new static($container->get('date')); + return new static($container->get('date.formatter')); } diff --git a/core/modules/node/src/NodeListBuilder.php b/core/modules/node/src/NodeListBuilder.php index d0fcdf962d75d1769cf7200b999dd16b9078f278..c78915d66660e399b10952045f1360d19ff1fba9 100644 --- a/core/modules/node/src/NodeListBuilder.php +++ b/core/modules/node/src/NodeListBuilder.php @@ -8,7 +8,7 @@ namespace Drupal\node; use Drupal\Component\Utility\String; -use Drupal\Core\Datetime\Date as DateFormatter; +use Drupal\Core\Datetime\DateFormatter; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityListBuilder; use Drupal\Core\Entity\EntityStorageInterface; @@ -26,7 +26,7 @@ class NodeListBuilder extends EntityListBuilder { /** * The date formatter service. * - * @var \Drupal\Core\Datetime\Date + * @var \Drupal\Core\Datetime\DateFormatter */ protected $dateFormatter; @@ -37,7 +37,7 @@ class NodeListBuilder extends EntityListBuilder { * The entity type definition. * @param \Drupal\Core\Entity\EntityStorageInterface $storage * The entity storage class. - * @param \Drupal\Core\Datetime\Date $date_formatter + * @param \Drupal\Core\Datetime\DateFormatter $date_formatter * The date formatter service. */ public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, DateFormatter $date_formatter) { @@ -53,7 +53,7 @@ public static function createInstance(ContainerInterface $container, EntityTypeI return new static( $entity_type, $container->get('entity.manager')->getStorage($entity_type->id()), - $container->get('date') + $container->get('date.formatter') ); } diff --git a/core/modules/node/src/Tests/NodeTokenReplaceTest.php b/core/modules/node/src/Tests/NodeTokenReplaceTest.php index a80ed796db67d2922eaac532fdc2f89887dc19fb..9acbe9c3eb7490aa0d9755b6ff05435633308d45 100644 --- a/core/modules/node/src/Tests/NodeTokenReplaceTest.php +++ b/core/modules/node/src/Tests/NodeTokenReplaceTest.php @@ -74,8 +74,8 @@ function testNodeTokenReplacement() { $tests['[node:author]'] = String::checkPlain($account->getUsername()); $tests['[node:author:uid]'] = $node->getOwnerId(); $tests['[node:author:name]'] = String::checkPlain($account->getUsername()); - $tests['[node:created:since]'] = \Drupal::service('date')->formatInterval(REQUEST_TIME - $node->getCreatedTime(), 2, $this->interfaceLanguage->id); - $tests['[node:changed:since]'] = \Drupal::service('date')->formatInterval(REQUEST_TIME - $node->getChangedTime(), 2, $this->interfaceLanguage->id); + $tests['[node:created:since]'] = \Drupal::service('date.formatter')->formatInterval(REQUEST_TIME - $node->getCreatedTime(), 2, $this->interfaceLanguage->id); + $tests['[node:changed:since]'] = \Drupal::service('date.formatter')->formatInterval(REQUEST_TIME - $node->getChangedTime(), 2, $this->interfaceLanguage->id); // Test to make sure that we generated something for each token. $this->assertFalse(in_array(0, array_map('strlen', $tests)), 'No empty tokens generated.'); diff --git a/core/modules/system/src/DateFormatListBuilder.php b/core/modules/system/src/DateFormatListBuilder.php index 576b92bd770b7ec68145b799fb66e048fe81fe6f..ba7511bcfbfb8cecce6eca76423a57b081a98b44 100644 --- a/core/modules/system/src/DateFormatListBuilder.php +++ b/core/modules/system/src/DateFormatListBuilder.php @@ -8,7 +8,7 @@ namespace Drupal\system; use Drupal\Core\Config\Entity\ConfigEntityListBuilder; -use Drupal\Core\Datetime\Date as DateFormatter; +use Drupal\Core\Datetime\DateFormatter; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Entity\EntityTypeInterface; @@ -24,7 +24,7 @@ class DateFormatListBuilder extends ConfigEntityListBuilder { /** * The date formatter service. * - * @var \Drupal\Core\Datetime\Date + * @var \Drupal\Core\Datetime\DateFormatter */ protected $dateFormatter; @@ -35,7 +35,7 @@ class DateFormatListBuilder extends ConfigEntityListBuilder { * The entity type definition. * @param \Drupal\Core\Entity\EntityStorageInterface $storage * The entity storage class. - * @param \Drupal\Core\Datetime\Date $date_formatter + * @param \Drupal\Core\Datetime\DateFormatter $date_formatter * The date formatter service. */ public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, DateFormatter $date_formatter) { @@ -51,7 +51,7 @@ public static function createInstance(ContainerInterface $container, EntityTypeI return new static( $entity_type, $container->get('entity.manager')->getStorage($entity_type->id()), - $container->get('date') + $container->get('date.formatter') ); } diff --git a/core/modules/system/src/Form/CronForm.php b/core/modules/system/src/Form/CronForm.php index 1ae69a1fa6dc29a2be2cb795a242c4ecf545c42a..27f9f1daf8510bf5bc819469ed4a4caef0defae2 100644 --- a/core/modules/system/src/Form/CronForm.php +++ b/core/modules/system/src/Form/CronForm.php @@ -9,7 +9,7 @@ use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\CronInterface; -use Drupal\Core\Datetime\Date as DateFormatter; +use Drupal\Core\Datetime\DateFormatter; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\State\StateInterface; use Drupal\Core\Form\ConfigFormBase; @@ -38,7 +38,7 @@ class CronForm extends ConfigFormBase { /** * The date formatter service. * - * @var \Drupal\Core\Datetime\Date + * @var \Drupal\Core\Datetime\DateFormatter */ protected $dateFormatter; @@ -51,7 +51,7 @@ class CronForm extends ConfigFormBase { * The state key value store. * @param \Drupal\Core\CronInterface $cron * The cron service. - * @param \Drupal\Core\Datetime\Date $date_formatter + * @param \Drupal\Core\Datetime\DateFormatter $date_formatter * The date formatter service. */ public function __construct(ConfigFactoryInterface $config_factory, StateInterface $state, CronInterface $cron, DateFormatter $date_formatter) { @@ -69,7 +69,7 @@ public static function create(ContainerInterface $container) { $container->get('config.factory'), $container->get('state'), $container->get('cron'), - $container->get('date') + $container->get('date.formatter') ); } diff --git a/core/modules/system/src/Form/DateFormatDeleteForm.php b/core/modules/system/src/Form/DateFormatDeleteForm.php index 7ba8f7d0ff3db1c72c70a74ba5f658130215212a..952ee479ca2201fd49f8cb8a50a3eab201b2c815 100644 --- a/core/modules/system/src/Form/DateFormatDeleteForm.php +++ b/core/modules/system/src/Form/DateFormatDeleteForm.php @@ -7,7 +7,7 @@ namespace Drupal\system\Form; -use Drupal\Core\Datetime\Date as DateFormatter; +use Drupal\Core\Datetime\DateFormatter; use Drupal\Core\Entity\EntityConfirmFormBase; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Url; @@ -21,14 +21,14 @@ class DateFormatDeleteForm extends EntityConfirmFormBase { /** * The date formatter service. * - * @var \Drupal\Core\Datetime\Date + * @var \Drupal\Core\Datetime\DateFormatter */ protected $dateFormatter; /** * Constructs an DateFormatDeleteForm object. * - * @param \Drupal\Core\Datetime\Date $date_formatter + * @param \Drupal\Core\Datetime\DateFormatter $date_formatter * The date formatter service. */ public function __construct(DateFormatter $date_formatter) { @@ -40,7 +40,7 @@ public function __construct(DateFormatter $date_formatter) { */ public static function create(ContainerInterface $container) { return new static( - $container->get('date') + $container->get('date.formatter') ); } diff --git a/core/modules/system/src/Form/DateFormatFormBase.php b/core/modules/system/src/Form/DateFormatFormBase.php index 757184bcbdd80835046a804edba3a6368253cd29..e250b9a23455c98c5a75185784b71f350b2e0f63 100644 --- a/core/modules/system/src/Form/DateFormatFormBase.php +++ b/core/modules/system/src/Form/DateFormatFormBase.php @@ -10,7 +10,7 @@ use Drupal\Core\Ajax\AjaxResponse; use Drupal\Core\Ajax\ReplaceCommand; use Drupal\Core\Config\Entity\ConfigEntityStorageInterface; -use Drupal\Core\Datetime\Date as DateFormatter; +use Drupal\Core\Datetime\DateFormatter; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Language\LanguageInterface; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -25,7 +25,7 @@ abstract class DateFormatFormBase extends EntityForm { /** * The date formatter service. * - * @var \Drupal\Core\Datetime\Date + * @var \Drupal\Core\Datetime\DateFormatter */ protected $dateFormatter; @@ -39,7 +39,7 @@ abstract class DateFormatFormBase extends EntityForm { /** * Constructs a new date format form. * - * @param \Drupal\Core\Datetime\Date $date_formatter + * @param \Drupal\Core\Datetime\DateFormatter $date_formatter * The date service. * @param \Drupal\Core\Config\Entity\ConfigEntityStorageInterface $date_format_storage * The date format storage. @@ -56,7 +56,7 @@ public function __construct(DateFormatter $date_formatter, ConfigEntityStorageIn */ public static function create(ContainerInterface $container) { return new static( - $container->get('date'), + $container->get('date.formatter'), $container->get('entity.manager')->getStorage('date_format') ); } @@ -93,7 +93,7 @@ public function exists($entity_id, array $element) { public static function dateTimeLookup(array $form, FormStateInterface $form_state) { $format = ''; if (!empty($form_state['values']['date_format_pattern'])) { - $format = t('Displayed as %date_format', array('%date_format' => \Drupal::service('date')->format(REQUEST_TIME, 'custom', $form_state['values']['date_format_pattern']))); + $format = t('Displayed as %date_format', array('%date_format' => \Drupal::service('date.formatter')->format(REQUEST_TIME, 'custom', $form_state['values']['date_format_pattern']))); } // Return a command instead of a string, since the Ajax framework // automatically prepends an additional empty DIV element for a string, which diff --git a/core/modules/system/src/Form/FileSystemForm.php b/core/modules/system/src/Form/FileSystemForm.php index d2429e5acf738cb334030a6604987bfd6e67d8f0..44958f20a84a40827fdaa1eafe555f59e5cd528c 100644 --- a/core/modules/system/src/Form/FileSystemForm.php +++ b/core/modules/system/src/Form/FileSystemForm.php @@ -9,7 +9,7 @@ use Drupal\Component\Utility\String; use Drupal\Core\Config\ConfigFactoryInterface; -use Drupal\Core\Datetime\Date as DateFormatter; +use Drupal\Core\Datetime\DateFormatter; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\StreamWrapper\PublicStream; use Drupal\Core\Form\ConfigFormBase; @@ -23,7 +23,7 @@ class FileSystemForm extends ConfigFormBase { /** * The date formatter service. * - * @var \Drupal\Core\Datetime\Date + * @var \Drupal\Core\Datetime\DateFormatter */ protected $dateFormatter; @@ -32,7 +32,7 @@ class FileSystemForm extends ConfigFormBase { * * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory * The factory for configuration objects. - * @param \Drupal\Core\Datetime\Date $date_formatter + * @param \Drupal\Core\Datetime\DateFormatter $date_formatter * The date formatter service. */ public function __construct(ConfigFactoryInterface $config_factory, DateFormatter $date_formatter) { @@ -46,7 +46,7 @@ public function __construct(ConfigFactoryInterface $config_factory, DateFormatte public static function create(ContainerInterface $container) { return new static ( $container->get('config.factory'), - $container->get('date') + $container->get('date.formatter') ); } diff --git a/core/modules/system/src/Form/PerformanceForm.php b/core/modules/system/src/Form/PerformanceForm.php index d208cc3cf9b1cdc7027dd3ddb93a71c8d3e494cc..b4274e75161478b9d450f24f6a03ed60dad80f65 100644 --- a/core/modules/system/src/Form/PerformanceForm.php +++ b/core/modules/system/src/Form/PerformanceForm.php @@ -10,7 +10,7 @@ use Drupal\Core\Form\ConfigFormBase; use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Cache\CacheBackendInterface; -use Drupal\Core\Datetime\Date as DateFormatter; +use Drupal\Core\Datetime\DateFormatter; use Drupal\Core\Form\FormStateInterface; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -29,7 +29,7 @@ class PerformanceForm extends ConfigFormBase { /** * The date formatter service. * - * @var \Drupal\Core\Datetime\Date + * @var \Drupal\Core\Datetime\DateFormatter */ protected $dateFormatter; @@ -39,7 +39,7 @@ class PerformanceForm extends ConfigFormBase { * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory * The factory for configuration objects. * @param \Drupal\Core\Cache\CacheBackendInterface $render_cache - * @param \Drupal\Core\Datetime\Date $date_formater + * @param \Drupal\Core\Datetime\DateFormatter $date_formater * The date formatter service. */ public function __construct(ConfigFactoryInterface $config_factory, CacheBackendInterface $render_cache, DateFormatter $date_formater) { @@ -56,7 +56,7 @@ public static function create(ContainerInterface $container) { return new static( $container->get('config.factory'), $container->get('cache.render'), - $container->get('date') + $container->get('date.formatter') ); } diff --git a/core/modules/system/src/Tests/System/TokenReplaceUnitTest.php b/core/modules/system/src/Tests/System/TokenReplaceUnitTest.php index 867ef2df9aa39427d9639a148fde7ad9c58098b6..907827f27ae25f20fda79fb5f0daa0e9fadf05c7 100644 --- a/core/modules/system/src/Tests/System/TokenReplaceUnitTest.php +++ b/core/modules/system/src/Tests/System/TokenReplaceUnitTest.php @@ -140,12 +140,12 @@ public function testSystemDateTokenReplacement() { // Generate and test tokens. $tests = array(); - $date_service = \Drupal::service('date'); - $tests['[date:short]'] = $date_service->format($date, 'short', '', NULL, $this->interfaceLanguage->id); - $tests['[date:medium]'] = $date_service->format($date, 'medium', '', NULL, $this->interfaceLanguage->id); - $tests['[date:long]'] = $date_service->format($date, 'long', '', NULL, $this->interfaceLanguage->id); - $tests['[date:custom:m/j/Y]'] = $date_service->format($date, 'custom', 'm/j/Y', NULL, $this->interfaceLanguage->id); - $tests['[date:since]'] = $date_service->formatInterval(REQUEST_TIME - $date, 2, $this->interfaceLanguage->id); + $date_formatter = \Drupal::service('date.formatter'); + $tests['[date:short]'] = $date_formatter->format($date, 'short', '', NULL, $this->interfaceLanguage->id); + $tests['[date:medium]'] = $date_formatter->format($date, 'medium', '', NULL, $this->interfaceLanguage->id); + $tests['[date:long]'] = $date_formatter->format($date, 'long', '', NULL, $this->interfaceLanguage->id); + $tests['[date:custom:m/j/Y]'] = $date_formatter->format($date, 'custom', 'm/j/Y', NULL, $this->interfaceLanguage->id); + $tests['[date:since]'] = $date_formatter->formatInterval(REQUEST_TIME - $date, 2, $this->interfaceLanguage->id); $tests['[date:raw]'] = Xss::filter($date); // Test to make sure that we generated something for each token. diff --git a/core/modules/system/system.api.php b/core/modules/system/system.api.php index ee83508d45c695c3e150249193bcda41dfee0933..14771543c082cbb9897dc544a28728e20c68f136 100644 --- a/core/modules/system/system.api.php +++ b/core/modules/system/system.api.php @@ -1666,7 +1666,7 @@ function hook_requirements($phase) { $cron_last = \Drupal::state()->get('system.cron_last'); if (is_numeric($cron_last)) { - $requirements['cron']['value'] = t('Last run !time ago', array('!time' => \Drupal::service('date')->formatInterval(REQUEST_TIME - $cron_last))); + $requirements['cron']['value'] = t('Last run !time ago', array('!time' => \Drupal::service('date.formatter')->formatInterval(REQUEST_TIME - $cron_last))); } else { $requirements['cron'] = array( diff --git a/core/modules/system/system.install b/core/modules/system/system.install index f93927eeece08ccaea58fb76633293bc862537f1..4c945167538e0e90c142c189cf435ae25461b86b 100644 --- a/core/modules/system/system.install +++ b/core/modules/system/system.install @@ -309,7 +309,7 @@ function system_requirements($phase) { } // Set summary and description based on values determined above. - $summary = t('Last run !time ago', array('!time' => \Drupal::service('date')->formatInterval(REQUEST_TIME - $cron_last))); + $summary = t('Last run !time ago', array('!time' => \Drupal::service('date.formatter')->formatInterval(REQUEST_TIME - $cron_last))); $description = ''; if ($severity != REQUIREMENT_INFO) { $description = t('Cron has not run recently.') . ' ' . $help; diff --git a/core/modules/system/system.tokens.inc b/core/modules/system/system.tokens.inc index 6b5ad4594ad8d74375b6535e6bc6c04e5e6713dd..e7433aaa79973c506d571fac998ece50b447776b 100644 --- a/core/modules/system/system.tokens.inc +++ b/core/modules/system/system.tokens.inc @@ -68,7 +68,7 @@ function system_token_info() { ); $date['since'] = array( 'name' => t("Time-since"), - 'description' => t("A date in 'time-since' format. (%date)", array('%date' => \Drupal::service('date')->formatInterval(REQUEST_TIME - 360, 2))), + 'description' => t("A date in 'time-since' format. (%date)", array('%date' => \Drupal::service('date.formatter')->formatInterval(REQUEST_TIME - 360, 2))), ); $date['raw'] = array( 'name' => t("Raw timestamp"), @@ -157,7 +157,7 @@ function system_tokens($type, $tokens, array $data = array(), array $options = a break; case 'since': - $replacements[$original] = \Drupal::service('date')->formatInterval((REQUEST_TIME - $date), 2, $langcode); + $replacements[$original] = \Drupal::service('date.formatter')->formatInterval((REQUEST_TIME - $date), 2, $langcode); break; case 'raw': diff --git a/core/modules/tracker/tracker.pages.inc b/core/modules/tracker/tracker.pages.inc index b3890206213fe71094a2c8a7d7dab4178012344f..0aac664d66a1f6f417f72f800ed0556ce7043eb7 100644 --- a/core/modules/tracker/tracker.pages.inc +++ b/core/modules/tracker/tracker.pages.inc @@ -92,7 +92,7 @@ function tracker_page($account = NULL) { 'title' => array('data' => l($node->getTitle(), 'node/' . $node->id()) . ' ' . drupal_render($mark_build)), 'author' => array('data' => array('#theme' => 'username', '#account' => $node->getOwner())), 'replies' => array('class' => array('replies'), 'data' => $comments), - 'last updated' => array('data' => t('!time ago', array('!time' => \Drupal::service('date')->formatInterval(REQUEST_TIME - $node->last_activity)))), + 'last updated' => array('data' => t('!time ago', array('!time' => \Drupal::service('date.formatter')->formatInterval(REQUEST_TIME - $node->last_activity)))), ); $rows[] = $row; diff --git a/core/modules/update/update.module b/core/modules/update/update.module index 0ce90b4985686f547e17db00f119a5af3dcfc01b..6529a48f555763e34b20c1b047fd6e40d24d40b1 100644 --- a/core/modules/update/update.module +++ b/core/modules/update/update.module @@ -575,7 +575,7 @@ function _update_project_status_sort($a, $b) { * @see theme_update_report() */ function template_preprocess_update_last_check(&$variables) { - $variables['time'] = \Drupal::service('date')->formatInterval(REQUEST_TIME - $variables['last']); + $variables['time'] = \Drupal::service('date.formatter')->formatInterval(REQUEST_TIME - $variables['last']); $variables['link'] = \Drupal::l(t('Check manually'), 'update.manual_status', array(), array('query' => drupal_get_destination())); } diff --git a/core/modules/user/src/Controller/UserController.php b/core/modules/user/src/Controller/UserController.php index 2c414c172d7c614f57ccf5ffbce0731ffe64f3ef..a895bc761759d1ad0ded0b3dbbd0d87a4a74b864 100644 --- a/core/modules/user/src/Controller/UserController.php +++ b/core/modules/user/src/Controller/UserController.php @@ -13,7 +13,7 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; -use Drupal\Core\Datetime\Date as DateFormatter; +use Drupal\Core\Datetime\DateFormatter; use Drupal\user\UserStorageInterface; /** @@ -24,7 +24,7 @@ class UserController extends ControllerBase { /** * The date formatter service. * - * @var \Drupal\Core\Datetime\Date + * @var \Drupal\Core\Datetime\DateFormatter */ protected $dateFormatter; @@ -38,7 +38,7 @@ class UserController extends ControllerBase { /** * Constructs a UserController object. * - * @param \Drupal\Core\Datetime\Date $date_formatter + * @param \Drupal\Core\Datetime\DateFormatter $date_formatter * The date formatter service. * @param \Drupal\user\UserStorageInterface $user_storage * The user storage. @@ -53,7 +53,7 @@ public function __construct(DateFormatter $date_formatter, UserStorageInterface */ public static function create(ContainerInterface $container) { return new static( - $container->get('date'), + $container->get('date.formatter'), $container->get('entity.manager')->getStorage('user') ); } diff --git a/core/modules/user/src/Tests/UserAdminListingTest.php b/core/modules/user/src/Tests/UserAdminListingTest.php index 13a79e5e235fb8ce4b4b218057c8326acf1c6de1..65e9ef33c4fadfd82f37cf77ff4a540dec4f7107 100644 --- a/core/modules/user/src/Tests/UserAdminListingTest.php +++ b/core/modules/user/src/Tests/UserAdminListingTest.php @@ -90,7 +90,7 @@ public function testUserListing() { $expected_roles = array('custom_role_1', 'custom_role_2'); $this->assertEqual($result_accounts[$role_account_name]['roles'], $expected_roles, 'Ensure roles are listed properly.'); - $this->assertEqual($result_accounts[$timestamp_user]['member_for'], \Drupal::service('date')->formatInterval(REQUEST_TIME - $accounts[$timestamp_user]->created->value), 'Ensure the right member time is displayed.'); + $this->assertEqual($result_accounts[$timestamp_user]['member_for'], \Drupal::service('date.formatter')->formatInterval(REQUEST_TIME - $accounts[$timestamp_user]->created->value), 'Ensure the right member time is displayed.'); } } diff --git a/core/modules/user/src/UserListBuilder.php b/core/modules/user/src/UserListBuilder.php index 53eb1b914cab6f83573c5ba8f325128403d45759..667ba4fcd5c9309808e09069577945441d0f357f 100644 --- a/core/modules/user/src/UserListBuilder.php +++ b/core/modules/user/src/UserListBuilder.php @@ -7,7 +7,7 @@ namespace Drupal\user; -use Drupal\Core\Datetime\Date as DateFormatter; +use Drupal\Core\Datetime\DateFormatter; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityListBuilder; use Drupal\Core\Entity\EntityStorageInterface; @@ -32,7 +32,7 @@ class UserListBuilder extends EntityListBuilder { /** * The date formatter service. * - * @var \Drupal\Core\Datetime\Date + * @var \Drupal\Core\Datetime\DateFormatter */ protected $dateFormatter; @@ -45,7 +45,7 @@ class UserListBuilder extends EntityListBuilder { * The entity storage class. * @param \Drupal\Core\Entity\Query\QueryFactory $query_factory * The entity query factory. - * @param \Drupal\Core\Datetime\Date $date_formatter + * @param \Drupal\Core\Datetime\DateFormatter $date_formatter * The date formatter service. */ public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, QueryFactory $query_factory, DateFormatter $date_formatter) { @@ -62,7 +62,7 @@ public static function createInstance(ContainerInterface $container, EntityTypeI $entity_type, $container->get('entity.manager')->getStorage($entity_type->id()), $container->get('entity.query'), - $container->get('date') + $container->get('date.formatter') ); } diff --git a/core/modules/user/user.module b/core/modules/user/user.module index c23cc2ca3fac26c403eede8ea447aee01056de27..2254e16750e200eb405810156ae8bbdcf102eacb 100644 --- a/core/modules/user/user.module +++ b/core/modules/user/user.module @@ -475,7 +475,7 @@ function user_user_view(array &$build, UserInterface $account, EntityViewDisplay if ($display->getComponent('member_for')) { $build['member_for'] = array( '#type' => 'item', - '#markup' => '<h4 class="label">' . t('Member for') . '</h4> ' . \Drupal::service('date')->formatInterval(REQUEST_TIME - $account->getCreatedTime()), + '#markup' => '<h4 class="label">' . t('Member for') . '</h4> ' . \Drupal::service('date.formatter')->formatInterval(REQUEST_TIME - $account->getCreatedTime()), ); } } diff --git a/core/modules/views/src/Plugin/views/cache/Time.php b/core/modules/views/src/Plugin/views/cache/Time.php index 48fad3e5b5723f088bd934d9ba8be8428ecf3e7b..4b6984fd7279b03bbe9f1a1e15bb35d0429e3d2b 100644 --- a/core/modules/views/src/Plugin/views/cache/Time.php +++ b/core/modules/views/src/Plugin/views/cache/Time.php @@ -7,7 +7,7 @@ namespace Drupal\views\Plugin\views\cache; -use Drupal\Core\Datetime\Date as DateFormatter; +use Drupal\Core\Datetime\DateFormatter; use Drupal\Core\Cache\Cache; use Symfony\Component\DependencyInjection\ContainerInterface; use Drupal\Core\Form\FormStateInterface; @@ -33,7 +33,7 @@ class Time extends CachePluginBase { /** * The date formatter service. * - * @var \Drupal\Core\Datetime\Date + * @var \Drupal\Core\Datetime\DateFormatter */ protected $dateFormatter; @@ -46,7 +46,7 @@ class Time extends CachePluginBase { * The plugin_id for the plugin instance. * @param mixed $plugin_definition * The plugin implementation definition. - * @param \Drupal\Core\Datetime\Date $date_formatter + * @param \Drupal\Core\Datetime\DateFormatter $date_formatter * The date formatter service. */ public function __construct(array $configuration, $plugin_id, $plugin_definition, DateFormatter $date_formatter) { @@ -62,7 +62,7 @@ public static function create(ContainerInterface $container, array $configuratio $configuration, $plugin_id, $plugin_definition, - $container->get('date') + $container->get('date.formatter') ); } diff --git a/core/modules/views/src/Plugin/views/field/Date.php b/core/modules/views/src/Plugin/views/field/Date.php index 588867066b3d419ce1bd273e06415785658c314f..c1a47c37e3e8871306cee36951c9aa250097ac14 100644 --- a/core/modules/views/src/Plugin/views/field/Date.php +++ b/core/modules/views/src/Plugin/views/field/Date.php @@ -11,7 +11,7 @@ use Drupal\Core\Form\FormStateInterface; use Drupal\views\ResultRow; use Symfony\Component\DependencyInjection\ContainerInterface; -use Drupal\Core\Datetime\Date as DateFormatter; +use Drupal\Core\Datetime\DateFormatter; /** * A handler to provide proper displays for dates. @@ -25,7 +25,7 @@ class Date extends FieldPluginBase { /** * The date formatter service. * - * @var \Drupal\Core\Datetime\Date + * @var \Drupal\Core\Datetime\DateFormatter */ protected $dateFormatter; @@ -45,7 +45,7 @@ class Date extends FieldPluginBase { * The plugin ID for the plugin instance. * @param mixed $plugin_definition * The plugin implementation definition. - * @param \Drupal\Core\Datetime\Date $date_formatter + * @param \Drupal\Core\Datetime\DateFormatter $date_formatter * The date formatter service. * @param \Drupal\Core\Entity\EntityStorageInterface $date_format_storage * The date format storage. @@ -65,7 +65,7 @@ public static function create(ContainerInterface $container, array $configuratio $configuration, $plugin_id, $plugin_definition, - $container->get('date'), + $container->get('date.formatter'), $container->get('entity.manager')->getStorage('date_format') ); } diff --git a/core/modules/views/src/Plugin/views/field/TimeInterval.php b/core/modules/views/src/Plugin/views/field/TimeInterval.php index bd3fae4a1933b9f8bce577d48ae0e439f125c29e..62f0286b2b931f7c0a5c9417fcd5512d3ba48f1b 100644 --- a/core/modules/views/src/Plugin/views/field/TimeInterval.php +++ b/core/modules/views/src/Plugin/views/field/TimeInterval.php @@ -7,7 +7,7 @@ namespace Drupal\views\Plugin\views\field; -use Drupal\Core\Datetime\Date as DateFormatter; +use Drupal\Core\Datetime\DateFormatter; use Drupal\Core\Form\FormStateInterface; use Drupal\views\ResultRow; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -24,7 +24,7 @@ class TimeInterval extends FieldPluginBase { /** * The date formatter service. * - * @var \Drupal\Core\Datetime\Date + * @var \Drupal\Core\Datetime\DateFormatter */ protected $dateFormatter; @@ -37,7 +37,7 @@ class TimeInterval extends FieldPluginBase { * The plugin_id for the plugin instance. * @param mixed $plugin_definition * The plugin implementation definition. - * @param \Drupal\Core\Datetime\Date $date_formatter + * @param \Drupal\Core\Datetime\DateFormatter $date_formatter * The date formatter service. */ public function __construct(array $configuration, $plugin_id, $plugin_definition, DateFormatter $date_formatter) { @@ -53,7 +53,7 @@ public static function create(ContainerInterface $container, array $configuratio $configuration, $plugin_id, $plugin_definition, - $container->get('date') + $container->get('date.formatter') ); } diff --git a/core/modules/views/src/Tests/Handler/FieldDateTest.php b/core/modules/views/src/Tests/Handler/FieldDateTest.php index 0fe52111d5bcd310f960ed8404ed3363c624ff76..c90413f986d13d149cc6ce8b1e4f3e5ae34d61c6 100644 --- a/core/modules/views/src/Tests/Handler/FieldDateTest.php +++ b/core/modules/views/src/Tests/Handler/FieldDateTest.php @@ -64,11 +64,11 @@ public function testFieldDate() { } $intervals = array( - 'raw time ago' => $this->container->get('date')->formatInterval(REQUEST_TIME - $time, 2), - 'time ago' => t('%time ago', array('%time' => $this->container->get('date')->formatInterval(REQUEST_TIME - $time, 2))), + 'raw time ago' => $this->container->get('date.formatter')->formatInterval(REQUEST_TIME - $time, 2), + 'time ago' => t('%time ago', array('%time' => $this->container->get('date.formatter')->formatInterval(REQUEST_TIME - $time, 2))), // TODO write tests for them -// 'raw time span' => $this->container->get('date')->formatInterval(REQUEST_TIME - $time, 2), -// 'time span' => t('%time hence', array('%time' => $this->container->get('date')->formatInterval(REQUEST_TIME - $time, 2))), +// 'raw time span' => $this->container->get('date.formatter')->formatInterval(REQUEST_TIME - $time, 2), +// 'time span' => t('%time hence', array('%time' => $this->container->get('date.formatter')->formatInterval(REQUEST_TIME - $time, 2))), ); $this->assertRenderedDatesEqual($view, $intervals); } diff --git a/core/modules/views_ui/src/ViewEditForm.php b/core/modules/views_ui/src/ViewEditForm.php index 719586ea4321e2884ddca183af2b9547a72ac726..be94add95a487c86dbe7d6f10b5c83871040de8e 100644 --- a/core/modules/views_ui/src/ViewEditForm.php +++ b/core/modules/views_ui/src/ViewEditForm.php @@ -11,7 +11,7 @@ use Drupal\Core\Ajax\AjaxResponse; use Drupal\Core\Ajax\HtmlCommand; use Drupal\Core\Ajax\ReplaceCommand; -use Drupal\Core\Datetime\Date as DateFormatter; +use Drupal\Core\Datetime\DateFormatter; use Drupal\Component\Utility\NestedArray; use Drupal\Component\Utility\String; use Drupal\Core\Form\FormStateInterface; @@ -43,7 +43,7 @@ class ViewEditForm extends ViewFormBase { /** * The date formatter service. * - * @var \Drupal\Core\Datetime\Date + * @var \Drupal\Core\Datetime\DateFormatter */ protected $dateFormatter; @@ -54,7 +54,7 @@ class ViewEditForm extends ViewFormBase { * The factory for the temp store object. * @param \Symfony\Component\HttpFoundation\RequestStack $requestStack * The request stack object. - * @param \Drupal\Core\Datetime\Date $date_formatter + * @param \Drupal\Core\Datetime\DateFormatter $date_formatter * The date Formatter service. */ public function __construct(TempStoreFactory $temp_store_factory, RequestStack $requestStack, DateFormatter $date_formatter) { @@ -70,7 +70,7 @@ public static function create(ContainerInterface $container) { return new static( $container->get('user.tempstore'), $container->get('request_stack'), - $container->get('date') + $container->get('date.formatter') ); } diff --git a/core/scripts/run-tests.sh b/core/scripts/run-tests.sh index 16b29ca1dbd3ee1d65f93a660404f7a802dafa44..70bdf4a12d8578ea69f1949a66e0ad474e7419aa 100755 --- a/core/scripts/run-tests.sh +++ b/core/scripts/run-tests.sh @@ -957,7 +957,7 @@ function simpletest_script_reporter_write_xml_results() { function simpletest_script_reporter_timer_stop() { echo "\n"; $end = Timer::stop('run-tests'); - echo "Test run duration: " . \Drupal::service('date')->formatInterval($end['time'] / 1000); + echo "Test run duration: " . \Drupal::service('date.formatter')->formatInterval($end['time'] / 1000); echo "\n\n"; } diff --git a/core/tests/Drupal/Tests/Core/Datetime/DateTest.php b/core/tests/Drupal/Tests/Core/Datetime/DateTest.php index 3b56c1e785b369ca49f3540ca7f6cda41fd14d62..74a155943b0ef70a25b6b2e1f4471f5b82e9b21d 100644 --- a/core/tests/Drupal/Tests/Core/Datetime/DateTest.php +++ b/core/tests/Drupal/Tests/Core/Datetime/DateTest.php @@ -7,7 +7,7 @@ namespace Drupal\Tests\Core\Datetime; -use Drupal\Core\Datetime\Date as DateFormatter; +use Drupal\Core\Datetime\DateFormatter; use Drupal\Tests\UnitTestCase; /** @@ -40,7 +40,7 @@ class DateTest extends UnitTestCase { /** * The tested date service class. * - * @var \Drupal\Core\Datetime\Date + * @var \Drupal\Core\Datetime\DateFormatter */ protected $dateFormatter; @@ -57,7 +57,7 @@ protected function setUp() { * * @dataProvider providerTestFormatInterval * - * @see \Drupal\Core\Datetime\Date::formatInterval() + * @see \Drupal\Core\Datetime\DateFormatter::formatInterval() */ public function testFormatInterval($interval, $granularity, $expected, $langcode = NULL) { // Mocks a simple formatPlural implementation.