/** * Compares two dates and returns true if they are the same day. * * @param Cake\I18n\FrozenTime $date1 First date * @param Cake\I18n\FrozenTime $date2 Second date * * @return bool */ public function isSameDay(FrozenTime $date1, FrozenTime $date2) { if ($date1->diffInDays($date2) > 0) { return false; } return true; }
/** * test the timezone option for timeAgoInWords * * @dataProvider classNameProvider * @return void */ public function testTimeAgoInWordsTimezone($class) { $time = new FrozenTime('1990-07-31 20:33:00 UTC'); $result = $time->timeAgoInWords(['timezone' => 'America/Vancouver', 'end' => '+1month', 'format' => 'dd-MM-YYYY HH:mm:ss']); $this->assertEquals('on 31-07-1990 13:33:00', $result); }
/** * Test isSameDay method * * @return void */ public function testIsSameDay() { $this->assertEquals(true, $this->ElabsTimeHelper->isSameDay(\Cake\I18n\FrozenTime::now(), \Cake\I18n\FrozenTime::now())); $this->assertEquals(false, $this->ElabsTimeHelper->isSameDay(\Cake\I18n\FrozenTime::now()->yesterday(), \Cake\I18n\FrozenTime::now()->tomorrow())); $this->assertEquals(true, $this->ElabsTimeHelper->isSameDay(\Cake\I18n\FrozenTime::now()->yesterday(), \Cake\I18n\FrozenTime::now()->subDay())); }
* */ Plugin::load('Migrations'); Plugin::load('Crud'); Plugin::load('ADmad/JwtAuth'); /** * Connect middleware/dispatcher filters. */ DispatcherFactory::add('Asset'); DispatcherFactory::add('Routing'); DispatcherFactory::add('NoExtensions'); DispatcherFactory::add('ControllerFactory'); /** * Enable immutable time objects in the ORM. * * You can enable default locale format parsing by adding calls * to `useLocaleParser()`. This enables the automatic conversion of * locale specific date formats. For details see * @link http://book.cakephp.org/3.0/en/core-libraries/internationalization-and-localization.html#parsing-localized-datetime-data */ Type::build('time')->useImmutable(); Type::build('date')->useImmutable(); Type::build('datetime')->useImmutable(); /** * More friendly formating of date/time in json output. */ use Cake\I18n\FrozenDate; use Cake\I18n\FrozenTime; FrozenDate::setJsonEncodeFormat('yyyy-MM-dd'); FrozenTime::setJsonEncodeFormat('yyyy-MM-dd HH:mm:ss');