public static function calculate_next_automated_backup($ignoredtimezone, $now) {

        $config = get_config('backup');

        $backuptime = new DateTime('@' . $now);
        $backuptime->setTimezone(core_date::get_server_timezone_object());
        $backuptime->setTime($config->backup_auto_hour, $config->backup_auto_minute);

        while ($backuptime->getTimestamp() < $now) {
            $backuptime->add(new DateInterval('P1D'));
        }

        // Get number of days from backup date to execute backups.
        $automateddays = substr($config->backup_auto_weekdays, $backuptime->format('w')) . $config->backup_auto_weekdays;
        $daysfromnow = strpos($automateddays, "1");

        // Error, there are no days to schedule the backup for.
        if ($daysfromnow === false) {
            return 0;
        }

        if ($daysfromnow > 0) {
            $backuptime->add(new DateInterval('P' . $daysfromnow . 'D'));
        }

        return $backuptime->getTimestamp();
    }
public static function calculate_next_automated_backup($ignoredtimezone, $now) {

        $config = get_config('backup');

        $backuptime = new DateTime('@' . $now);
        $backuptime->setTimezone(core_date::get_server_timezone_object());
        $backuptime->setTime($config->backup_auto_hour, $config->backup_auto_minute);

        while ($backuptime->getTimestamp() < $now) {
            $backuptime->add(new DateInterval('P1D'));
        }

        // Get number of days from backup date to execute backups.
        $automateddays = substr($config->backup_auto_weekdays, $backuptime->format('w')) . $config->backup_auto_weekdays;
        $daysfromnow = strpos($automateddays, "1");

        // Error, there are no days to schedule the backup for.
        if ($daysfromnow === false) {
            return 0;
        }

        if ($daysfromnow > 0) {
            $backuptime->add(new DateInterval('P' . $daysfromnow . 'D'));
        }

        return $backuptime->getTimestamp();
    }
public static function calculate_next_automated_backup ( $ ignoredtimezone , $ now ) { $ config = get_config ( 'backup' ) ; $ backuptime = new DateTime ( '@' . $ now ) ; $ backuptime -> setTimezone ( core_date :: get_server_timezone_object ( ) ) ; $ backuptime -> setTime ( $ config -> backup_auto_hour , $ config -> backup_auto_minute ) ; while ( $ backuptime -> getTimestamp ( ) < $ now ) { $ backuptime -> add ( new DateInterval ( 'P1D' ) ) ; } // Get number of days from backup date to execute backups. $ automateddays = substr ( $ config -> backup_auto_weekdays , $ backuptime -> format ( 'w' ) ) . $ config -> backup_auto_weekdays ; $ daysfromnow = strpos ( $ automateddays , "1" ) ; // Error, there are no days to schedule the backup for. if ( $ daysfromnow === false ) { return 0 ; } if ( $ daysfromnow > 0 ) { $ backuptime -> add ( new DateInterval ( 'P' . $ daysfromnow . 'D' ) ) ; } return $ backuptime -> getTimestamp ( ) ; }
Works out the next time the automated backup should be run.

@param mixed $ignoredtimezone all settings are in server timezone!
@param int $now timestamp, should not be in the past, most likely time()
@return int timestamp of the next execution at server time
Works out the next time the automated backup should be run .