value = $value; $this->nanoSeconds = $nanoSeconds !== null ? (int) $nanoSeconds : null; } /** * Get the underlying `\DateTimeInterface` implementation. * * Please note that if you provided nanoseconds when creating the timestamp, * they will not be included in this value. * * Example: * ``` * $dateTime = $timestamp->get(); * ``` * * @return \DateTimeInterface */ public function get() { return $this->value; } /** * Return the number of nanoseconds. * * Example: * ``` * $nanos = $timestamp->nanoSeconds(); * ``` * * @return int */ public function nanoSeconds() { return $this->nanoSeconds === null ? (int) $this->value->format('u') * 1000 : $this->nanoSeconds; } /** * Format the value as a string. * * Example: * ``` * $value = $timestamp->formatAsString(); * ``` * * @return string */ public function formatAsString() { return $this->formatTimeAsString($this->value, $this->nanoSeconds); } /** * Format the value as a string. * * @return string * @access private */ public function __toString() { return $this->formatAsString(); } /** * Format a timestamp for the API with nanosecond precision. * * @return array */ public function formatForApi() { return $this->formatTimeAsArray($this->value, $this->nanoSeconds()); } }