Example #1
0
 /**
  * {@inheritdoc}
  */
 public function expand($className, $value, array $options = [])
 {
     try {
         switch ($className) {
             case Duration::class:
                 return Duration::parse($value);
             case LocalDate::class:
                 return LocalDate::parse($value);
             case LocalTime::class:
                 return LocalTime::parse($value);
             case LocalDateTime::class:
                 return LocalDateTime::parse($value);
             case TimeZoneOffset::class:
                 return TimeZoneOffset::parse($value);
             case TimeZoneRegion::class:
                 return TimeZoneRegion::parse($value);
             case YearMonth::class:
                 return YearMonth::parse($value);
             case ZonedDateTime::class:
                 return ZonedDateTime::parse($value);
         }
     } catch (DateTimeParseException $e) {
         throw new ObjectNotConvertibleException($e->getMessage(), $e->getCode(), $e);
     }
     return null;
 }
Example #2
0
 /**
  * @return string
  */
 public function __toString()
 {
     return (string) ZonedDateTime::ofInstant($this, TimeZone::utc());
 }
Example #3
0
 /**
  * Returns a zoned date-time formed from this date-time and the specified time-zone.
  *
  * @param TimeZone $zone The zime-zone to use.
  *
  * @return ZonedDateTime The zoned date-time formed from this date-time.
  */
 public function atTimeZone(TimeZone $zone)
 {
     return ZonedDateTime::of($this, $zone);
 }
Example #4
0
 public function testChangeTimeZone()
 {
     $timezone1 = TimeZone::parse('UTC');
     $timezone2 = TimeZone::parse('America/Los_Angeles');
     $datetime1 = ZonedDateTime::ofInstant(Instant::of(1000000000), $timezone1);
     $datetime2 = $datetime1->withTimeZoneSameInstant($timezone2);
     $this->assertSame($timezone1, $datetime1->getTimezone());
     $this->assertSame($timezone2, $datetime2->getTimezone());
     $this->assertSame('2001-09-08T18:46:40', (string) $datetime2->getDateTime());
     $datetime2 = $datetime1->withTimeZoneSameLocal($timezone2);
     $this->assertSame($timezone1, $datetime1->getTimezone());
     $this->assertSame($timezone2, $datetime2->getTimezone());
     $this->assertSame('2001-09-09T01:46:40', (string) $datetime2->getDateTime());
 }
Example #5
0
 /**
  * Returns the current date, in the given time zone.
  *
  * @param TimeZone $timeZone
  *
  * @return LocalDate
  */
 public static function now(TimeZone $timeZone)
 {
     return ZonedDateTime::now($timeZone)->getDate();
 }
Example #6
0
 /**
  * Returns a copy of this ZonedDateTime with the specified period in seconds added.
  *
  * @param integer $seconds
  *
  * @return ZonedDateTime
  */
 public function plusSeconds($seconds)
 {
     return ZonedDateTime::of($this->localDateTime->plusSeconds($seconds), $this->timeZone);
 }