firebase::Timestamp

#include <timestamp.h>

ATimestamp represents a point in time independent of any time zone or calendar, represented as seconds and fractions of seconds at nanosecond resolution in UTC Epoch time.

Summary

It is encoded using the Proleptic Gregorian Calendar which extends the Gregorian calendar backwards to year one. It is encoded assuming all minutes are 60 seconds long, i.e. leap seconds are "smeared" so that no leap second table is needed for interpretation. Range is from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59.999999999Z.

See also:https://github.com/google/protobuf/blob/main/src/google/protobuf/timestamp.proto

Constructors and Destructors

Timestamp()
Creates a new timestamp representing the epoch (with seconds and nanoseconds set to 0).
Timestamp(int64_t seconds, int32_t nanoseconds)
Creates a new timestamp.
Timestamp(constTimestamp & other)
Copy constructor,Timestamp is trivially copyable.
Timestamp(Timestamp && other)
Move constructor, equivalent to copying.

Public functions

ToString() const
std::string
Returns a string representation of thisTimestamp for logging/debugging purposes.
ToTimePoint() const
std::chrono::time_point< Clock, Duration >
Converts thisTimestamp to atime_point.
nanoseconds() const
int32_t
The non-negative fractions of a second at nanosecond resolution.
operator=(constTimestamp & other)=default
Copy assignment operator,Timestamp is trivially copyable.
operator=(Timestamp && other)=default
Move assignment operator, equivalent to copying.
seconds() const
int64_t
The number of seconds of UTC time since Unix epoch 1970-01-01T00:00:00Z.

Public static functions

FromTimePoint(std::chrono::time_point< std::chrono::system_clock > time_point)
Convertsstd::chrono::time_point to aTimestamp.
FromTimeT(time_t seconds_since_unix_epoch)
Convertstime_t to aTimestamp.
Now()
Creates a new timestamp with the current date.

Friend classes

operator<<
friend std::ostream &
Outputs the string representation of thisTimestamp to the given stream.

Public functions

Timestamp

Timestamp()=default

Creates a new timestamp representing the epoch (with seconds and nanoseconds set to 0).

Timestamp

Timestamp(int64_tseconds,int32_tnanoseconds)

Creates a new timestamp.

Details
Parameters
seconds
The number of seconds of UTC time since Unix epoch 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59Z inclusive; otherwise, assertion failure will be triggered.
nanoseconds
The non-negative fractions of a second at nanosecond resolution. Negative second values with fractions must still have non-negative nanoseconds values that count forward in time. Must be from 0 to 999,999,999 inclusive; otherwise, assertion failure will be triggered.

Timestamp

Timestamp(constTimestamp&other)=default

Copy constructor,Timestamp is trivially copyable.

Timestamp

Timestamp(Timestamp&&other)=default

Move constructor, equivalent to copying.

ToString

std::stringToString()const

ToTimePoint

std::chrono::time_point<Clock,Duration>ToTimePoint()const

Converts thisTimestamp to atime_point.

Important: if overflow would occur, the returned value will be the maximum or minimum value thatDuration can hold. Note in particular thatlong long is insufficient to hold the full range ofTimestamp values with nanosecond precision (which is whyDuration defaults tomicroseconds).

nanoseconds

int32_tnanoseconds()const

The non-negative fractions of a second at nanosecond resolution.

Negative second values with fractions still have non-negative nanoseconds values that count forward in time.

operator=

Timestamp&operator=(constTimestamp&other)=default

Copy assignment operator,Timestamp is trivially copyable.

operator=

Timestamp&operator=(Timestamp&&other)=default

Move assignment operator, equivalent to copying.

seconds

int64_tseconds()const

The number of seconds of UTC time since Unix epoch 1970-01-01T00:00:00Z.

Public static functions

FromTimePoint

TimestampFromTimePoint(std::chrono::time_point<std::chrono::system_clock>time_point)

Convertsstd::chrono::time_point to aTimestamp.

Details
Parameters
time_point
The time point with system clock's epoch, which is presumed to be Unix epoch 1970-01-01T00:00:00Z. Can be negative to represent dates before the epoch. Must be from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59Z inclusive; otherwise, assertion failure will be triggered. Note that while the epoch ofstd::chrono::system_clock is unspecified, it's usually Unix epoch. If this assumption is broken, this constructor will produce incorrect results.

FromTimeT

TimestampFromTimeT(time_tseconds_since_unix_epoch)

Convertstime_t to aTimestamp.

Details
Parameters
seconds_since_unix_epoch
The number of seconds of UTC time since Unix epoch 1970-01-01T00:00:00Z. Can be negative to represent dates before the epoch. Must be from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59Z inclusive; otherwise, assertion failure will be triggered. Note that while the epoch oftime_t is unspecified, it's usually Unix epoch. If this assumption is broken, this function will produce incorrect results.
Returns
a new timestamp with the given number of seconds and zero nanoseconds.

Now

TimestampNow()

Creates a new timestamp with the current date.

The precision is up to nanoseconds, depending on the system clock.

Details
Returns
a new timestamp representing the current date.

Friend classes

operator<<

friendstd::ostream&operator<<(std::ostream&out,constTimestamp&timestamp)

Outputs the string representation of thisTimestamp to the given stream.

See also:ToString() for comments on the representation format.

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2024-03-13 UTC.