1 #ifndef OSMIUM_OSM_TIMESTAMP_HPP 2 #define OSMIUM_OSM_TIMESTAMP_HPP 88 template <typename T, typename std::enable_if<std::is_integral<T>::value,
int>
::type = 0>
102 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
105 throw std::invalid_argument(
"can't parse timestamp");
107 m_timestamp =
static_cast<uint32_t
>(timegm(&tm));
110 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);
112 throw std::invalid_argument(
"can't parse timestamp");
119 m_timestamp =
static_cast<uint32_t
>(_mkgmtime(&tm));
138 return m_timestamp != 0;
142 explicit constexpr
operator bool() const noexcept {
143 return m_timestamp != 0;
148 return time_t(m_timestamp);
152 explicit constexpr
operator uint32_t() const noexcept {
153 return uint32_t(m_timestamp);
157 explicit constexpr
operator uint64_t() const noexcept {
158 return uint64_t(m_timestamp);
170 template <
typename T>
172 m_timestamp += time_difference;
175 template <
typename T>
177 m_timestamp -= time_difference;
188 if (m_timestamp != 0) {
196 assert(result !=
nullptr);
202 s.resize(timestamp_length);
208 s.resize(strftime(const_cast<char*>(s.c_str()), timestamp_length,
timestamp_format(), &tm));
229 return Timestamp(std::numeric_limits<uint32_t>::max());
232 template <
typename TChar,
typename TTraits>
233 inline std::basic_ostream<TChar, TTraits>& operator<<(std::basic_ostream<TChar, TTraits>& out,
Timestamp timestamp) {
234 out << timestamp.
to_iso();
239 return uint32_t(lhs) == uint32_t(rhs);
243 return !(lhs == rhs);
247 return uint32_t(lhs) < uint32_t(rhs);
255 return ! (rhs < lhs);
259 return ! (lhs < rhs);
274 #endif // OSMIUM_OSM_TIMESTAMP_HPP #define OSMIUM_DEPRECATED
Definition: compatibility.hpp:50
type
Definition: entity_bits.hpp:60
bool operator<=(const Changeset &lhs, const Changeset &rhs)
Definition: changeset.hpp:446
constexpr Timestamp start_of_time() noexcept
Definition: timestamp.hpp:220
constexpr bool operator==(const Box &lhs, const Box &rhs) noexcept
Definition: box.hpp:222
static constexpr int timestamp_length
Definition: timestamp.hpp:59
bool operator<(const Changeset &lhs, const Changeset &rhs)
Definition: changeset.hpp:438
Namespace for everything in the Osmium library.
Definition: assembler.hpp:59
Definition: timestamp.hpp:56
bool operator>=(const Changeset &lhs, const Changeset &rhs)
Definition: changeset.hpp:450
void operator-=(T time_difference) noexcept
Definition: timestamp.hpp:176
bool operator>(const Changeset &lhs, const Changeset &rhs)
Definition: changeset.hpp:442
constexpr Timestamp() noexcept
Definition: timestamp.hpp:75
Timestamp(const std::string ×tamp)
Definition: timestamp.hpp:129
void operator+=(T time_difference) noexcept
Definition: timestamp.hpp:171
constexpr Timestamp(T timestamp) noexcept
Definition: timestamp.hpp:89
std::string to_iso() const
Definition: timestamp.hpp:185
constexpr Timestamp end_of_time() noexcept
Definition: timestamp.hpp:228
Timestamp(const char *timestamp)
Definition: timestamp.hpp:99
uint32_t m_timestamp
Definition: timestamp.hpp:68
bool valid() const noexcept
Definition: timestamp.hpp:137
constexpr time_t seconds_since_epoch() const noexcept
Explicit conversion into time_t.
Definition: timestamp.hpp:147
bool operator!=(const Changeset &lhs, const Changeset &rhs)
Definition: changeset.hpp:431
static const char * timestamp_format()
Definition: timestamp.hpp:63