2012-06-03 14:19:28 -04:00
|
|
|
<?php
|
|
|
|
|
2012-08-11 04:07:19 -04:00
|
|
|
namespace Sabre\VObject\Property;
|
|
|
|
|
|
|
|
class MultiDateTimeTest extends \PHPUnit_Framework_TestCase {
|
2012-06-03 14:19:28 -04:00
|
|
|
|
|
|
|
function testSetDateTime() {
|
|
|
|
|
2012-08-11 04:07:19 -04:00
|
|
|
$tz = new \DateTimeZone('Europe/Amsterdam');
|
|
|
|
$dt1 = new \DateTime('1985-07-04 01:30:00', $tz);
|
|
|
|
$dt2 = new \DateTime('1986-07-04 01:30:00', $tz);
|
2012-06-03 14:19:28 -04:00
|
|
|
$dt1->setTimeZone($tz);
|
|
|
|
$dt2->setTimeZone($tz);
|
|
|
|
|
2012-08-11 04:07:19 -04:00
|
|
|
$elem = new MultiDateTime('DTSTART');
|
2012-06-03 14:19:28 -04:00
|
|
|
$elem->setDateTimes(array($dt1,$dt2));
|
|
|
|
|
|
|
|
$this->assertEquals('19850704T013000,19860704T013000', $elem->value);
|
|
|
|
$this->assertEquals('Europe/Amsterdam', (string)$elem['TZID']);
|
|
|
|
$this->assertEquals('DATE-TIME', (string)$elem['VALUE']);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function testSetDateTimeLOCAL() {
|
|
|
|
|
2012-08-11 04:07:19 -04:00
|
|
|
$tz = new \DateTimeZone('Europe/Amsterdam');
|
|
|
|
$dt1 = new \DateTime('1985-07-04 01:30:00', $tz);
|
|
|
|
$dt2 = new \DateTime('1986-07-04 01:30:00', $tz);
|
2012-06-03 14:19:28 -04:00
|
|
|
$dt1->setTimeZone($tz);
|
|
|
|
$dt2->setTimeZone($tz);
|
|
|
|
|
2012-08-11 04:07:19 -04:00
|
|
|
$elem = new MultiDateTime('DTSTART');
|
|
|
|
$elem->setDateTimes(array($dt1,$dt2), DateTime::LOCAL);
|
2012-06-03 14:19:28 -04:00
|
|
|
|
|
|
|
$this->assertEquals('19850704T013000,19860704T013000', $elem->value);
|
|
|
|
$this->assertNull($elem['TZID']);
|
|
|
|
$this->assertEquals('DATE-TIME', (string)$elem['VALUE']);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function testSetDateTimeUTC() {
|
|
|
|
|
2012-08-11 04:07:19 -04:00
|
|
|
$tz = new \DateTimeZone('GMT');
|
|
|
|
$dt1 = new \DateTime('1985-07-04 01:30:00', $tz);
|
|
|
|
$dt2 = new \DateTime('1986-07-04 01:30:00', $tz);
|
2012-06-03 14:19:28 -04:00
|
|
|
$dt1->setTimeZone($tz);
|
|
|
|
$dt2->setTimeZone($tz);
|
|
|
|
|
2012-08-11 04:07:19 -04:00
|
|
|
$elem = new MultiDateTime('DTSTART');
|
|
|
|
$elem->setDateTimes(array($dt1,$dt2), DateTime::UTC);
|
2012-06-03 14:19:28 -04:00
|
|
|
|
|
|
|
$this->assertEquals('19850704T013000Z,19860704T013000Z', $elem->value);
|
|
|
|
$this->assertNull($elem['TZID']);
|
|
|
|
$this->assertEquals('DATE-TIME', (string)$elem['VALUE']);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function testSetDateTimeLOCALTZ() {
|
|
|
|
|
2012-08-11 04:07:19 -04:00
|
|
|
$tz = new \DateTimeZone('Europe/Amsterdam');
|
|
|
|
$dt1 = new \DateTime('1985-07-04 01:30:00', $tz);
|
|
|
|
$dt2 = new \DateTime('1986-07-04 01:30:00', $tz);
|
2012-06-03 14:19:28 -04:00
|
|
|
$dt1->setTimeZone($tz);
|
|
|
|
$dt2->setTimeZone($tz);
|
|
|
|
|
2012-08-11 04:07:19 -04:00
|
|
|
$elem = new MultiDateTime('DTSTART');
|
|
|
|
$elem->setDateTimes(array($dt1,$dt2), DateTime::LOCALTZ);
|
2012-06-03 14:19:28 -04:00
|
|
|
|
|
|
|
$this->assertEquals('19850704T013000,19860704T013000', $elem->value);
|
|
|
|
$this->assertEquals('Europe/Amsterdam', (string)$elem['TZID']);
|
|
|
|
$this->assertEquals('DATE-TIME', (string)$elem['VALUE']);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function testSetDateTimeDATE() {
|
|
|
|
|
2012-08-11 04:07:19 -04:00
|
|
|
$tz = new \DateTimeZone('Europe/Amsterdam');
|
|
|
|
$dt1 = new \DateTime('1985-07-04 01:30:00', $tz);
|
|
|
|
$dt2 = new \DateTime('1986-07-04 01:30:00', $tz);
|
2012-06-03 14:19:28 -04:00
|
|
|
$dt1->settimezone($tz);
|
|
|
|
$dt2->settimezone($tz);
|
|
|
|
|
2012-08-11 04:07:19 -04:00
|
|
|
$elem = new MultiDateTime('DTSTART');
|
|
|
|
$elem->setDateTimes(array($dt1,$dt2), DateTime::DATE);
|
2012-06-03 14:19:28 -04:00
|
|
|
|
|
|
|
$this->assertEquals('19850704,19860704', $elem->value);
|
|
|
|
$this->assertNull($elem['TZID']);
|
|
|
|
$this->assertEquals('DATE', (string)$elem['VALUE']);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException InvalidArgumentException
|
|
|
|
*/
|
|
|
|
function testSetDateTimeInvalid() {
|
|
|
|
|
2012-08-11 04:07:19 -04:00
|
|
|
$tz = new \DateTimeZone('Europe/Amsterdam');
|
|
|
|
$dt = new \DateTime('1985-07-04 01:30:00', $tz);
|
2012-06-03 14:19:28 -04:00
|
|
|
$dt->setTimeZone($tz);
|
|
|
|
|
2012-08-11 04:07:19 -04:00
|
|
|
$elem = new MultiDateTime('DTSTART');
|
2012-06-03 14:19:28 -04:00
|
|
|
$elem->setDateTimes(array($dt), 7);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function testGetDateTimeCached() {
|
|
|
|
|
2012-08-11 04:07:19 -04:00
|
|
|
$tz = new \DateTimeZone('Europe/Amsterdam');
|
|
|
|
$dt1 = new \DateTime('1985-07-04 01:30:00', $tz);
|
|
|
|
$dt2 = new \DateTime('1986-07-04 01:30:00', $tz);
|
2012-06-03 14:19:28 -04:00
|
|
|
$dt1->settimezone($tz);
|
|
|
|
$dt2->settimezone($tz);
|
|
|
|
|
2012-08-11 04:07:19 -04:00
|
|
|
$elem = new MultiDateTime('DTSTART');
|
2012-06-03 14:19:28 -04:00
|
|
|
$elem->setDateTimes(array($dt1,$dt2));
|
|
|
|
|
|
|
|
$this->assertEquals($elem->getDateTimes(), array($dt1,$dt2));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function testGetDateTimeDateNULL() {
|
|
|
|
|
2012-08-11 04:07:19 -04:00
|
|
|
$elem = new MultiDateTime('DTSTART');
|
2012-06-03 14:19:28 -04:00
|
|
|
$dt = $elem->getDateTimes();
|
|
|
|
|
|
|
|
$this->assertNull($dt);
|
|
|
|
$this->assertNull($elem->getDateType());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function testGetDateTimeDateDATE() {
|
|
|
|
|
2012-08-11 04:07:19 -04:00
|
|
|
$elem = new MultiDateTime('DTSTART','19850704,19860704');
|
2012-06-03 14:19:28 -04:00
|
|
|
$dt = $elem->getDateTimes();
|
|
|
|
|
|
|
|
$this->assertEquals('1985-07-04 00:00:00', $dt[0]->format('Y-m-d H:i:s'));
|
|
|
|
$this->assertEquals('1986-07-04 00:00:00', $dt[1]->format('Y-m-d H:i:s'));
|
2012-08-11 04:07:19 -04:00
|
|
|
$this->assertEquals(DateTime::DATE, $elem->getDateType());
|
2012-06-03 14:19:28 -04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function testGetDateTimeDateDATEReverse() {
|
|
|
|
|
2012-08-11 04:07:19 -04:00
|
|
|
$elem = new MultiDateTime('DTSTART','19850704,19860704');
|
2012-06-03 14:19:28 -04:00
|
|
|
|
2012-08-11 04:07:19 -04:00
|
|
|
$this->assertEquals(DateTime::DATE, $elem->getDateType());
|
2012-06-03 14:19:28 -04:00
|
|
|
|
|
|
|
$dt = $elem->getDateTimes();
|
|
|
|
$this->assertEquals('1985-07-04 00:00:00', $dt[0]->format('Y-m-d H:i:s'));
|
|
|
|
$this->assertEquals('1986-07-04 00:00:00', $dt[1]->format('Y-m-d H:i:s'));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function testGetDateTimeDateLOCAL() {
|
|
|
|
|
2012-08-11 04:07:19 -04:00
|
|
|
$elem = new DateTime('DTSTART','19850704T013000');
|
2012-06-03 14:19:28 -04:00
|
|
|
$dt = $elem->getDateTime();
|
|
|
|
|
|
|
|
$this->assertInstanceOf('DateTime', $dt);
|
|
|
|
$this->assertEquals('1985-07-04 01:30:00', $dt->format('Y-m-d H:i:s'));
|
2012-08-11 04:07:19 -04:00
|
|
|
$this->assertEquals(DateTime::LOCAL, $elem->getDateType());
|
2012-06-03 14:19:28 -04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function testGetDateTimeDateUTC() {
|
|
|
|
|
2012-08-11 04:07:19 -04:00
|
|
|
$elem = new DateTime('DTSTART','19850704T013000Z');
|
2012-06-03 14:19:28 -04:00
|
|
|
$dt = $elem->getDateTime();
|
|
|
|
|
|
|
|
$this->assertInstanceOf('DateTime', $dt);
|
|
|
|
$this->assertEquals('1985-07-04 01:30:00', $dt->format('Y-m-d H:i:s'));
|
|
|
|
$this->assertEquals('UTC', $dt->getTimeZone()->getName());
|
2012-08-11 04:07:19 -04:00
|
|
|
$this->assertEquals(DateTime::UTC, $elem->getDateType());
|
2012-06-03 14:19:28 -04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function testGetDateTimeDateLOCALTZ() {
|
|
|
|
|
2012-08-11 04:07:19 -04:00
|
|
|
$elem = new DateTime('DTSTART','19850704T013000');
|
2012-06-03 14:19:28 -04:00
|
|
|
$elem['TZID'] = 'Europe/Amsterdam';
|
|
|
|
|
|
|
|
$dt = $elem->getDateTime();
|
|
|
|
|
|
|
|
$this->assertInstanceOf('DateTime', $dt);
|
|
|
|
$this->assertEquals('1985-07-04 01:30:00', $dt->format('Y-m-d H:i:s'));
|
|
|
|
$this->assertEquals('Europe/Amsterdam', $dt->getTimeZone()->getName());
|
2012-08-11 04:07:19 -04:00
|
|
|
$this->assertEquals(DateTime::LOCALTZ, $elem->getDateType());
|
2012-06-03 14:19:28 -04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException InvalidArgumentException
|
|
|
|
*/
|
|
|
|
function testGetDateTimeDateInvalid() {
|
|
|
|
|
2012-08-11 04:07:19 -04:00
|
|
|
$elem = new DateTime('DTSTART','bla');
|
2012-06-03 14:19:28 -04:00
|
|
|
$dt = $elem->getDateTime();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|