public function testResetToStringFormat() { $d = Date::now(); Date::setToStringFormat('123'); Date::resetToStringFormat(); $this->assertSame($d->toDateTimeString(), '' . $d); }
public function testParseCreatesAnInstanceDefaultToNow() { $c = Date::parse(); $now = Date::now(); $this->assertInstanceOfDate($c); $this->assertSame($now->getTimezoneName(), $c->getTimezoneName()); $this->assertDate($c, $now->getYear(), $now->getMonth(), $now->getDay(), $now->getHour(), $now->getMinute(), $now->getSecond()); }
public function testDiffForHumansLocalizedInPortugueseBrazilBC() { Date::setLocale('pt_BR'); $scope = $this; $this->wrapWithTestNow(function () use($scope) { $d = Date::now()->subSecond(); $scope->assertSame('há 1 segundo', $d->diffForHumans()); }); }
public function testDiffForHumansLocalizedInItalian() { Date::setLocale('it'); $scope = $this; $this->wrapWithTestNow(function () use($scope) { $d = Date::now()->addYear(); $scope->assertSame('1 anno da adesso', $d->diffForHumans()); $d = Date::now()->addYears(2); $scope->assertSame('2 anni da adesso', $d->diffForHumans()); }); }
public function testDiffForHumansLocalizedInKorean() { Date::setLocale('ko'); $scope = $this; $this->wrapWithTestNow(function () use($scope) { $d = Date::now()->addYear(); $scope->assertSame('1 년 후', $d->diffForHumans()); $d = Date::now()->addYears(2); $scope->assertSame('2 년 후', $d->diffForHumans()); }); }
public function testDiffForHumansLocalizedInLithuanian() { Date::setLocale('lt'); $scope = $this; $this->wrapWithTestNow(function () use($scope) { $d = Date::now()->addYear(); $scope->assertSame('už 1 metus', $d->diffForHumans()); $d = Date::now()->addYears(2); $scope->assertSame('už 2 metus', $d->diffForHumans()); }); }
public function testDiffForHumansLocalizedInFarsi() { Date::setLocale('fa'); $scope = $this; $this->wrapWithTestNow(function () use($scope) { $d = Date::now()->subSecond(); $scope->assertSame('1 ثانیه پیش', $d->diffForHumans()); $d = Date::now()->subSeconds(2); $scope->assertSame('2 ثانیه پیش', $d->diffForHumans()); $d = Date::now()->subMinute(); $scope->assertSame('1 دقیقه پیش', $d->diffForHumans()); $d = Date::now()->subMinutes(2); $scope->assertSame('2 دقیقه پیش', $d->diffForHumans()); $d = Date::now()->subHour(); $scope->assertSame('1 ساعت پیش', $d->diffForHumans()); $d = Date::now()->subHours(2); $scope->assertSame('2 ساعت پیش', $d->diffForHumans()); $d = Date::now()->subDay(); $scope->assertSame('1 روز پیش', $d->diffForHumans()); $d = Date::now()->subDays(2); $scope->assertSame('2 روز پیش', $d->diffForHumans()); $d = Date::now()->subWeek(); $scope->assertSame('1 هفته پیش', $d->diffForHumans()); $d = Date::now()->subWeeks(2); $scope->assertSame('2 هفته پیش', $d->diffForHumans()); $d = Date::now()->subMonth(); $scope->assertSame('1 ماه پیش', $d->diffForHumans()); $d = Date::now()->subMonths(2); $scope->assertSame('2 ماه پیش', $d->diffForHumans()); $d = Date::now()->subYear(); $scope->assertSame('1 سال پیش', $d->diffForHumans()); $d = Date::now()->subYears(2); $scope->assertSame('2 سال پیش', $d->diffForHumans()); $d = Date::now()->addSecond(); $scope->assertSame('1 ثانیه بعد', $d->diffForHumans()); $d = Date::now()->addSecond(); $d2 = Date::now(); $scope->assertSame('1 ثانیه پیش از', $d->diffForHumans($d2)); $scope->assertSame('1 ثانیه پس از', $d2->diffForHumans($d)); $d = Date::now()->addSecond(); $d2 = Date::now(); $scope->assertSame('1 ثانیه پیش از', $d->diffForHumans($d2)); $scope->assertSame('1 ثانیه پس از', $d2->diffForHumans($d)); $scope->assertSame('1 ثانیه', $d->diffForHumans($d2, true)); $scope->assertSame('2 ثانیه', $d2->diffForHumans($d->addSecond(), true)); }); }
public function testDiffForHumansLocalizedInFaroese() { Date::setLocale('fo'); $scope = $this; $this->wrapWithTestNow(function () use($scope) { $d = Date::now()->subSecond(); $scope->assertSame('1 sekund síðan', $d->diffForHumans()); $d = Date::now()->subSeconds(2); $scope->assertSame('2 sekundir síðan', $d->diffForHumans()); $d = Date::now()->subMinute(); $scope->assertSame('1 minutt síðan', $d->diffForHumans()); $d = Date::now()->subMinutes(2); $scope->assertSame('2 minuttir síðan', $d->diffForHumans()); $d = Date::now()->subHour(); $scope->assertSame('1 tími síðan', $d->diffForHumans()); $d = Date::now()->subHours(2); $scope->assertSame('2 tímar síðan', $d->diffForHumans()); $d = Date::now()->subDay(); $scope->assertSame('1 dag síðan', $d->diffForHumans()); $d = Date::now()->subDays(2); $scope->assertSame('2 dagar síðan', $d->diffForHumans()); $d = Date::now()->subWeek(); $scope->assertSame('1 vika síðan', $d->diffForHumans()); $d = Date::now()->subWeeks(2); $scope->assertSame('2 vikur síðan', $d->diffForHumans()); $d = Date::now()->subMonth(); $scope->assertSame('1 mánaður síðan', $d->diffForHumans()); $d = Date::now()->subMonths(2); $scope->assertSame('2 mánaðir síðan', $d->diffForHumans()); $d = Date::now()->subYear(); $scope->assertSame('1 ár síðan', $d->diffForHumans()); $d = Date::now()->subYears(2); $scope->assertSame('2 ár síðan', $d->diffForHumans()); $d = Date::now()->addSecond(); $scope->assertSame('um 1 sekund', $d->diffForHumans()); $d = Date::now()->addSecond(); $d2 = Date::now(); $scope->assertSame('1 sekund aftaná', $d->diffForHumans($d2)); $scope->assertSame('1 sekund áðrenn', $d2->diffForHumans($d)); $scope->assertSame('1 sekund', $d->diffForHumans($d2, true)); $scope->assertSame('2 sekundir', $d2->diffForHumans($d->addSecond(), true)); }); }
public function testDiffForHumansLocalizedInFrench() { Date::setLocale('fr'); $scope = $this; $this->wrapWithTestNow(function () use($scope) { $d = Date::now()->subSecond(); $scope->assertSame('il y a 1 seconde', $d->diffForHumans()); $d = Date::now()->subSeconds(2); $scope->assertSame('il y a 2 secondes', $d->diffForHumans()); $d = Date::now()->subMinute(); $scope->assertSame('il y a 1 minute', $d->diffForHumans()); $d = Date::now()->subMinutes(2); $scope->assertSame('il y a 2 minutes', $d->diffForHumans()); $d = Date::now()->subHour(); $scope->assertSame('il y a 1 heure', $d->diffForHumans()); $d = Date::now()->subHours(2); $scope->assertSame('il y a 2 heures', $d->diffForHumans()); $d = Date::now()->subDay(); $scope->assertSame('il y a 1 jour', $d->diffForHumans()); $d = Date::now()->subDays(2); $scope->assertSame('il y a 2 jours', $d->diffForHumans()); $d = Date::now()->subWeek(); $scope->assertSame('il y a 1 semaine', $d->diffForHumans()); $d = Date::now()->subWeeks(2); $scope->assertSame('il y a 2 semaines', $d->diffForHumans()); $d = Date::now()->subMonth(); $scope->assertSame('il y a 1 mois', $d->diffForHumans()); $d = Date::now()->subMonths(2); $scope->assertSame('il y a 2 mois', $d->diffForHumans()); $d = Date::now()->subYear(); $scope->assertSame('il y a 1 an', $d->diffForHumans()); $d = Date::now()->subYears(2); $scope->assertSame('il y a 2 ans', $d->diffForHumans()); $d = Date::now()->addSecond(); $scope->assertSame('dans 1 seconde', $d->diffForHumans()); $d = Date::now()->addSecond(); $d2 = Date::now(); $scope->assertSame('1 seconde après', $d->diffForHumans($d2)); $scope->assertSame('1 seconde avant', $d2->diffForHumans($d)); $scope->assertSame('1 seconde', $d->diffForHumans($d2, true)); $scope->assertSame('2 secondes', $d2->diffForHumans($d->addSecond(), true)); }); }
public function testDiffForHumansLocalizedInTurkish() { Date::setLocale('tr'); $scope = $this; $this->wrapWithTestNow(function () use($scope) { $d = Date::now()->subSecond(); $scope->assertSame('1 saniye önce', $d->diffForHumans()); $d = Date::now()->subSeconds(2); $scope->assertSame('2 saniye önce', $d->diffForHumans()); $d = Date::now()->subMinute(); $scope->assertSame('1 dakika önce', $d->diffForHumans()); $d = Date::now()->subMinutes(2); $scope->assertSame('2 dakika önce', $d->diffForHumans()); $d = Date::now()->subHour(); $scope->assertSame('1 saat önce', $d->diffForHumans()); $d = Date::now()->subHours(2); $scope->assertSame('2 saat önce', $d->diffForHumans()); $d = Date::now()->subDay(); $scope->assertSame('1 gün önce', $d->diffForHumans()); $d = Date::now()->subDays(2); $scope->assertSame('2 gün önce', $d->diffForHumans()); $d = Date::now()->subWeek(); $scope->assertSame('1 hafta önce', $d->diffForHumans()); $d = Date::now()->subWeeks(2); $scope->assertSame('2 hafta önce', $d->diffForHumans()); $d = Date::now()->subMonth(); $scope->assertSame('1 ay önce', $d->diffForHumans()); $d = Date::now()->subMonths(2); $scope->assertSame('2 ay önce', $d->diffForHumans()); $d = Date::now()->subYear(); $scope->assertSame('1 yıl önce', $d->diffForHumans()); $d = Date::now()->subYears(2); $scope->assertSame('2 yıl önce', $d->diffForHumans()); $d = Date::now()->addSecond(); $scope->assertSame('1 saniye andan itibaren', $d->diffForHumans()); $d = Date::now()->addSecond(); $d2 = Date::now(); $scope->assertSame('1 saniye sonra', $d->diffForHumans($d2)); $scope->assertSame('1 saniye önce', $d2->diffForHumans($d)); $scope->assertSame('1 saniye', $d->diffForHumans($d2, true)); $scope->assertSame('2 saniye', $d2->diffForHumans($d->addSecond(), true)); }); }
public function testDiffForHumansLocalizedInJapanese() { Date::setLocale('ja'); $scope = $this; $this->wrapWithTestNow(function () use($scope) { $d = Date::now()->subSecond(); $scope->assertSame('1 秒 前', $d->diffForHumans()); $d = Date::now()->subSeconds(2); $scope->assertSame('2 秒 前', $d->diffForHumans()); $d = Date::now()->subMinute(); $scope->assertSame('1 分 前', $d->diffForHumans()); $d = Date::now()->subMinutes(2); $scope->assertSame('2 分 前', $d->diffForHumans()); $d = Date::now()->subHour(); $scope->assertSame('1 時間 前', $d->diffForHumans()); $d = Date::now()->subHours(2); $scope->assertSame('2 時間 前', $d->diffForHumans()); $d = Date::now()->subDay(); $scope->assertSame('1 日 前', $d->diffForHumans()); $d = Date::now()->subDays(2); $scope->assertSame('2 日 前', $d->diffForHumans()); $d = Date::now()->subWeek(); $scope->assertSame('1 週間 前', $d->diffForHumans()); $d = Date::now()->subWeeks(2); $scope->assertSame('2 週間 前', $d->diffForHumans()); $d = Date::now()->subMonth(); $scope->assertSame('1 ヶ月 前', $d->diffForHumans()); $d = Date::now()->subMonths(2); $scope->assertSame('2 ヶ月 前', $d->diffForHumans()); $d = Date::now()->subYear(); $scope->assertSame('1 年 前', $d->diffForHumans()); $d = Date::now()->subYears(2); $scope->assertSame('2 年 前', $d->diffForHumans()); $d = Date::now()->addSecond(); $scope->assertSame('今から 1 秒', $d->diffForHumans()); $d = Date::now()->addSecond(); $d2 = Date::now(); $scope->assertSame('1 秒 後', $d->diffForHumans($d2)); $scope->assertSame('1 秒 前', $d2->diffForHumans($d)); $scope->assertSame('1 秒', $d->diffForHumans($d2, true)); $scope->assertSame('2 秒', $d2->diffForHumans($d->addSecond(), true)); }); }
public function testDiffForHumansLocalizedInDanish() { Date::setLocale('da'); $scope = $this; $this->wrapWithTestNow(function () use($scope) { $d = Date::now()->subSecond(); $scope->assertSame('1 sekund siden', $d->diffForHumans()); $d = Date::now()->subSeconds(2); $scope->assertSame('2 sekunder siden', $d->diffForHumans()); $d = Date::now()->subMinute(); $scope->assertSame('1 minut siden', $d->diffForHumans()); $d = Date::now()->subMinutes(2); $scope->assertSame('2 minutter siden', $d->diffForHumans()); $d = Date::now()->subHour(); $scope->assertSame('1 time siden', $d->diffForHumans()); $d = Date::now()->subHours(2); $scope->assertSame('2 timer siden', $d->diffForHumans()); $d = Date::now()->subDay(); $scope->assertSame('1 dag siden', $d->diffForHumans()); $d = Date::now()->subDays(2); $scope->assertSame('2 dage siden', $d->diffForHumans()); $d = Date::now()->subWeek(); $scope->assertSame('1 uge siden', $d->diffForHumans()); $d = Date::now()->subWeeks(2); $scope->assertSame('2 uger siden', $d->diffForHumans()); $d = Date::now()->subMonth(); $scope->assertSame('1 måned siden', $d->diffForHumans()); $d = Date::now()->subMonths(2); $scope->assertSame('2 måneder siden', $d->diffForHumans()); $d = Date::now()->subYear(); $scope->assertSame('1 år siden', $d->diffForHumans()); $d = Date::now()->subYears(2); $scope->assertSame('2 år siden', $d->diffForHumans()); $d = Date::now()->addSecond(); $scope->assertSame('om 1 sekund', $d->diffForHumans()); $d = Date::now()->addSecond(); $d2 = Date::now(); $scope->assertSame('1 sekund efter', $d->diffForHumans($d2)); $scope->assertSame('1 sekund før', $d2->diffForHumans($d)); $scope->assertSame('1 sekund', $d->diffForHumans($d2, true)); $scope->assertSame('2 sekunder', $d2->diffForHumans($d->addSecond(), true)); }); }
public function testDiffForHumansLocalizedInSpanish() { Date::setLocale('es'); $scope = $this; $this->wrapWithTestNow(function () use($scope) { $d = Date::now()->subSecond(); $scope->assertSame('hace 1 segundo', $d->diffForHumans()); $d = Date::now()->subSeconds(3); $scope->assertSame('hace 3 segundos', $d->diffForHumans()); $d = Date::now()->subMinute(); $scope->assertSame('hace 1 minuto', $d->diffForHumans()); $d = Date::now()->subMinutes(2); $scope->assertSame('hace 2 minutos', $d->diffForHumans()); $d = Date::now()->subHour(); $scope->assertSame('hace 1 hora', $d->diffForHumans()); $d = Date::now()->subHours(2); $scope->assertSame('hace 2 horas', $d->diffForHumans()); $d = Date::now()->subDay(); $scope->assertSame('hace 1 día', $d->diffForHumans()); $d = Date::now()->subDays(2); $scope->assertSame('hace 2 días', $d->diffForHumans()); $d = Date::now()->subWeek(); $scope->assertSame('hace 1 semana', $d->diffForHumans()); $d = Date::now()->subWeeks(2); $scope->assertSame('hace 2 semanas', $d->diffForHumans()); $d = Date::now()->subMonth(); $scope->assertSame('hace 1 mes', $d->diffForHumans()); $d = Date::now()->subMonths(2); $scope->assertSame('hace 2 meses', $d->diffForHumans()); $d = Date::now()->subYear(); $scope->assertSame('hace 1 año', $d->diffForHumans()); $d = Date::now()->subYears(2); $scope->assertSame('hace 2 años', $d->diffForHumans()); $d = Date::now()->addSecond(); $scope->assertSame('dentro de 1 segundo', $d->diffForHumans()); $d = Date::now()->addSecond(); $d2 = Date::now(); $scope->assertSame('1 segundo después', $d->diffForHumans($d2)); $scope->assertSame('1 segundo antes', $d2->diffForHumans($d)); $scope->assertSame('1 segundo', $d->diffForHumans($d2, true)); $scope->assertSame('2 segundos', $d2->diffForHumans($d->addSecond(), true)); }); }
public function testDiffForHumansLocalizedInGerman() { Date::setLocale('de'); $scope = $this; $this->wrapWithTestNow(function () use($scope) { $d = Date::now()->addYear(); $scope->assertSame('in 1 Jahr', $d->diffForHumans()); $d = Date::now()->addYears(2); $scope->assertSame('in 2 Jahren', $d->diffForHumans()); $d = Date::now()->subYear(); $scope->assertSame('1 Jahr später', Date::now()->diffForHumans($d)); $d = Date::now()->subYears(2); $scope->assertSame('2 Jahre später', Date::now()->diffForHumans($d)); $d = Date::now()->addYear(); $scope->assertSame('1 Jahr zuvor', Date::now()->diffForHumans($d)); $d = Date::now()->addYears(2); $scope->assertSame('2 Jahre zuvor', Date::now()->diffForHumans($d)); $d = Date::now()->subYear(); $scope->assertSame('vor 1 Jahr', $d->diffForHumans()); $d = Date::now()->subYears(2); $scope->assertSame('vor 2 Jahren', $d->diffForHumans()); }); }
/** * @expectedException \InvalidArgumentException */ public function testInstanceWithDaysThrowsException() { Interval::instance(Date::now()->diff(Date::now()->addWeeks(3))); }
public function __construct(Date $day) { $this->created = Date::now(); $this->day = $day; }
protected function wrapWithTestNow(Closure $func, Date $dt = null) { Date::setTestNow($dt ?: Date::now()); $func(); Date::setTestNow(); }
public function testFluidTimestampSetter() { $d = Date::now()->timestamp(10); $this->assertTrue($d instanceof Date); $this->assertSame(10, $d->getTimestamp()); }
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 testNowWithTestValueSet() { $notNow = Date::yesterday(); Date::setTestNow($notNow); $this->assertEquals($notNow, Date::now()); }
public function testCopy() { $dating = Date::now(); $dating2 = $dating->copy(); $this->assertNotSame($dating, $dating2); }
public function testCreateFromTimeWithTimeZoneString() { $d = Date::createFromTime(12, 0, 0, 'Europe/London'); $this->assertDate($d, Date::now()->getYear(), Date::now()->getMonth(), Date::now()->getDay(), 12, 0, 0); $this->assertSame('Europe/London', $d->getTimezoneName()); }
public function testAddWithNegativeDiffInterval() { $diff = Date::now()->diff(Date::now()->subWeeks(3)); $ci = Interval::create(4, 3, 6, 7, 8, 10, 11)->add($diff); $this->assertInterval($ci, 4, 3, 28, 8, 10, 11); }
public function testSetTimeFromTimeString() { $d = Date::now(); $d = $d->setTimeFromTimeString('09:15:30'); $this->assertSame(9, $d->getHour()); $this->assertSame(15, $d->getMinute()); $this->assertSame(30, $d->getSecond()); }
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 testGetAge() { $d = Date::now(); $this->assertSame(0, $d->getAge()); }
public function testDiffForHumansAbsoluteYears() { $scope = $this; $this->wrapWithTestNow(function () use($scope) { $scope->assertSame('1 year', Date::now()->diffForHumans(Date::now()->subYears(1), true)); $scope->assertSame('1 year', Date::now()->diffForHumans(Date::now()->addYears(1), true)); }); }
public function testCreateWithDefaults() { $d = Date::create(); $this->assertSame($d->getTimestamp(), Date::now()->getTimestamp()); }
public function testNowWithTimezone() { $dt = Date::now('Europe/London'); $this->assertSame(time(), $dt->getTimestamp()); $this->assertSame('Europe/London', $dt->getTimezoneName()); }