rampesna/date-diff-calculator

Date Diff Calculator is a library that helps you to calculate the difference between two dates.

v1.1.0 2023-10-16 06:59 UTC

This package is auto-updated.

Last update: 2024-09-17 13:32:16 UTC


README

This package is a simple date diff calculator. It calculates the difference between two dates and returns the result in a human readable format.

Total Downloads GitHub repo size Build

Requirements

  • PHP >= 8.0

Installation

composer require rampesna/date-diff-calculator

Usage

Controller

use Rampesna\DateDiffCalculator;

class ExampleController extends Controller
{
    public function index(Request $request)
    {
        $permitStartDate = '2023-09-20 09:00:00';
        $permitEndDate = '2023-10-10 18:00:00';
    
        $dailyWorkingHours = 8;
    
        $dateDiffCalculator = new DateDiffCalculator(
            $dailyWorkingHours,
            $permitStartDate,
            $permitEndDate
        );
    
        $minutes = $dateDiffCalculator->calculate();
        
        return response()->json(
            $dateDiffCalculator->getDurationForHuman($minutes)
        );
    }
}

License

MIT License