mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-14 10:05:44 -04:00
Fix updates menu showing massive negative seconds values when system time is set to years behind current time (e.g. 2000)
This commit is contained in:
parent
5898f4edef
commit
51d4842c30
@ -1570,14 +1570,27 @@ static struct UpdatesScreen {
|
|||||||
cc_bool pendingFetch, release, d3d9;
|
cc_bool pendingFetch, release, d3d9;
|
||||||
} UpdatesScreen_Instance;
|
} UpdatesScreen_Instance;
|
||||||
|
|
||||||
CC_NOINLINE static void UpdatesScreen_FormatTime(cc_string* str, char* type, int delta, int unit) {
|
CC_NOINLINE static void UpdatesScreen_FormatTime(cc_string* str, int delta) {
|
||||||
delta /= unit;
|
const char* span;
|
||||||
String_AppendInt(str, delta);
|
int unit, value = Math_AbsI(delta);
|
||||||
String_Append(str, ' ');
|
|
||||||
String_AppendConst(str, type);
|
|
||||||
|
|
||||||
if (delta > 1) String_Append(str, 's');
|
if (value < SECS_PER_MIN) {
|
||||||
String_AppendConst(str, " ago");
|
span = "second"; unit = 1;
|
||||||
|
} else if (value < SECS_PER_HOUR) {
|
||||||
|
span = "minute"; unit = SECS_PER_MIN;
|
||||||
|
} else if (value < SECS_PER_DAY) {
|
||||||
|
span = "hour"; unit = SECS_PER_HOUR;
|
||||||
|
} else {
|
||||||
|
span = "day"; unit = SECS_PER_DAY;
|
||||||
|
}
|
||||||
|
|
||||||
|
value /= unit;
|
||||||
|
String_AppendInt(str, value);
|
||||||
|
String_Append(str, ' ');
|
||||||
|
String_AppendConst(str, span);
|
||||||
|
|
||||||
|
if (value > 1) String_Append(str, 's');
|
||||||
|
String_AppendConst(str, delta >= 0 ? " ago" : " in the future");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void UpdatesScreen_Format(struct LLabel* lbl, const char* prefix, cc_uint64 timestamp) {
|
static void UpdatesScreen_Format(struct LLabel* lbl, const char* prefix, cc_uint64 timestamp) {
|
||||||
@ -1594,16 +1607,7 @@ static void UpdatesScreen_Format(struct LLabel* lbl, const char* prefix, cc_uint
|
|||||||
now = DateTime_CurrentUTC_MS() - UNIX_EPOCH;
|
now = DateTime_CurrentUTC_MS() - UNIX_EPOCH;
|
||||||
/* must divide as cc_uint64, int delta overflows after 26 days */
|
/* must divide as cc_uint64, int delta overflows after 26 days */
|
||||||
delta = (int)((now / 1000) - timestamp);
|
delta = (int)((now / 1000) - timestamp);
|
||||||
|
UpdatesScreen_FormatTime(&str, delta);
|
||||||
if (delta < SECS_PER_MIN) {
|
|
||||||
UpdatesScreen_FormatTime(&str, "second", delta, 1);
|
|
||||||
} else if (delta < SECS_PER_HOUR) {
|
|
||||||
UpdatesScreen_FormatTime(&str, "minute", delta, SECS_PER_MIN);
|
|
||||||
} else if (delta < SECS_PER_DAY) {
|
|
||||||
UpdatesScreen_FormatTime(&str, "hour", delta, SECS_PER_HOUR);
|
|
||||||
} else {
|
|
||||||
UpdatesScreen_FormatTime(&str, "day", delta, SECS_PER_DAY);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
LLabel_SetText(lbl, &str);
|
LLabel_SetText(lbl, &str);
|
||||||
LWidget_Redraw(lbl);
|
LWidget_Redraw(lbl);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user