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 template <
typename T>
118 m_timestamp += time_difference;
121 template <
typename T>
123 m_timestamp -= time_difference;
132 if (m_timestamp != 0) {
141 s.resize(timestamp_length);
147 s.resize(strftime(const_cast<char*>(s.c_str()), timestamp_length,
timestamp_format(), &tm));
160 return Timestamp(std::numeric_limits<time_t>::max());
163 template <
typename TChar,
typename TTraits>
164 inline std::basic_ostream<TChar, TTraits>& operator<<(std::basic_ostream<TChar, TTraits>& out,
Timestamp timestamp) {
165 out << timestamp.
to_iso();
171 #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:155
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:159
void operator-=(T time_difference) noexcept
Definition: timestamp.hpp:122
#define OSMIUM_CONSTEXPR
Definition: compatibility.hpp:43
constexpr Timestamp() noexcept
Definition: timestamp.hpp:70
void operator+=(T time_difference) noexcept
Definition: timestamp.hpp:117
std::string to_iso() const
Definition: timestamp.hpp:129
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