1 #ifndef OSMIUM_OSM_TIMESTAMP_HPP
2 #define OSMIUM_OSM_TIMESTAMP_HPP
87 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
90 throw std::invalid_argument(
"can't parse timestamp");
92 m_timestamp =
static_cast<uint32_t
>(timegm(&tm));
95 int n = sscanf(timestamp,
"%4d-%2d-%2dT%2d:%2d:%2dZ", &tm.tm_year, &tm.tm_mon, &tm.tm_mday, &tm.tm_hour, &tm.tm_min, &tm.tm_sec);
97 throw std::invalid_argument(
"can't parse timestamp");
104 m_timestamp =
static_cast<uint32_t
>(_mkgmtime(&tm));
112 constexpr
operator time_t() const noexcept {
116 explicit constexpr
operator uint32_t() const noexcept {
120 template <
typename T>
122 m_timestamp += time_difference;
125 template <
typename T>
127 m_timestamp -= time_difference;
136 if (m_timestamp != 0) {
145 s.resize(timestamp_length);
151 s.resize(strftime(const_cast<char*>(s.c_str()), timestamp_length,
timestamp_format(), &tm));
164 return Timestamp(std::numeric_limits<time_t>::max());
167 template <
typename TChar,
typename TTraits>
168 inline std::basic_ostream<TChar, TTraits>& operator<<(std::basic_ostream<TChar, TTraits>& out,
Timestamp timestamp) {
169 out << timestamp.
to_iso();
185 #endif // OSMIUM_OSM_TIMESTAMP_HPP
constexpr time_t seconds_since_epoch() const noexcept
Definition: timestamp.hpp:108
static constexpr int timestamp_length
Definition: timestamp.hpp:55
OSMIUM_CONSTEXPR Timestamp start_of_time() noexcept
Definition: timestamp.hpp:159
Namespace for everything in the Osmium library.
Definition: assembler.hpp:55
Definition: timestamp.hpp:52
OSMIUM_CONSTEXPR Timestamp end_of_time() noexcept
Definition: timestamp.hpp:163
void operator-=(T time_difference) noexcept
Definition: timestamp.hpp:126
#define OSMIUM_CONSTEXPR
Definition: compatibility.hpp:43
constexpr Timestamp() noexcept
Definition: timestamp.hpp:70
void operator+=(T time_difference) noexcept
Definition: timestamp.hpp:121
std::string to_iso() const
Definition: timestamp.hpp:133
Timestamp(const char *timestamp)
Definition: timestamp.hpp:84
uint32_t m_timestamp
Definition: timestamp.hpp:66
constexpr Timestamp(time_t timestamp) noexcept
Definition: timestamp.hpp:76
static const char * timestamp_format()
Definition: timestamp.hpp:61