private function dateTimeToTimePoint(DateTime $date)
    {
        // missing or offset only timezone? correct to UTC
        if (!$date->getTimezone() instanceof DateTimeZone || preg_match('#^[+-]{1}[0-9]{2}:?[0-9]{2}$#', $date->getTimezone()->getName())) {
            $date->setTimezone(new DateTimeZone('UTC'));
        }

        try {
            // DateTime::createFromFormat() will create an invalid DateTimeZone object when the timezone is an offset
            // (-05:00, for example) instead of a named timezone. By recreating the DateTimeZone object, we can expose
            // this problem and ensure that a valid DateTimeZone object is always set.
            $timezone = new DateTimeZone($date->getTimezone()->getName());
        } catch (Exception $e) {
            // @codeCoverageIgnoreStart
            $date->setTimezone(new DateTimeZone('UTC'));
            // @codeCoverageIgnoreEnd
        }

        return new TimePoint(
            (int) $date->format('Y'),
            (int) $date->format('m'),
            (int) $date->format('d'),
            (int) $date->format('H'),
            (int) $date->format('i'),
            (int) $date->format('s'),
            $date->getTimezone()->getName(),
            (int) $date->format('u')
        );
    }
private function dateTimeToTimePoint(DateTime $date)
    {
        // missing or offset only timezone? correct to UTC
        if (!$date->getTimezone() instanceof DateTimeZone || preg_match('#^[+-]{1}[0-9]{2}:?[0-9]{2}$#', $date->getTimezone()->getName())) {
            $date->setTimezone(new DateTimeZone('UTC'));
        }

        try {
            // DateTime::createFromFormat() will create an invalid DateTimeZone object when the timezone is an offset
            // (-05:00, for example) instead of a named timezone. By recreating the DateTimeZone object, we can expose
            // this problem and ensure that a valid DateTimeZone object is always set.
            $timezone = new DateTimeZone($date->getTimezone()->getName());
        } catch (Exception $e) {
            // @codeCoverageIgnoreStart
            $date->setTimezone(new DateTimeZone('UTC'));
            // @codeCoverageIgnoreEnd
        }

        return new TimePoint(
            (int) $date->format('Y'),
            (int) $date->format('m'),
            (int) $date->format('d'),
            (int) $date->format('H'),
            (int) $date->format('i'),
            (int) $date->format('s'),
            $date->getTimezone()->getName(),
            (int) $date->format('u')
        );
    }
private function dateTimeToTimePoint ( DateTime $ date ) { // missing or offset only timezone? correct to UTC if ( ! $ date -> getTimezone ( ) instanceof DateTimeZone || preg_match ( '#^[+-]{1}[0-9]{2}:?[0-9]{2}$#' , $ date -> getTimezone ( ) -> getName ( ) ) ) { $ date -> setTimezone ( new DateTimeZone ( 'UTC' ) ) ; } try { // DateTime::createFromFormat() will create an invalid DateTimeZone object when the timezone is an offset // (-05:00, for example) instead of a named timezone. By recreating the DateTimeZone object, we can expose // this problem and ensure that a valid DateTimeZone object is always set. $ timezone = new DateTimeZone ( $ date -> getTimezone ( ) -> getName ( ) ) ; } catch ( Exception $ e ) { // @codeCoverageIgnoreStart $ date -> setTimezone ( new DateTimeZone ( 'UTC' ) ) ; // @codeCoverageIgnoreEnd } return new TimePoint ( ( int ) $ date -> format ( 'Y' ) , ( int ) $ date -> format ( 'm' ) , ( int ) $ date -> format ( 'd' ) , ( int ) $ date -> format ( 'H' ) , ( int ) $ date -> format ( 'i' ) , ( int ) $ date -> format ( 's' ) , $ date -> getTimezone ( ) -> getName ( ) , ( int ) $ date -> format ( 'u' ) ) ; }
Convert a DateTime to a TimePoint

Note that, if the DateTime includes fractional seconds, that precision will be lost as the TimePoint object
does not support the inclusion of fractional seconds.

@param DateTime $date

@return TimePoint
Convert a DateTime to a TimePoint