make %z portable

This commit is contained in:
Daniel Stenberg 2025-08-01 16:56:00 +02:00
parent 3c92c60a1f
commit 958b3c1105
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
3 changed files with 13 additions and 8 deletions

View file

@ -532,4 +532,4 @@ from UTC). As time is always UTC, this outputs `+0000`.
## `%Z`
The timezone name, meaning `UTC`.
The timezone name. For some reason `GMT`.

View file

@ -584,13 +584,18 @@ static const char *outtime(const char *ptr, /* %time{ ... */
curlx_dyn_init(&format, 1024);
/* insert sub-seconds for %f */
/* insert +0000 for %z because it is otherwise not portable */
for(i = 0; !result && i < vlen; i++) {
if((i < vlen - 1) && ptr[i] == '%' && ptr[i + 1] == 'f') {
result = curlx_dyn_addf(&format, "%06u", usecs);
if((i < vlen - 1) && ptr[i] == '%' &&
((ptr[i + 1] == 'f') || (ptr[i + 1] == 'z'))) {
if(ptr[i + 1] == 'f')
result = curlx_dyn_addf(&format, "%06u", usecs);
else
result = curlx_dyn_addn(&format, "+0000", 5);
i++;
continue;
}
result = curlx_dyn_addn(&format, &ptr[i], 1);
else
result = curlx_dyn_addn(&format, &ptr[i], 1);
}
if(!result) {
/* !checksrc! disable BANNEDFUNC 1 */

View file

@ -38,10 +38,10 @@ http
Debug
</features>
<setenv>
CURL_TIME=1754037100
CURL_TIME=1754037103
</setenv>
<command>
http://%HOSTIP:%HTTPPORT/%TESTNUMBER --write-out='Time: %time{%d/%b/%Y %H:%M:%S.%f %z}\n' -s -o %LOGDIR/dump
http://%HOSTIP:%HTTPPORT/%TESTNUMBER --write-out='Time: %time{%d/%b/%Y %H:%M:%S.%f %z %Z}\n' -s -o %LOGDIR/dump
</command>
</client>
@ -56,7 +56,7 @@ Accept: */*
</protocol>
<stdout mode="text">
Time: 01/Aug/2025 08:31:40.037100 +0000
Time: 01/Aug/2025 08:31:43.037103 +0000 GMT
</stdout>
</verify>
</testcase>