Stay organized with collections
Save and categorize content based on your preferences.
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.
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
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.
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_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.
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 of std::chrono::system_clock is unspecified, it's usually Unix epoch. If this assumption is broken, this constructor will produce incorrect results.
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 of time_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.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-03-13 UTC."],[],[],null,["firebase::Timestamp\n\n\n`#include \u003ctimestamp.h\u003e`\n\nA [Timestamp](/docs/reference/cpp/class/firebase/timestamp#classfirebase_1_1_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.\n\nSummary\n\nIt 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.\n\n\n**See also:**\n\u003chttps://github.com/google/protobuf/blob/main/src/google/protobuf/timestamp.proto\u003e\n\nPublic functions \n\nTimestamp \n\n```c++\n Timestamp()=default\n``` \nCreates a new timestamp representing the epoch (with seconds and nanoseconds set to 0). \n\nTimestamp \n\n```c++\n Timestamp(\n int64_t seconds,\n int32_t nanoseconds\n)\n``` \nCreates a new timestamp.\n\n\u003cbr /\u003e\n\nTimestamp \n\n```c++\n Timestamp(\n const Timestamp & other\n)=default\n``` \nCopy constructor, [Timestamp](/docs/reference/cpp/class/firebase/timestamp#classfirebase_1_1_timestamp) is trivially copyable. \n\nTimestamp \n\n```c++\n Timestamp(\n Timestamp && other\n)=default\n``` \nMove constructor, equivalent to copying. \n\nToString \n\n```c++\nstd::string ToString() const \n``` \nReturns a string representation of this [Timestamp](/docs/reference/cpp/class/firebase/timestamp#classfirebase_1_1_timestamp) for logging/debugging purposes.\n\n\n| **Note:** : the exact string representation is unspecified and subject to change; don't rely on the format of the string.\n\n\u003cbr /\u003e\n\nToTimePoint \n\n```c++\nstd::chrono::time_point\u003c Clock, Duration \u003e ToTimePoint() const \n``` \nConverts this [Timestamp](/docs/reference/cpp/class/firebase/timestamp#classfirebase_1_1_timestamp) to a `time_point`.\n\nImportant: 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](/docs/reference/cpp/class/firebase/timestamp#classfirebase_1_1_timestamp) values with nanosecond precision (which is why `Duration` defaults to `microseconds`). \n\nnanoseconds \n\n```c++\nint32_t nanoseconds() const \n``` \nThe non-negative fractions of a second at nanosecond resolution.\n\nNegative second values with fractions still have non-negative nanoseconds values that count forward in time. \n\noperator= \n\n```c++\nTimestamp & operator=(\n const Timestamp & other\n)=default\n``` \nCopy assignment operator, [Timestamp](/docs/reference/cpp/class/firebase/timestamp#classfirebase_1_1_timestamp) is trivially copyable. \n\noperator= \n\n```c++\nTimestamp & operator=(\n Timestamp && other\n)=default\n``` \nMove assignment operator, equivalent to copying. \n\nseconds \n\n```c++\nint64_t seconds() const \n``` \nThe number of seconds of UTC time since Unix epoch 1970-01-01T00:00:00Z.\n\nPublic static functions \n\nFromTimePoint \n\n```c++\nTimestamp FromTimePoint(\n std::chrono::time_point\u003c std::chrono::system_clock \u003e time_point\n)\n``` \nConverts `std::chrono::time_point` to a [Timestamp](/docs/reference/cpp/class/firebase/timestamp#classfirebase_1_1_timestamp).\n\n\u003cbr /\u003e\n\nFromTimeT \n\n```c++\nTimestamp FromTimeT(\n time_t seconds_since_unix_epoch\n)\n``` \nConverts `time_t` to a [Timestamp](/docs/reference/cpp/class/firebase/timestamp#classfirebase_1_1_timestamp).\n\n\u003cbr /\u003e\n\nNow \n\n```c++\nTimestamp Now()\n``` \nCreates a new timestamp with the current date.\n\nThe precision is up to nanoseconds, depending on the system clock.\n\n\u003cbr /\u003e\n\nFriend classes \n\noperator\\\u003c\\\u003c \n\n```c++\nfriend std::ostream & operator\u003c\u003c(std::ostream &out, const Timestamp ×tamp)\n``` \nOutputs the string representation of this [Timestamp](/docs/reference/cpp/class/firebase/timestamp#classfirebase_1_1_timestamp) to the given stream.\n\n**See also:** [ToString()](/docs/reference/cpp/class/firebase/timestamp#classfirebase_1_1_timestamp_1a6f41b38da6d7a697f7f7f8605a8f2298) for comments on the representation format."]]