Deprecated function: Implicit conversion from float-string "<float>" to int loses precision

Created on 19 May 2022, over 2 years ago
Updated 27 July 2023, over 1 year ago

Problem/Motivation

When using PHP 8.1 and viewing the Cron Tasks page (/admin/config/system/cron/jobs) the following warnings are displayed:

Deprecated function: Implicit conversion from float-string "1652964155.9678" to int loses precision in Drupal\Component\Datetime\DateTimePlus->__call() (line 360 of core/lib/Drupal/Component/Datetime/DateTimePlus.php).
Drupal\Component\Datetime\DateTimePlus->__call('setTimestamp', Array) (Line: 204)
Drupal\Component\Datetime\DateTimePlus::createFromTimestamp('1652964155.9678', Object, Array) (Line: 122)
Drupal\Core\Datetime\DateFormatter->format('1652964155.9678', 'short') (Line: 53)
Drupal\ultimate_cron\CronJobListBuilder->buildRow(Object) (Line: 126)
Drupal\Core\Config\Entity\DraggableListBuilder->buildForm(Array, Object)
call_user_func_array(Array, Array) (Line: 531)
Drupal\Core\Form\FormBuilder->retrieveForm('ultimate_cron_job_list', Object) (Line: 278)

Steps to reproduce

  • Use PHP 8.1
  • Install ultimate_cron
  • Visit Cron Tasks page (/admin/config/system/cron/jobs)

Proposed resolution

Convert the start_time to an int before passing it over to \Drupal::service('date.formatter')->format()

πŸ› Bug report
Status

Closed: duplicate

Version

2.0

Component

Code

Created by

πŸ‡¬πŸ‡§United Kingdom 3li U.K. πŸ‡¬πŸ‡§

Live updates comments and jobs are added and updated live.
  • PHP 8.1

    The issue particularly affects sites running on PHP version 8.1.0 or later.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States jakegibs617

    This patch is no longer working for "drupal/ultimate_cron": "^2.0@alpha", https://www.drupal.org/project/ultimate_cron/releases/8.x-2.0-alpha6 β†’ which is the Drupal 10 compatible version.

    the new line is now:

    $row['started']['#markup'] = $log_entry->start_time ? \Drupal::service('date.formatter')->format((int) $log_entry->start_time, "short") : $this->t('Never');

    compared to the old

    -    $row['started']['#markup'] = $log_entry->start_time ? \Drupal::service('date.formatter')->format($log_entry->start_time, "short") : $this->t('Never');
    +    $row['started']['#markup'] = $log_entry->start_time ? \Drupal::service('date.formatter')->format($start_time, "short") : $this->t('Never');
     

    It seems since they added (int) that we do not need this patch any more.
    Is this accurate?

Production build 0.71.5 2024