Skip to content

Commit

Permalink
Merge pull request #19466 from demeritcowboy/api4-reldate-5.34
Browse files Browse the repository at this point in the history
backport of 19462 - relative date test failure
  • Loading branch information
seamuslee001 authored Jan 30, 2021
2 parents 05e1fac + f564e9e commit 2cdcd16
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions tests/phpunit/api/v4/Action/DateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,24 @@ public function testRelativeDateRanges() {
->addValue('last_name', 'one')
->execute()
->first()['id'];

// Avoid problems with `strtotime(<date arithmetic expression>)` giving
// impossible dates like April 31 which roll over and then don't match.
$thisMonth = date('m');
$lastMonth = ($thisMonth === 1 ? 12 : $thisMonth - 1);
$nextMonth = ($thisMonth === 12 ? 1 : $thisMonth + 1);
$lastMonthsYear = ($thisMonth === 1 ? date('Y') - 1 : date('Y'));
$nextMonthsYear = ($thisMonth === 12 ? date('Y') + 1 : date('Y'));

$act = Activity::save()
->setDefaults(['activity_type_id:name' => 'Meeting', 'source_contact_id' => $c1])
->addRecord(['activity_date_time' => 'now - 3 year'])
->addRecord(['activity_date_time' => 'now - 1 year'])
->addRecord(['activity_date_time' => 'now - 1 month'])
->addRecord(['activity_date_time' => (date('Y') - 3) . '-' . date('m-01 H:i:s')])
->addRecord(['activity_date_time' => (date('Y') - 1) . '-' . date('m-01 H:i:s')])
->addRecord(['activity_date_time' => "{$lastMonthsYear}-{$lastMonth}-01 " . date('H:i:s')])
->addRecord(['activity_date_time' => 'now'])
->addRecord(['activity_date_time' => 'now + 1 month'])
->addRecord(['activity_date_time' => 'now + 1 year'])
->addRecord(['activity_date_time' => 'now + 3 year'])
->addRecord(['activity_date_time' => "{$nextMonthsYear}-{$nextMonth}-01 " . date('H:i:s')])
->addRecord(['activity_date_time' => (date('Y') + 1) . '-' . date('m-01 H:i:s')])
->addRecord(['activity_date_time' => (date('Y') + 3) . '-' . date('m-01 H:i:s')])
->execute()->column('id');

$result = Activity::get(FALSE)->addSelect('id')
Expand Down

0 comments on commit 2cdcd16

Please sign in to comment.