PHP code example of damenjo / rutin

1. Go to this page and download the library: Download damenjo/rutin library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

damenjo / rutin example snippets


use Damenjo\Rutin\Main\Rutin;
// 2023-08-03 20:39:45
$now = Rutin::now()->format();
 
$now = Rutin::now("Asia/Jakarta")->format();

// 2023-08-03
$date = Rutin::now("Asia/Jakarta")->format("Y-m-d");
// 20:39:45
$time = Rutin::now("Asia/Jakarta")->format("H:i:s");
// 2023
$year = Rutin::now("Asia/Jakarta")->format("Y");

// 2023-08-04
$rutin = Rutin::now()->add("day",1)->format("Y-m-d");

// 2023-08-03
$rutinNow = Rutin::now()->format("Y-m-d");

// 2023-08-04
$rutinPlusOneDay = Rutin::now()->addDay()->format("Y-m-d");

// 2023-08-05
$rutinPlusTwoDay = Rutin::now()->addDays(2)->format("Y-m-d");

// 2023-08-03
$rutinNull = Rutin::now()->addDays(null ?? 0)->format("Y-m-d");

try {
    // Invalid argument data type
    $rutinNull = Rutin::now()->addDays("")->format("Y-m-d");
} catch (\Damenjo\Rutin\Exceptions\RutinException $e) {
    // We recommend you to use this catch blocks too
    echo $e->ruinMessage();
} catch (\TypeError $e) {
    // Do whatever you want inside this block
}

$prediction = true;
$rutinPlusOneDayIf = Rutin::now()->addDayIf(fn() => $prediction)->format("Y-m-d");

$prediction = true;
Rutin::now()->while(fn() => $prediction)->add("month",3)->format("Y-m-d");