feat: add time offset configuration

This commit is contained in:
2026-03-24 07:20:52 +01:00
parent 560cb67722
commit 195028d994
14 changed files with 148 additions and 27 deletions
+4
View File
@@ -333,6 +333,10 @@ namespace Montauk {
return Sys_BtInfo((BtAdapterInfo*)frame->arg1);
case SYS_SUSPEND:
return Sys_Suspend();
case SYS_SETTZ:
return Sys_SetTZ((int32_t)frame->arg1);
case SYS_GETTZ:
return Sys_GetTZ();
default:
return -1;
}
+4
View File
@@ -174,6 +174,10 @@ namespace Montauk {
/* Power.hpp */
static constexpr uint64_t SYS_SUSPEND = 89;
/* Time.hpp */
static constexpr uint64_t SYS_SETTZ = 90;
static constexpr uint64_t SYS_GETTZ = 91;
static constexpr int SOCK_TCP = 1;
static constexpr int SOCK_UDP = 2;
+9
View File
@@ -29,4 +29,13 @@ namespace Montauk {
out->Minute = dt.Minute;
out->Second = dt.Second;
}
static int64_t Sys_SetTZ(int32_t offsetMinutes) {
Timekeeping::SetTZOffset(offsetMinutes);
return 0;
}
static int64_t Sys_GetTZ() {
return (int64_t)Timekeeping::GetTZOffset();
}
};
+29 -27
View File
@@ -11,6 +11,7 @@
using namespace Kt;
static int64_t g_bootEpoch = 0;
static int g_tzOffsetMinutes = 60; /* Default: UTC+1 (CET) until userspace overrides */
static bool IsLeapYear(int year) {
return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
@@ -68,34 +69,29 @@ static Timekeeping::DateTime EpochToDate(int64_t epoch) {
void Timekeeping::Init(uint16_t Year, uint8_t Month, uint8_t Day, uint8_t Hour, uint8_t Minute, uint8_t Second) {
g_bootEpoch = DateToEpoch(Year, Month, Day, Hour, Minute, Second);
/* Hardcode CET for now */
TimeZone CET = {
"Central European Time",
"CET",
1, /* UTC+1 */
0,
false
};
Kt::KernelLogStream(INFO, "Timekeeping Service") << "Setting time zone to " << CET.TZLongName << " (" << CET.TZShortName << ")";
/* Apply default timezone offset for boot log display */
int adjMin = Minute + (g_tzOffsetMinutes % 60);
int adjHour = Hour + (g_tzOffsetMinutes / 60);
if (adjMin < 0) { adjMin += 60; adjHour -= 1; }
if (adjMin >= 60) { adjMin -= 60; adjHour += 1; }
if (adjHour < 0) adjHour += 24;
if (adjHour >= 24) adjHour -= 24;
Minute = Minute + CET.MinuteOffset;
Hour = Hour + CET.HourOffset;
if (Minute >= 60) {
Minute -= 60;
Hour += 1;
}
if (Hour >= 24) {
Hour -= 24;
Day += 1;
/* Note: No month/day overflow handling yet */
}
int offH = g_tzOffsetMinutes / 60;
int offM = g_tzOffsetMinutes % 60;
if (offM < 0) offM = -offM;
Kt::KernelLogStream(INFO, "Timekeeping Service") << "Time zone: UTC"
<< (offH >= 0 ? "+" : "") << offH
<< (offM ? ":" : "") << (offM >= 10 ? "" : (offM ? "0" : ""))
<< (offM ? offM : 0);
kcp::cstringstream minuteStream;
if (Minute < 10) {
if (adjMin < 10) {
minuteStream << "0";
}
minuteStream << Minute;
minuteStream << adjMin;
CString minuteStr = minuteStream.c_str();
kcp::cstringstream secondStream;
@@ -111,12 +107,10 @@ void Timekeeping::Init(uint16_t Year, uint8_t Month, uint8_t Day, uint8_t Hour,
<< Day << " "
<< Months[Month] << " "
<< Year << ", "
<< Hour << ":"
<< adjHour << ":"
<< minuteStr << ":"
<< secondStr
<< " (" << CET.TZLongName << ")";
<< " (UTC" << (offH >= 0 ? "+" : "") << offH << ")";
CString dateString = panelStr.c_str();
@@ -128,5 +122,13 @@ int64_t Timekeeping::GetUnixTimestamp() {
}
Timekeeping::DateTime Timekeeping::GetDateTime() {
return EpochToDate(GetUnixTimestamp());
return EpochToDate(GetUnixTimestamp() + (int64_t)g_tzOffsetMinutes * 60);
}
void Timekeeping::SetTZOffset(int totalMinutes) {
g_tzOffsetMinutes = totalMinutes;
}
int Timekeeping::GetTZOffset() {
return g_tzOffsetMinutes;
}
+3
View File
@@ -53,4 +53,7 @@ namespace Timekeeping {
void Init(uint16_t Year, uint8_t Month, uint8_t Day, uint8_t Hour, uint8_t Minute, uint8_t Second);
int64_t GetUnixTimestamp();
DateTime GetDateTime();
void SetTZOffset(int totalMinutes);
int GetTZOffset();
};