From: Michael R Sweet Date: Mon, 7 Apr 2025 12:27:49 +0000 (-0400) Subject: Update fix for ippDateToTime. X-Git-Tag: v2.4.12~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=efa6ff3bedbf584ba1c52f06cdaebe414d0524c1;p=thirdparty%2Fcups.git Update fix for ippDateToTime. --- diff --git a/cups/ipp.c b/cups/ipp.c index b9f6420a56..283e386b6e 100644 --- a/cups/ipp.c +++ b/cups/ipp.c @@ -1713,25 +1713,42 @@ ippDateToTime(const ipp_uchar_t *date) /* I - RFC 2579 date info */ #if _WIN32 if ((t = _mkgmtime(&unixdate)) < 0) return (0); + #elif defined(HAVE_TIMEGM) if ((t = timegm(&unixdate)) < 0) return (0); + #else if ((t = mktime(&unixdate)) < 0) return (0); # if defined(HAVE_TM_GMTOFF) - localtime_r(&t, &unixdate); - t -= unixdate.tm_gmtoff; + /* + * Adjust the time value using the "tm_gmtoff" and "tm_isdst" members. As + * noted by M-HT on Github, this DST hack will fail in timezones where the + * DST offset is not one hour, such as Australia/Lord_Howe. Fortunately, + * this is unusual and most systems support the "timegm" function... + */ + + t += unixdate.tm_gmtoff - 3600 * unixdate.tm_isdst; # else - t -= timezone; + /* + * Adjust the time value using the even more legacy "timezone" variable, + * which also reflects any DST offset... + */ + + t += timezone; # endif // HAVE_TM_GMTOFF #endif // _WIN32 + /* + * Subtract the UTC timezone offset to get the actual time_t value... + */ + if (date[8] == '-') - t += date[9] * 3600 + date[10] * 60; + t += date[9] * 3600 + date[10] * 60;/* "t - -offset" is "t + offset" */ else - t -= date[9] * 3600 + date[10] * 60; + t -= date[9] * 3600 + date[10] * 60;/* "t - offset" */ return (t); }