philippwitzmann / date-time-handler
日期和时间框架
1.2
2019-12-31 09:55 UTC
Requires
- nesbot/carbon: ~1.36.0
Requires (Dev)
- php: >=7.2
- mockery/mockery: ^1.1
- philippwitzmann/codingstandard: ^3.0
- philippwitzmann/testing: ~1.1
This package is auto-updated.
Last update: 2024-09-29 05:42:35 UTC
README
这个库旨在提供基本功能,用于处理(可测试的)日期、时间和DateTime对象。
安装
composer require philippwitzmann/date-time-handler
使用方法
创建实例
设置时间
$year = 2000; $month = 12; $day = 30; $hours = 20; $minutes = 58; $seconds = 13; $timeZone = new DateTimeZone('Europe/Berlin'); $dateTimeHandler = new DateTimeHandler( $year, $month, $day, $hours, $minutes, $seconds, $timeZone );
使用当前时间
$dateTimeHandler = new DateTimeHandler();
比较两个DateTime
$dateTimeHandler = new DateTimeHandler( $year, $month, $day, $hours, $minutes, $seconds, $timeZone ); $date = new Date($year + 1, $month, $day); $time = new Time($hours, $minutes, $seconds); $dateTimeToDiffAgainst = new DateTime( $date, $time, $timeZone ); $dateInverval = $dateTimeHandler->diff($dateTimeToDiffAgainst);
设置测试时间
$dateTimeHandler = new DateTimeHandler(); $dateTimeHandler->setTestNow(); //freezes time $dateTimeHandler->getTime(); // returns the Time, setTestNow() was called at.
运行测试
php vendor/bin/phpunit tests/ --configuration=config/phpunit.xml