fromNativeDateTimeZone() public static method

Returns a new Time from a native PHP \DateTime
public static fromNativeDateTimeZone ( DateTimeZone $timezone ) : self
$timezone DateTimeZone
return self
Beispiel #1
0
 public function testFromNativeDateTimeZone()
 {
     $nativeTimeZone = new \DateTimeZone('Europe/Madrid');
     $timeZoneFromNative = TimeZone::fromNativeDateTimeZone($nativeTimeZone);
     $constructedTimeZone = new TimeZone(new StringLiteral('Europe/Madrid'));
     $this->assertTrue($timeZoneFromNative->sameValueAs($constructedTimeZone));
 }
 /**
  * Returns a new DateTime from a native PHP \DateTime
  *
  * @param \DateTime $nativeDatetime
  *
  * @return DateTimeWithTimeZone
  */
 public static function fromNativeDateTime(\DateTime $nativeDatetime)
 {
     $datetime = DateTime::fromNativeDateTime($nativeDatetime);
     $timezone = TimeZone::fromNativeDateTimeZone($nativeDatetime->getTimezone());
     return new static($datetime, $timezone);
 }