granam/date-interval

Provides additional functionality to the DateInterval class

3.1.0 2021-03-25 07:56 UTC

This package is auto-updated.

Last update: 2024-12-25 16:18:02 UTC


README

Build Status

Provides additional functionality to the DateInterval class.

Usage

<?php

use Granam\DateInterval\DateInterval;

$interval = new DateInterval('P2H');
echo $interval->toSeconds(); // "7200"
echo $interval->toSpec(); // "P2H"

$fromSeconds = DateInterval::fromSeconds(7201);
echo $fromSeconds->toSpec(); // P2HS1

Summary

The DateInterval class builds on the existing DateInterval class provided by PHP. With the new class, you may

  • convert DateInterval to the interval spec
  • convert DateInterval to the number of seconds
  • convert number of seconds to DateInterval

Installation

Add it to your list of Composer dependencies:

composer require granam/date-interval