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::stringReturns a string representation of this Timestamp for logging/debugging purposes. |
ToTimePoint() const | std::chrono::time_point< Clock, Duration >Converts this Timestamp to atime_point. |
nanoseconds() const | int32_tThe 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_tThe 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 aTimestamp. |
FromTimeT(time_t seconds_since_unix_epoch) | Converts time_t to aTimestamp. |
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_tseconds,int32_tnanoseconds)
Creates a new timestamp.
| Details | |||||
|---|---|---|---|---|---|
| Parameters |
|
ToString
std::stringToString()const
Returns a string representation of thisTimestamp for logging/debugging purposes.
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 |
|
FromTimeT
TimestampFromTimeT(time_tseconds_since_unix_epoch)
Convertstime_t to aTimestamp.
| Details | |||
|---|---|---|---|
| Parameters |
| ||
| 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×tamp)
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.