firebase:: Timestamp
#include <timestamp.h>
A Timestamp 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(const Timestamp & 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 this
Timestamp for logging/debugging purposes. |
ToTimePoint() const
|
std::chrono::time_point< Clock, Duration >
Converts this
Timestamp to a time_point . |
nanoseconds() const
|
int32_t
The non-negative fractions of a second at nanosecond resolution.
|
operator=(const Timestamp & 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)
|
Converts
std::chrono::time_point to a Timestamp . |
FromTimeT(time_t seconds_since_unix_epoch)
|
Converts
time_t to a Timestamp . |
Now()
|
Creates a new timestamp with the current date.
|
Friend classes |
|
---|---|
operator<<
|
friend std::ostream &
Outputs the string representation of this
Timestamp 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_t seconds, int32_t nanoseconds )
Creates a new timestamp.
Details | |||||
---|---|---|---|---|---|
Parameters |
|
Timestamp
Timestamp( const Timestamp & other )=default
Copy constructor, Timestamp
is trivially copyable.
ToString
std::string ToString() const
Returns a string representation of this Timestamp
for logging/debugging purposes.
ToTimePoint
std::chrono::time_point< Clock, Duration > ToTimePoint() const
Converts this Timestamp
to a time_point
.
Important: if overflow would occur, the returned value will be the maximum or minimum value that Duration
can hold. Note in particular that long long
is insufficient to hold the full range of Timestamp
values with nanosecond precision (which is why Duration
defaults to microseconds
).
nanoseconds
int32_t nanoseconds() 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=( const Timestamp & other )=default
Copy assignment operator, Timestamp
is trivially copyable.
operator=
Timestamp & operator=( Timestamp && other )=default
Move assignment operator, equivalent to copying.
seconds
int64_t seconds() const
The number of seconds of UTC time since Unix epoch 1970-01-01T00:00:00Z.
Public static functions
FromTimePoint
Timestamp FromTimePoint( std::chrono::time_point< std::chrono::system_clock > time_point )
Converts std::chrono::time_point
to a Timestamp
.
Details | |||
---|---|---|---|
Parameters |
|
FromTimeT
Timestamp FromTimeT( time_t seconds_since_unix_epoch )
Converts time_t
to a Timestamp
.
Details | |||
---|---|---|---|
Parameters |
|
||
Returns |
a new timestamp with the given number of seconds and zero nanoseconds.
|
Now
Timestamp Now()
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<<
friend std::ostream & operator<<(std::ostream &out, const Timestamp ×tamp)
Outputs the string representation of this Timestamp
to the given stream.
See also:ToString()
for comments on the representation format.