1 #ifndef OSMIUM_OSM_TIMESTAMP_HPP
2 #define OSMIUM_OSM_TIMESTAMP_HPP
87 template <typename T, typename std::enable_if<std::is_integral<T>::value,
int>
::type = 0>
101 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
104 throw std::invalid_argument(
"can't parse timestamp");
106 m_timestamp =
static_cast<uint32_t
>(timegm(&tm));
109 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);
111 throw std::invalid_argument(
"can't parse timestamp");
118 m_timestamp =
static_cast<uint32_t
>(_mkgmtime(&tm));
137 return m_timestamp != 0;
141 explicit constexpr
operator bool() const noexcept {
142 return m_timestamp != 0;
147 return time_t(m_timestamp);
151 explicit constexpr
operator uint32_t() const noexcept {
152 return uint32_t(m_timestamp);
156 explicit constexpr
operator uint64_t() const noexcept {
157 return uint64_t(m_timestamp);
169 template <
typename T>
171 m_timestamp += time_difference;
174 template <
typename T>
176 m_timestamp -= time_difference;
186 if (m_timestamp != 0) {
195 s.resize(timestamp_length);
201 s.resize(strftime(const_cast<char*>(s.c_str()), timestamp_length,
timestamp_format(), &tm));
222 return Timestamp(std::numeric_limits<uint32_t>::max());
225 template <
typename TChar,
typename TTraits>
226 inline std::basic_ostream<TChar, TTraits>& operator<<(std::basic_ostream<TChar, TTraits>& out,
Timestamp timestamp) {
227 out << timestamp.
to_iso();
232 return uint32_t(lhs) == uint32_t(rhs);
236 return !(lhs == rhs);
240 return uint32_t(lhs) < uint32_t(rhs);
248 return ! (rhs < lhs);
252 return ! (lhs < rhs);
267 #endif // OSMIUM_OSM_TIMESTAMP_HPP
#define OSMIUM_DEPRECATED
Definition: compatibility.hpp:53
type
Definition: entity_bits.hpp:60
bool operator<=(const Changeset &lhs, const Changeset &rhs)
Definition: changeset.hpp:446
static constexpr int timestamp_length
Definition: timestamp.hpp:58
OSMIUM_CONSTEXPR Timestamp start_of_time() noexcept
Definition: timestamp.hpp:213
OSMIUM_CONSTEXPR bool operator==(const Box &lhs, const Box &rhs) noexcept
Definition: box.hpp:219
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:55
OSMIUM_CONSTEXPR Timestamp end_of_time() noexcept
Definition: timestamp.hpp:221
bool operator>=(const Changeset &lhs, const Changeset &rhs)
Definition: changeset.hpp:450
void operator-=(T time_difference) noexcept
Definition: timestamp.hpp:175
#define OSMIUM_CONSTEXPR
Definition: compatibility.hpp:43
bool operator>(const Changeset &lhs, const Changeset &rhs)
Definition: changeset.hpp:442
constexpr Timestamp() noexcept
Definition: timestamp.hpp:74
Timestamp(const std::string ×tamp)
Definition: timestamp.hpp:128
void operator+=(T time_difference) noexcept
Definition: timestamp.hpp:170
constexpr Timestamp(T timestamp) noexcept
Definition: timestamp.hpp:88
std::string to_iso() const
Definition: timestamp.hpp:183
Timestamp(const char *timestamp)
Definition: timestamp.hpp:98
uint32_t m_timestamp
Definition: timestamp.hpp:67
bool valid() const noexcept
Definition: timestamp.hpp:136
constexpr time_t seconds_since_epoch() const noexcept
Explicit conversion into time_t.
Definition: timestamp.hpp:146
bool operator!=(const Changeset &lhs, const Changeset &rhs)
Definition: changeset.hpp:431
static const char * timestamp_format()
Definition: timestamp.hpp:62