arokettu / datetime-rounding
DateTime rounding helper
1.0.0
2023-11-15 18:35 UTC
Requires
- php: ^7.1 | ^8.0
Requires (Dev)
- nesbot/carbon: ^2.71
- phpunit/phpunit: >= 7.5 < 10
- sandfox.dev/code-standard: ^1.2023.06.29
- squizlabs/php_codesniffer: *
- vimeo/psalm: ^4 | ^5
This package is auto-updated.
Last update: 2024-11-25 18:14:20 UTC
README
A tool to truncate a DateTime instance to a specific time unit.
Installation
composer require arokettu/datetime-rounding
Example
<?php use Arokettu\DateTime\DateTimeTruncate; use Carbon\CarbonImmutable; // to hours $dateTime = new DateTimeImmutable('2012-03-04T05:06:07.890123Z'); echo DateTimeTruncate::toHours($dateTime)->format('c'); // 2012-03-04T05:00:00+00:00 // truncating to dates uses the DT timezone $dateTime = new DateTimeImmutable('2012-03-04T05:06:07.890123 Europe/Stockholm'); echo DateTimeTruncate::toMonths($dateTime)->format('c'); // 2012-03-01T00:00:00+01:00 // using mutable will change the object $dateTime = new DateTime('2012-03-04T05:06:07.890123Z'); DateTimeTruncate::toMinutes($dateTime); echo $dateTime->format('c'); // 2012-03-04T05:06:00+00:00 // the tool tries to preserve the extended objects as well $dateTime = new CarbonImmutable('2012-03-04T05:06:07.890123Z'); echo get_class(DateTimeTruncate::toMonths($dateTime)); // Carbon\CarbonImmutable
Documentation
Read full documentation here: https://sandfox.dev/php/datetime-rounding.html
Support
Please file issues on our main repo at GitLab: https://gitlab.com/sandfox/datetime-rounding/-/issues
Feel free to ask any questions in our room on Gitter: https://gitter.im/arokettu/community
License
The library is available as open source under the terms of the MIT License.