/**
  * Get the datetime object, in site's time zone, if the datetime string was valid
  *
  * @todo This is messed up, output type changed, doc wrong. Revert, add new method for formatted. R.
  *
  * @param string $datetime_string The datetime string in UTC time zone, that needs to be converted to a DateTime object.
  * @param string $format          Date format to use.
  *
  * @return DateTime|null in site's time zone
  */
 public function get_datetime_with_timezone($datetime_string, $format = 'c')
 {
     static $utc_timezone, $local_timezone;
     if (!isset($utc_timezone)) {
         $utc_timezone = new DateTimeZone('UTC');
         $local_timezone = new DateTimeZone($this->get_timezone_string());
     }
     if (!empty($datetime_string) && WPSEO_Utils::is_valid_datetime($datetime_string)) {
         $datetime = new DateTime($datetime_string, $utc_timezone);
         $datetime->setTimezone($local_timezone);
         return $datetime->format($format);
     }
     return null;
 }
 /**
  * Get the datetime object is the datetime string was valid with a timezone
  *
  * @param string $datetime The datetime string that needs to be converted to a Datetime object
  *
  * @return DateTime|string
  */
 private function get_datetime_with_timezone($datetime)
 {
     if (!empty($datetime) && WPSEO_Utils::is_valid_datetime($datetime)) {
         return new DateTime($datetime, new DateTimeZone($this->get_timezone_string()));
     }
     return null;
 }
 /**
  * Wrapper function to check if we have a valid datetime (Uses a new util in WPSEO)
  *
  * @param string $datetime
  *
  * @return bool
  */
 private function is_valid_datetime($datetime)
 {
     if (method_exists('WPSEO_Utils', 'is_valid_datetime')) {
         return WPSEO_Utils::is_valid_datetime($datetime);
     }
     return true;
 }
 /**
  * Test the datetime with an invalid date string
  *
  * @covers WPSEO_Utils::is_valid_datetime
  */
 public function test_is_valid_datetime_WITH_invalid_datetime()
 {
     $this->assertFalse(WPSEO_Utils::is_valid_datetime('-0001-11-30T00:00:00+00:00'));
 }