/**
  * {@inheritdoc}
  */
 public function reverseTransform($rfc3339)
 {
     if (!is_string($rfc3339)) {
         throw new TransformationFailedException('Expected a string.');
     }
     if ('' === $rfc3339) {
         return;
     }
     try {
         $dateTime = new Date($rfc3339);
     } catch (\Exception $e) {
         throw new TransformationFailedException($e->getMessage(), $e->getCode(), $e);
     }
     if ($this->outputTimezone !== $dateTime->getTimezone()->getName()) {
         try {
             $dateTime->setTimezone(new \DateTimeZone($this->inputTimezone));
         } catch (\Exception $e) {
             throw new TransformationFailedException($e->getMessage(), $e->getCode(), $e);
         }
     }
     if (preg_match('/(\\d{4})-(\\d{2})-(\\d{2})/', $rfc3339, $matches)) {
         if (!checkdate($matches[2], $matches[3], $matches[1])) {
             throw new TransformationFailedException(sprintf('The date "%s-%s-%s" is not a valid date.', $matches[1], $matches[2], $matches[3]));
         }
     }
     return $dateTime;
 }
Beispiel #2
0
 public function testCopyEnsureMicrosAreCopied()
 {
     $micro = 254687;
     $dating = Date::createFromFormat('Y-m-d H:i:s.u', '2014-02-01 03:45:27.' . $micro);
     $dating2 = $dating->copy();
     $this->assertSame($micro, $dating2->getMicro());
 }
Beispiel #3
0
 public function testInstanceFromDateTimeKeepsMicros()
 {
     $micro = 254687;
     $datetime = \DateTime::createFromFormat('Y-m-d H:i:s.u', '2014-02-01 03:45:27.' . $micro);
     $date = Date::instance($datetime);
     $this->assertSame($micro, $date->getMicro());
 }
Beispiel #4
0
 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());
     });
 }
Beispiel #5
0
 private function createAndPersistTestEntity()
 {
     Date::setTestNow(Date::create(2020, 01, 01, 12, 30, 20));
     $entity = new TestEntity(Date::create(1980, 04, 14, 13, 37));
     Date::setTestNow();
     $em = $this->doctrine->getManager();
     $em->persist($entity);
     $em->flush();
     $em->clear();
 }
Beispiel #6
0
 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());
     });
 }
Beispiel #7
0
 public function testSecondsUntilEndOfDay()
 {
     $d = Date::today()->endOfDay();
     $this->assertSame(0, $d->secondsUntilEndOfDay());
     $d = Date::today()->endOfDay()->subSeconds(60);
     $this->assertSame(60, $d->secondsUntilEndOfDay());
     $d = Date::create(2014, 10, 24, 12, 34, 56);
     $this->assertSame(41103, $d->secondsUntilEndOfDay());
     $d = Date::create(2014, 10, 24, 0, 0, 0);
     $this->assertSame(86399, $d->secondsUntilEndOfDay());
 }
Beispiel #8
0
 /**
  * {@inheritdoc}
  */
 public function convertToPHPValue($value, AbstractPlatform $platform)
 {
     if ($value === null || $value instanceof Date) {
         return $value;
     }
     $val = Date::createFromFormat($platform->getDateTimeFormatString(), $value);
     if (!$val) {
         throw ConversionException::conversionFailedFormat($value, $this->getName(), $platform->getDateTimeFormatString());
     }
     return $val;
 }
Beispiel #9
0
 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());
     });
 }
Beispiel #10
0
 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());
     });
 }
Beispiel #11
0
 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));
     });
 }
Beispiel #12
0
 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));
     });
 }
Beispiel #13
0
 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));
     });
 }
Beispiel #14
0
 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));
     });
 }
Beispiel #15
0
 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));
     });
 }
Beispiel #16
0
 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));
     });
 }
Beispiel #17
0
 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));
     });
 }
Beispiel #18
0
 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());
     });
 }
Beispiel #19
0
 /**
  * {@inheritdoc}
  *
  * @throws NotFoundHttpException When invalid date given
  */
 public function apply(Request $request, ParamConverter $configuration)
 {
     $param = $configuration->getName();
     if (!$request->attributes->has($param)) {
         return false;
     }
     $options = $configuration->getOptions();
     $value = $request->attributes->get($param);
     if (!$value && $configuration->isOptional()) {
         return false;
     }
     $invalidDateMessage = 'Invalid date given.';
     try {
         $date = isset($options['format']) ? Date::createFromFormat($options['format'], $value) : new Date($value);
     } catch (Exception $e) {
         throw new NotFoundHttpException($invalidDateMessage);
     }
     if (!$date) {
         throw new NotFoundHttpException($invalidDateMessage);
     }
     $request->attributes->set($param, $date);
     return true;
 }
Beispiel #20
0
 public function test3rdWednesdayOfYear()
 {
     $d = Date::createFromDate(1975, 8, 5)->nthOfYear(3, 3);
     $this->assertDate($d, 1975, 1, 15, 0, 0, 0);
 }
Beispiel #21
0
 public function testAddSecondPassingArg()
 {
     $this->assertSame(2, Date::createFromTime(0)->addSecond(2)->getSecond());
 }
Beispiel #22
0
 /**
  * @expectedException \InvalidArgumentException
  */
 public function testCreateWithInvalidTimezoneOffset()
 {
     Date::createFromDate(2000, 1, 1, 'Mars/Somewhere');
 }
Beispiel #23
0
 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);
 }
Beispiel #24
0
 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());
 }
Beispiel #25
0
 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());
 }
Beispiel #26
0
 public function testParseSettingTimezoneWithString()
 {
     $timezone = 'Asia/Tokyo';
     $dtz = new \DateTimeZone($timezone);
     $dt = new \DateTime('now', $dtz);
     $dayLightSavingTimeOffset = (int) $dt->format('I');
     $c = Date::parse('now', $timezone);
     $this->assertSame($timezone, $c->getTimezoneName());
     $this->assertSame(9 + $dayLightSavingTimeOffset, $c->getOffsetHours());
 }
Beispiel #27
0
 public function __construct(Date $day)
 {
     $this->created = Date::now();
     $this->day = $day;
 }
Beispiel #28
0
 protected function wrapWithTestNow(Closure $func, Date $dt = null)
 {
     Date::setTestNow($dt ?: Date::now());
     $func();
     Date::setTestNow();
 }
Beispiel #29
0
 public function testFluidTimestampSetter()
 {
     $d = Date::now()->timestamp(10);
     $this->assertTrue($d instanceof Date);
     $this->assertSame(10, $d->getTimestamp());
 }
Beispiel #30
0
 public function testFarthestWithEquals()
 {
     $instance = Date::create(2015, 5, 28, 12, 0, 0);
     $dt1 = Date::create(2015, 5, 28, 12, 0, 0);
     $dt2 = Date::create(2015, 5, 28, 14, 0, 0);
     $Farthest = $instance->farthest($dt1, $dt2);
     $this->assertEquals($dt2, $Farthest);
 }