dpeuscher / util
Code that extends existing basic PHP-functionality
Installs: 7 318
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 2
Open Issues: 22
Requires
- psr/log: ^1.0
- psr/simple-cache: ^1.0
Requires (Dev)
- phpunit/phpunit: ^7.2
This package is auto-updated.
Last update: 2024-10-29 00:16:44 UTC
README
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