diff --git a/cron_example/cron_example.module b/cron_example/cron_example.module index 0112247..bfb3413 100644 --- a/cron_example/cron_example.module +++ b/cron_example/cron_example.module @@ -37,7 +37,7 @@ function cron_example_cron() { // We usually don't want to act every time cron runs (which could be every // minute) so keep a time for the next run in the site state. $next_execution = \Drupal::state()->get('cron_example.next_execution', 0); - if (REQUEST_TIME >= $next_execution) { + if (\Drupal::time()->getRequestTime()>= $next_execution) { // This is a silly example of a cron job. // It just makes it obvious that the job has run without // making any changes to your database. @@ -46,7 +46,7 @@ function cron_example_cron() { \Drupal::messenger()->addMessage(t('cron_example executed at %time', ['%time' => date('c')])); \Drupal::state()->set('cron_example_show_status_message', FALSE); } - \Drupal::state()->set('cron_example.next_execution', REQUEST_TIME + $interval); + \Drupal::state()->set('cron_example.next_execution', \Drupal::time()->getRequestTime() + $interval); } } diff --git a/cron_example/src/Form/CronExampleForm.php b/cron_example/src/Form/CronExampleForm.php index b93c609..6a22cc7 100644 --- a/cron_example/src/Form/CronExampleForm.php +++ b/cron_example/src/Form/CronExampleForm.php @@ -95,11 +95,11 @@ class CronExampleForm extends ConfigFormBase { ]; $next_execution = $this->state->get('cron_example.next_execution'); - $next_execution = !empty($next_execution) ? $next_execution : REQUEST_TIME; + $next_execution = !empty($next_execution) ? $next_execution : \Drupal::time()->getRequestTime(); $args = [ '%time' => date('c', $this->state->get('cron_example.next_execution')), - '%seconds' => $next_execution - REQUEST_TIME, + '%seconds' => $next_execution - \Drupal::time()->getRequestTime(), ]; $form['status']['last'] = [ '#type' => 'item', @@ -222,7 +222,7 @@ class CronExampleForm extends ConfigFormBase { // Create a new item, a new data object, which is passed to the // QueueWorker's processItem() method. $item = new \stdClass(); - $item->created = REQUEST_TIME; + $item->created = \Drupal::time()->getRequestTime(); $item->sequence = $i; $queue->createItem($item); } diff --git a/render_example/src/Controller/RenderExampleController.php b/render_example/src/Controller/RenderExampleController.php index 04bca2d..effbfe5 100644 --- a/render_example/src/Controller/RenderExampleController.php +++ b/render_example/src/Controller/RenderExampleController.php @@ -487,7 +487,7 @@ class RenderExampleController extends ControllerBase { $build = [ 'lazy_builder_time' => [ '#markup' => '

' . \Drupal::translation()->translate('The current time is @time', [ - '@time' => \Drupal::service('date.formatter')->format(REQUEST_TIME, 'long'), + '@time' => \Drupal::service('date.formatter')->format(\Drupal::time()->getRequestTime(), 'long'), ]) . '

', ], ];