1 #ifndef OSMIUM_OSM_TIMESTAMP_HPP
2 #define OSMIUM_OSM_TIMESTAMP_HPP
88 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
91 throw std::invalid_argument(
"can't parse timestamp");
93 m_timestamp =
static_cast<uint32_t
>(timegm(&tm));
96 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);
98 throw std::invalid_argument(
"can't parse timestamp");
105 m_timestamp =
static_cast<uint32_t
>(_mkgmtime(&tm));
113 constexpr
operator time_t() const noexcept {
117 explicit constexpr
operator uint32_t() const noexcept {
121 template <
typename T>
123 m_timestamp += time_difference;
126 template <
typename T>
128 m_timestamp -= time_difference;
137 if (m_timestamp != 0) {
146 s.resize(timestamp_length);
152 s.resize(strftime(const_cast<char*>(s.c_str()), timestamp_length,
timestamp_format(), &tm));
165 return Timestamp(std::numeric_limits<time_t>::max());
168 template <
typename TChar,
typename TTraits>
169 inline std::basic_ostream<TChar, TTraits>& operator<<(std::basic_ostream<TChar, TTraits>& out,
Timestamp timestamp) {
170 out << timestamp.
to_iso();
186 #endif // OSMIUM_OSM_TIMESTAMP_HPP
constexpr time_t seconds_since_epoch() const noexcept
Definition: timestamp.hpp:109
static constexpr int timestamp_length
Definition: timestamp.hpp:56
OSMIUM_CONSTEXPR Timestamp start_of_time() noexcept
Definition: timestamp.hpp:160
Namespace for everything in the Osmium library.
Definition: assembler.hpp:55
Definition: timestamp.hpp:53
OSMIUM_CONSTEXPR Timestamp end_of_time() noexcept
Definition: timestamp.hpp:164
void operator-=(T time_difference) noexcept
Definition: timestamp.hpp:127
#define OSMIUM_CONSTEXPR
Definition: compatibility.hpp:43
constexpr Timestamp() noexcept
Definition: timestamp.hpp:71
void operator+=(T time_difference) noexcept
Definition: timestamp.hpp:122
std::string to_iso() const
Definition: timestamp.hpp:134
Timestamp(const char *timestamp)
Definition: timestamp.hpp:85
uint32_t m_timestamp
Definition: timestamp.hpp:67
constexpr Timestamp(time_t timestamp) noexcept
Definition: timestamp.hpp:77
static const char * timestamp_format()
Definition: timestamp.hpp:62