#pragma once #include #include namespace roro { // Ordered by trust: a source can only replace the time set by an equal or less trusted one. enum class TimeSource : uint8_t { None, Mesh, Ntp, Gnss }; // Wall-clock time on a device with no battery-backed clock: unset until a TimeSource provides // it, then advanced from uptime. Stored in UTC; local display uses the POSIX TZ applied globally. class ClockModel { public: // Returns false if a more trusted source already set the time. bool set(int64_t utcSeconds, TimeSource source, uint32_t nowMs); bool isSet() const { return source_ != TimeSource::None; } TimeSource source() const { return source_; } int64_t utcNow(uint32_t nowMs) const; static void applyTimezone(const char* posixTz); static std::string formatLocalTime(int64_t utcSeconds); // "HH:MM" static std::string formatLocalDate(int64_t utcSeconds); // "YYYY-MM-DD" static std::string formatAge(int64_t seconds); // "now", "5 min ago", "3 h ago", "2 d ago" private: TimeSource source_ = TimeSource::None; int64_t utcAtSet_ = 0; uint32_t msAtSet_ = 0; }; } // namespace roro