shortdark/powercable

Checks to see if the current time or start time/date is far enough away from an end date/time.

0.4.7 2019-04-21 17:54 UTC

This package is auto-updated.

Last update: 2024-03-22 19:18:41 UTC


README

Powercable tells you from the start time and end time whether a product that takes n days is able to be ordered. Also, working backwards from the end time, do we have enough time to process the order.

Installation

Install the latest version with

$ composer require shortdark/powercable

Basic Usage

<?php

require_once 'vendor/autoload.php';

$test = new Shortdark\Powercable();

$test->endtime = '1556452800'; // UNIX timestamp for the end time

/*
 * Calculate the latest dates we can start work based on the end time
 */
$test->latestStartTime();
var_dump($test->image_message);

/*
 * Calculate whether someone can order a product that takes n days
 */
$test->earliestEndTime();
var_dump($test->workdays_boolean);

Basic Usage in a Laravel Controller

<?php

use App\Http\Controllers\Controller;
use Shortdark\Powercable;

class MyController extends Controller
{
    public function index(Powercable $power)
    {
        $power->latestStartTime();
        $result = $power->image_message;
        return view('index', compact('result'));
    }
    
}

Then, as $result is an array, to get a representation of the array you could have something like the following in the index.blade.php.

{{ json_encode($result) }}

Author

Neil Ludlow - neil@shortdark.net - https://twitter.com/shortdark