mirror of
https://github.com/rlanvin/php-rrule.git
synced 2025-02-20 09:54:16 +01:00
Fix tests for PHP 5.6 and PHP 7.1
Fix bugs related to microseconds in PHP 7.1
This commit is contained in:
parent
e2f42382d4
commit
145c0817f7
@ -277,7 +277,16 @@ class RRule implements RRuleInterface
|
||||
}
|
||||
}
|
||||
else {
|
||||
$this->dtstart = new \DateTime();
|
||||
$this->dtstart = new \DateTime(); // for PHP 7.1+ this contains microseconds which causes many problems
|
||||
if ( version_compare(PHP_VERSION, '7.1.0') >= 0 ) {
|
||||
// remove microseconds
|
||||
$this->dtstart->setTime(
|
||||
$this->dtstart->format('H'),
|
||||
$this->dtstart->format('i'),
|
||||
$this->dtstart->format('s'),
|
||||
0
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// UNTIL (optional)
|
||||
|
@ -81,7 +81,17 @@ class RfcParser
|
||||
|
||||
if ( $dtstart ) {
|
||||
$nb_dtstart = 1;
|
||||
$dtstart_type = 'tzid';
|
||||
if ( is_string($dtstart) ) {
|
||||
if ( strlen($dtstart) == 10 ) {
|
||||
$dtstart_type = 'date';
|
||||
}
|
||||
else {
|
||||
$dtstart_type = 'localtime';
|
||||
}
|
||||
}
|
||||
else {
|
||||
$dtstart_type = 'tzid';
|
||||
}
|
||||
$parts['DTSTART'] = RRule::parseDate($dtstart);
|
||||
}
|
||||
|
||||
|
@ -1910,13 +1910,13 @@ class RRuleTest extends PHPUnit_Framework_TestCase
|
||||
public function testRfcStringParserWithDtStart()
|
||||
{
|
||||
$rrule = new RRule('RRULE:FREQ=YEARLY');
|
||||
$this->assertEquals(date_create(), $rrule[0]);
|
||||
$this->assertEquals(date_create()->format('Y-m-d'), $rrule[0]->format('Y-m-d'));
|
||||
|
||||
$rrule = new RRule('RRULE:FREQ=YEARLY', date_create('2017-01-01'));
|
||||
$this->assertEquals(date_create('2017-01-01'), $rrule[0]);
|
||||
$this->assertEquals('2017-01-01', $rrule[0]->format('Y-m-d'));
|
||||
|
||||
$rrule = new RRule('RRULE:FREQ=YEARLY', '2017-01-01');
|
||||
$this->assertEquals(date_create('2017-01-01'), $rrule[0]);
|
||||
$this->assertEquals('2017-01-01', $rrule[0]->format('Y-m-d'));
|
||||
|
||||
try {
|
||||
$rrule = new RRule("DTSTART:19970512\nRRULE:FREQ=YEARLY", date_create('2017-01-01'));
|
||||
@ -1968,7 +1968,7 @@ class RRuleTest extends PHPUnit_Framework_TestCase
|
||||
$rule = @ new RRule($str);
|
||||
|
||||
if ( $occurrences ) {
|
||||
$this->assertEquals($occurrences, $rule->getOccurrences());
|
||||
$this->assertEquals($occurrences, $rule->getOccurrences(), '', 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -439,12 +439,12 @@ class RSetTest extends PHPUnit_Framework_TestCase
|
||||
)));
|
||||
|
||||
$this->assertCount(1, $rset->getOccurrences(1));
|
||||
$this->assertEquals([date_create('2017-01-01')], $rset->getOccurrences(1));
|
||||
$this->assertEquals(array(date_create('2017-01-01')), $rset->getOccurrences(1));
|
||||
$this->assertCount(5, $rset->getOccurrences(5));
|
||||
$this->assertEquals([
|
||||
$this->assertEquals(array(
|
||||
date_create('2017-01-01'),date_create('2017-01-02'),date_create('2017-01-03'),
|
||||
date_create('2017-01-04'),date_create('2017-01-05')
|
||||
], $rset->getOccurrences(5));
|
||||
), $rset->getOccurrences(5));
|
||||
try {
|
||||
$rset->getOccurrences();
|
||||
$this->fail('Expected exception (infinite rule) not thrown');
|
||||
@ -463,7 +463,7 @@ class RSetTest extends PHPUnit_Framework_TestCase
|
||||
|
||||
$this->assertCount(1, $rset->getOccurrencesBetween('2017-01-01', null, 1));
|
||||
$this->assertCount(1, $rset->getOccurrencesBetween('2017-02-01', '2017-12-31', 1));
|
||||
$this->assertEquals([date_create('2017-02-01')], $rset->getOccurrencesBetween('2017-02-01', '2017-12-31', 1));
|
||||
$this->assertEquals(array(date_create('2017-02-01')), $rset->getOccurrencesBetween('2017-02-01', '2017-12-31', 1));
|
||||
$this->assertCount(5, $rset->getOccurrencesBetween('2017-01-01', null, 5));
|
||||
try {
|
||||
$rset->getOccurrencesBetween('2017-01-01', null);
|
||||
@ -517,8 +517,9 @@ class RSetTest extends PHPUnit_Framework_TestCase
|
||||
"RRULE:FREQ=DAILY;COUNT=3\nEXRULE:FREQ=DAILY;INTERVAL=2;COUNT=1"
|
||||
);
|
||||
$this->assertEquals(array(
|
||||
date_create('+1day'),
|
||||
date_create('+2day')
|
||||
// get rid of microseconds for PHP 7.1+
|
||||
date_create(date_create('+1day')->format('Y-m-d H:i:s')),
|
||||
date_create(date_create('+2day')->format('Y-m-d H:i:s'))
|
||||
), $rset->getOccurrences());
|
||||
|
||||
$rset = new RSet(
|
||||
|
Loading…
x
Reference in New Issue
Block a user