public static function Parse( $datetime, \DateTimeZone $timezone = null )
   {

      if ( \is_null( $datetime ) )
      {
         // NULL returns FALSE
         return false;
      }

      if ( $datetime instanceof DateTime )
      {
         // Its already a \Beluga\DateTime => return it.
         return $datetime;
      }

      if ( $datetime instanceof \DateTimeInterface )
      {
         // \DateTime values can be handled directly without some other requirements.
         return new DateTime( $datetime->format( 'y-m-d H:i:s' ), $datetime->getTimezone() );
      }

      if ( is_array( $datetime ) || ( $datetime instanceof \stdClass ) )
      {
         return false;
      }

      if ( TypeTool::IsInteger( $datetime ) )
      {
         // Unix timestamp convert to DateTime string
         $datetime = \strftime( '%Y-%m-%d %H:%M:%S', \intval( $datetime ) );
      }
      else if ( ! \is_string( $datetime ) )
      {
         $type = new Type( $datetime );
         if ( ! $type->hasAssociatedString() )
         {
            // Not a string and not convertible to a string.
            return false;
         }
         // Getting the associated string value
         $datetime = $type->getStringValue();
      }

      // $datetime is a string now!

      try
      {
         $dt = new DateTime( $datetime, $timezone );
         return $dt;
      }
      catch ( \Throwable $ex )
      {
         $replacements = array( '1.', '2.', '3.', '4.', '5.', '6.', '7.', '8.', '9.', '10.', '11.', '12.' );
         $ex = null;
         // Replace all month names and short month names.
         $datetime = \preg_replace(
            static::$monthNamesShortRegex,
            $replacements,
            \preg_replace(
               static::$monthNamesLongRegex,
               $replacements,
               $datetime
            )
         );
         // Replace every thing that's not an [0-9.:+/ -]
         $datetime = \preg_replace( '~\s{2,}~', ' ', \preg_replace( '~[^0-9.:+/-]+~', ' ', $datetime ) );
      }

      try
      {
         $dt = new DateTime( \trim( $datetime ), $timezone );
         return $dt;
      }
      catch ( \Throwable $ex )
      {
         $ex = null;
         return false;
      }

   }
public static function Parse( $datetime, \DateTimeZone $timezone = null )
   {

      if ( \is_null( $datetime ) )
      {
         // NULL returns FALSE
         return false;
      }

      if ( $datetime instanceof DateTime )
      {
         // Its already a \Beluga\DateTime => return it.
         return $datetime;
      }

      if ( $datetime instanceof \DateTimeInterface )
      {
         // \DateTime values can be handled directly without some other requirements.
         return new DateTime( $datetime->format( 'y-m-d H:i:s' ), $datetime->getTimezone() );
      }

      if ( is_array( $datetime ) || ( $datetime instanceof \stdClass ) )
      {
         return false;
      }

      if ( TypeTool::IsInteger( $datetime ) )
      {
         // Unix timestamp convert to DateTime string
         $datetime = \strftime( '%Y-%m-%d %H:%M:%S', \intval( $datetime ) );
      }
      else if ( ! \is_string( $datetime ) )
      {
         $type = new Type( $datetime );
         if ( ! $type->hasAssociatedString() )
         {
            // Not a string and not convertible to a string.
            return false;
         }
         // Getting the associated string value
         $datetime = $type->getStringValue();
      }

      // $datetime is a string now!

      try
      {
         $dt = new DateTime( $datetime, $timezone );
         return $dt;
      }
      catch ( \Throwable $ex )
      {
         $replacements = array( '1.', '2.', '3.', '4.', '5.', '6.', '7.', '8.', '9.', '10.', '11.', '12.' );
         $ex = null;
         // Replace all month names and short month names.
         $datetime = \preg_replace(
            static::$monthNamesShortRegex,
            $replacements,
            \preg_replace(
               static::$monthNamesLongRegex,
               $replacements,
               $datetime
            )
         );
         // Replace every thing that's not an [0-9.:+/ -]
         $datetime = \preg_replace( '~\s{2,}~', ' ', \preg_replace( '~[^0-9.:+/-]+~', ' ', $datetime ) );
      }

      try
      {
         $dt = new DateTime( \trim( $datetime ), $timezone );
         return $dt;
      }
      catch ( \Throwable $ex )
      {
         $ex = null;
         return false;
      }

   }
public static function Parse ( $ datetime , \ DateTimeZone $ timezone = null ) { if ( \ is_null ( $ datetime ) ) { // NULL returns FALSE return false ; } if ( $ datetime instanceof DateTime ) { // Its already a \Beluga\DateTime => return it. return $ datetime ; } if ( $ datetime instanceof \ DateTimeInterface ) { // \DateTime values can be handled directly without some other requirements. return new DateTime ( $ datetime -> format ( 'y-m-d H:i:s' ) , $ datetime -> getTimezone ( ) ) ; } if ( is_array ( $ datetime ) || ( $ datetime instanceof \ stdClass ) ) { return false ; } if ( TypeTool :: IsInteger ( $ datetime ) ) { // Unix timestamp convert to DateTime string $ datetime = \ strftime ( '%Y-%m-%d %H:%M:%S' , \ intval ( $ datetime ) ) ; } else if ( ! \ is_string ( $ datetime ) ) { $ type = new Type ( $ datetime ) ; if ( ! $ type -> hasAssociatedString ( ) ) { // Not a string and not convertible to a string. return false ; } // Getting the associated string value $ datetime = $ type -> getStringValue ( ) ; } // $datetime is a string now! try { $ dt = new DateTime ( $ datetime , $ timezone ) ; return $ dt ; } catch ( \ Throwable $ ex ) { $ replacements = array ( '1.' , '2.' , '3.' , '4.' , '5.' , '6.' , '7.' , '8.' , '9.' , '10.' , '11.' , '12.' ) ; $ ex = null ; // Replace all month names and short month names. $ datetime = \ preg_replace ( static :: $ monthNamesShortRegex , $ replacements , \ preg_replace ( static :: $ monthNamesLongRegex , $ replacements , $ datetime ) ) ; // Replace every thing that's not an [0-9.:+/ -] $ datetime = \ preg_replace ( '~\s{2,}~' , ' ' , \ preg_replace ( '~[^0-9.:+/-]+~' , ' ' , $ datetime ) ) ; } try { $ dt = new DateTime ( \ trim ( $ datetime ) , $ timezone ) ; return $ dt ; } catch ( \ Throwable $ ex ) { $ ex = null ; return false ; } }
Parses a value to a \Beluga\Date\DateTime instance.

@param  mixed         $datetime The value to parse as DateTime. If can be a date(time) string, a unix timestamp
, a object of type \DateTime or something that can be converted, by a string
cast, to a valid date(time) string.
@param  \DateTimeZone $timezone An optional TimeZone
@return \Beluga\Date\DateTime|bool Returns the created \Beluga\Date\DateTime instance, or boolean FALSE if parsing fails.
Parses a value to a \ Beluga \ Date \ DateTime instance .