You are here

public static function Schedule::secondsToPeriod in Backup and Migrate 5.0.x

Same name and namespace in other branches
  1. 8.4 src/Entity/Schedule.php \Drupal\backup_migrate\Entity\Schedule::secondsToPeriod()

Convert a number of seconds into a period array.

Parameters

int $seconds: The number of seconds to convert.

Return value

array An array containing the period definition and the number of them. ['number' => 123, 'type' => [...]]

Throws

\Drupal\backup_migrate\Core\Exception\BackupMigrateException

2 calls to Schedule::secondsToPeriod()
Schedule::getPeriodFormatted in src/Entity/Schedule.php
Return the schedule frequency formatted for display in human language.
ScheduleForm::form in src/Form/ScheduleForm.php
Gets the actual form array to be built.

File

src/Entity/Schedule.php, line 244

Class

Schedule
Defines the Schedule entity.

Namespace

Drupal\backup_migrate\Entity

Code

public static function secondsToPeriod($seconds) {
  foreach (array_reverse(Schedule::getPeriodTypes()) as $type) {
    if ($seconds % $type['seconds'] === 0) {
      return [
        'number' => $seconds / $type['seconds'],
        'type' => $type,
      ];
    }
  }
  throw new BackupMigrateException('Invalid period.');
}