add TZ offset +3h (MSK) for time display/set

This commit is contained in:
UA1ZBE
2026-07-22 13:00:55 +03:00
parent dfdd6ab343
commit d3990516b5

View File

@@ -46,6 +46,8 @@ static float g_last_temperature = -127.0f;
static unsigned long g_last_hall_alert = 0;
static unsigned long g_last_motion_alert = 0;
static const unsigned long ALERT_COOLDOWN_MS = 600000;
static const uint32_t TZ_OFFSET = 10800; // +3h (MSK)
static uint32_t date_to_epoch(int y, int m, int d, int h, int mi) {
const uint8_t mdays[] = {31,28,31,30,31,30,31,31,30,31,30,31};
uint32_t days = (y - 1970) * 365;
@@ -227,7 +229,7 @@ public:
} else if (strncmp(cmd, "time", 4) == 0) {
const char* rest = cmd + 4; while (*rest == ' ') rest++;
if (*rest == 0) {
uint32_t ts = rtc_clock.getCurrentTime();
uint32_t ts = rtc_clock.getCurrentTime() + TZ_OFFSET;
if (ts < 100000) { defer_response("time not set"); return; }
uint32_t days = ts / 86400;
int h = (ts % 86400) / 3600;
@@ -258,7 +260,7 @@ public:
if (y < 2020 || y > 2099 || m < 1 || m > 12 || d < 1 || d > 31 || h > 23 || mi > 59) {
defer_response("bad date"); return;
}
rtc_clock.setCurrentTime(date_to_epoch(y, m, d, h, mi));
rtc_clock.setCurrentTime(date_to_epoch(y, m, d, h, mi) - TZ_OFFSET);
char r[64]; snprintf(r, sizeof(r), "time set %02d.%02d.%04d %02d.%02d", d, m, y, h, mi);
defer_response(r);
} else defer_response("time s DD.MM.YYYY HH.MM");