Public Access
- lib/storage_model (host-tested): FAT-safe names, daily Log paths, dates from Log/Capture file names, CleanupPlan by category and age, byte formatting - StorageService does all card I/O on its task: queued Log lines are written in batches each second (dropped while Logs are paused), plus file listing and deletion jobs - Settings > Storage moves into StoragePage: usage, Clean up (category, age with size preview, confirmation), Erase SD card - Clock: local date for Log names - Serial: log <text>, sd list Verified on the device: lines land in /irc/dev/#test/2026-10-02.log with folders created as needed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EhqxQ49eCju4CzKYNjZzwT
59 lines
1.7 KiB
C++
59 lines
1.7 KiB
C++
#include "clock_model.h"
|
|
|
|
#include <cstdio>
|
|
#include <cstdlib>
|
|
#include <ctime>
|
|
|
|
namespace roro {
|
|
|
|
bool ClockModel::set(int64_t utcSeconds, TimeSource source, uint32_t nowMs) {
|
|
if (source < source_) return false;
|
|
source_ = source;
|
|
utcAtSet_ = utcSeconds;
|
|
msAtSet_ = nowMs;
|
|
return true;
|
|
}
|
|
|
|
int64_t ClockModel::utcNow(uint32_t nowMs) const {
|
|
// Unsigned subtraction handles the millis() wraparound. Uptime beyond 49 days between two
|
|
// sets would lose 49 days; sources refresh far more often than that.
|
|
return utcAtSet_ + static_cast<int64_t>(static_cast<uint32_t>(nowMs - msAtSet_) / 1000);
|
|
}
|
|
|
|
void ClockModel::applyTimezone(const char* posixTz) {
|
|
setenv("TZ", posixTz, 1);
|
|
tzset();
|
|
}
|
|
|
|
std::string ClockModel::formatLocalTime(int64_t utcSeconds) {
|
|
time_t t = static_cast<time_t>(utcSeconds);
|
|
struct tm local;
|
|
localtime_r(&t, &local);
|
|
char buf[8];
|
|
std::snprintf(buf, sizeof(buf), "%02d:%02d", local.tm_hour, local.tm_min);
|
|
return buf;
|
|
}
|
|
|
|
std::string ClockModel::formatLocalDate(int64_t utcSeconds) {
|
|
time_t t = static_cast<time_t>(utcSeconds);
|
|
struct tm local;
|
|
localtime_r(&t, &local);
|
|
char buf[12];
|
|
std::snprintf(buf, sizeof(buf), "%04d-%02d-%02d", local.tm_year + 1900, local.tm_mon + 1, local.tm_mday);
|
|
return buf;
|
|
}
|
|
|
|
std::string ClockModel::formatAge(int64_t seconds) {
|
|
char buf[24];
|
|
if (seconds < 60) return "now";
|
|
if (seconds < 3600)
|
|
std::snprintf(buf, sizeof(buf), "%d min ago", static_cast<int>(seconds / 60));
|
|
else if (seconds < 86400)
|
|
std::snprintf(buf, sizeof(buf), "%d h ago", static_cast<int>(seconds / 3600));
|
|
else
|
|
std::snprintf(buf, sizeof(buf), "%d d ago", static_cast<int>(seconds / 86400));
|
|
return buf;
|
|
}
|
|
|
|
} // namespace roro
|