cups: compute the UTC print time without time()

This also fixes zones with quarter hours like Nepal, which came out an
hour wrong.
This commit is contained in:
Daemonratte 2026-10-17 12:17:32 +02:00
commit 22e603ee99

View file

@ -5440,13 +5440,8 @@ localtime_to_utctime (const char *local_time)
" %I %p ", " %p %I "};
const char *formats_1[] = {" %H : %M : %S ", " %H : %M "};
const char *end = NULL;
struct tm *actual_local_time;
struct tm *actual_utc_time;
struct tm local_print_time;
struct tm utc_now;
struct tm local_now;
struct tm utc_print_time;
struct tm diff_time;
gchar *utc_time = NULL;
int i, n;
@ -5472,31 +5467,24 @@ localtime_to_utctime (const char *local_time)
if (end != NULL && end[0] == '\0')
{
time_t rawtime;
struct tm *tmp_tm;
GDateTime *now;
gint64 offset, secs;
time (&rawtime);
tmp_tm = gmtime (&rawtime);
if (tmp_tm == NULL)
/* The offset of local time now, from GDateTime: time () has no
* answer after 2038 where time_t is 32 bits */
now = g_date_time_new_now_local ();
if (now == NULL)
return NULL;
utc_now = *tmp_tm;
offset = g_date_time_get_utc_offset (now) / G_USEC_PER_SEC;
g_date_time_unref (now);
tmp_tm = localtime (&rawtime);
if (tmp_tm == NULL)
return NULL;
local_now = *tmp_tm;
secs = local_print_time.tm_hour * 3600 + local_print_time.tm_min * 60 +
local_print_time.tm_sec - offset;
secs = ((secs % 86400) + 86400) % 86400;
actual_utc_time = &utc_now;
actual_local_time = &local_now;
diff_time.tm_hour = actual_utc_time->tm_hour - actual_local_time->tm_hour;
diff_time.tm_min = actual_utc_time->tm_min - actual_local_time->tm_min;
diff_time.tm_sec = actual_utc_time->tm_sec - actual_local_time->tm_sec;
utc_print_time.tm_hour = ((local_print_time.tm_hour + diff_time.tm_hour) + 24) % 24;
utc_print_time.tm_min = ((local_print_time.tm_min + diff_time.tm_min) + 60) % 60;
utc_print_time.tm_sec = ((local_print_time.tm_sec + diff_time.tm_sec) + 60) % 60;
utc_print_time.tm_hour = secs / 3600;
utc_print_time.tm_min = (secs / 60) % 60;
utc_print_time.tm_sec = secs % 60;
utc_time = g_strdup_printf ("%02d:%02d:%02d",
utc_print_time.tm_hour,