public function testCopyEnsureTzIsCopied() { $dating = Date::createFromDate(2000, 1, 1, 'Europe/London'); $dating2 = $dating->copy(); $this->assertSame($dating->getTimezoneName(), $dating2->getTimezoneName()); $this->assertSame($dating->getOffset(), $dating2->getOffset()); }
public function testAddDayPassingArg() { $this->assertSame(12, Date::createFromDate(1975, 5, 10)->addDay(2)->getDay()); }
/** * @expectedException \InvalidArgumentException */ public function testCreateWithInvalidTimezoneOffset() { Date::createFromDate(2000, 1, 1, 'Mars/Somewhere'); }
public function testGetTimezoneName() { $dt = Date::createFromDate(2000, 1, 1, 'America/Toronto'); $this->assertSame('America/Toronto', $dt->getTimezoneName()); $dt = Date::createFromDate(2000, 1, 1, -5); $this->assertSame('-05:00', $dt->getTimezoneName()); }
public function testDaySetterWithWrap() { $d = Date::createFromDate(2012, 8, 5)->day(32); $this->assertSame(1, $d->getDay()); }
public function testFluidSetTime() { $d = Date::createFromDate(2000, 1, 1)->setTime(25, 61, 61); $this->assertTrue($d instanceof Date); $this->assertDate($d, 2000, 1, 2, 2, 2, 1); }
public function test3rdWednesdayOfYear() { $d = Date::createFromDate(1975, 8, 5)->nthOfYear(3, 3); $this->assertDate($d, 1975, 1, 15, 0, 0, 0); }
public function testIsBirthday() { $dt = Date::now(); $aBirthday = $dt->subYear(); $this->assertTrue($aBirthday->isBirthday()); $notABirthday = $dt->subDay(); $this->assertFalse($notABirthday->isBirthday()); $alsoNotABirthday = $dt->addDays(2); $this->assertFalse($alsoNotABirthday->isBirthday()); $dt1 = Date::createFromDate(1987, 4, 23); $dt2 = Date::createFromDate(2014, 9, 26); $dt3 = Date::createFromDate(2014, 4, 23); $this->assertFalse($dt2->isBirthday($dt1)); $this->assertTrue($dt3->isBirthday($dt1)); }
public function testDiffInSecondsWithTimezones() { $dtOttawa = Date::createFromDate(2000, 1, 1, 'America/Toronto'); $dtVancouver = Date::createFromDate(2000, 1, 1, 'America/Vancouver'); $this->assertSame(3 * 60 * 60, $dtOttawa->diffInSeconds($dtVancouver)); }
public function testIsSaturday() { // True in the past past $this->assertTrue(Date::createFromDate(2015, 6, 6)->isSaturday()); $this->assertTrue(Date::now()->subWeek()->previous(Date::SATURDAY)->isSaturday()); // True in the future $this->assertTrue(Date::now()->addWeek()->previous(Date::SATURDAY)->isSaturday()); $this->assertTrue(Date::now()->addMonth()->previous(Date::SATURDAY)->isSaturday()); // False in the past $this->assertFalse(Date::now()->subWeek()->previous(Date::SUNDAY)->isSaturday()); $this->assertFalse(Date::now()->subMonth()->previous(Date::SUNDAY)->isSaturday()); // False in the future $this->assertFalse(Date::now()->addWeek()->previous(Date::SUNDAY)->isSaturday()); $this->assertFalse(Date::now()->addMonth()->previous(Date::SUNDAY)->isSaturday()); }
public function testCreateFromDateWithDateTimeZone() { $d = Date::createFromDate(1975, 5, 21, new \DateTimeZone('Europe/London')); $this->assertDate($d, 1975, 5, 21); $this->assertSame('Europe/London', $d->getTimezoneName()); }