Code that extends existing basic PHP-functionality

1.1.1 2018-10-03 16:26 UTC

This package is auto-updated.

Last update: 2024-10-29 00:16:44 UTC


README

Build Status codecov FOSSA Status Scrutinizer Code Quality

util

Code that extends existing basic PHP-functionality

$from = '5'; // possible also: '1.5.', '5-1', '2018-05-01'
$to = '7';

$dateHelper = new DateHelper();
list($fromDateTime, $toDateTime) = $dateHelper->buildDateTimeRangeFromTwoInputs($from, $to);
// Default $to is generated by third parameter as DateInterval:
// list($fromDateTime, $toDateTime) = $dateHelper->buildDateTimeRangeFromTwoInputs($from, null, 'P2M');


var_export([$fromDateTime->format('Y-m'), $toDateTime->format('Y-m')]);

Result looks like this: (given today is 2018)

array ( 0 => '2018-05-01', 1 => '2018-08-01', )

$dateHelper = new DateHelper();
$date = $dateHelper->buildDateTimeSince('P3D'); // Interval param defaults to P7D = 1 week - will use P1D if not parsable

print($date->format('Y-m-d'));

Result looks like this: (given today is 2018-05-01)

2018-05-04

$dateHelper = new DateHelper();
$text = $dateHelper->diffToText(new DateInterval('P3DPT4H5M6S'));

print($text);

Result looks like this:

3d 4h 5m 6s

$text = StringHelper::trim('Longtext', 5);

print($text);

Result looks like this:

Longt...

$text = StringHelper::shortenNameToFirst('John Doe');

print($text);

Result looks like this:

John D

License

FOSSA Status