private function formatTimeAsString(\DateTimeInterface $dateTime, $ns)
    {
        $dateTime = $dateTime->setTimeZone(new \DateTimeZone('UTC'));
        if ($ns === null) {
            return $dateTime->format(Timestamp::FORMAT);
        } else {
            $ns = (string) $ns;
            $ns = str_pad($ns, 9, '0', STR_PAD_LEFT);
            if (substr($ns, 6, 3) === '000') {
                $ns = substr($ns, 0, 6);
            }

            return sprintf(
                $dateTime->format(Timestamp::FORMAT_INTERPOLATE),
                $ns
            );
        }
    }