2017 © Pedro Peláez
 

library dateinterval

DateInterval extension

image

rm/dateinterval

DateInterval extension

  • Tuesday, February 27, 2018
  • by romanmatyus
  • Repository
  • 1 Watchers
  • 1 Stars
  • 52 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 33 % Grown

The README.md

RM\DateInterval

Build Status Code Quality Code Coverage Latest Stable Version Latest Unstable Version License, (*1)

Simple library for manipulating with date intervals in PHP., (*2)

Requirements

  • PHP 7.0

Installation

$ composer require rm/dateinterval

Features

Extends creation possibility

namespace RM\DateInterval;

new DateInterval; // 0 seconds
new DateInterval('PT0S'); // 0 seconds
new DateInterval(new \DateInterval('PT0S')); // 0 seconds
new DateInterval('-P1D'); // - 1 day
new DateInterval('+2 minutes'); 
new DateInterval(10); // 10 seconds
new DateInterval(-1000); // -1000 seconds
new DateInterval(5.5); // 6 seconds

Adding/Subtraction

Allowing summarize multiple intervals into one., (*3)

$interval = new \RM\DateInterval;
foreach ([
    'PT10S', // 0:10
    'PT13M14S', // 13:24
    'PT3M3S', // 16:27
    'PT4M58S', // 21:25
] as $data) {
    $interval->add($data);
}
echo $interval->format('%i:%s'); // '21:25'

Convert to seconds

Usable for comparing., (*4)

(new \RM\DateInterval('+1 day'))->toSeconds(); // int(86400)

Generate string

Generating standardized string, for storing interval to database., (*5)

$now = new DateTime;
$next = clone $now;
$next->modify('+1 day') // 1 day
    ->modify('+14 hours') // 1 day 14 hours
    ->modify('-3 minutes') // 1 day 13 hours 57 mins
    ->modify('13 seconds'); // 1 day 13 hours 57 mins 13 seconds
$interval = new \RM\DateInterval($now->diff($next));
echo (string) $interval; // P1DT13H57M13S

$interval = new \RM\DateInterval($string);
echo $interval->format('%dd %hh %im %ss'); // 1d 13h 57m 13s

Alternatively it's possible use only static method RM\DateInterval::parse(DateInterval $interval)., (*6)

The Versions

27/02 2018

dev-master

9999999-dev https://github.com/romanmatyus/DateInterval

DateInterval extension

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

14/10 2017
13/10 2017