On 2003-07-31 14:37:19 +0200, Heiko Oberdiek wrote:
In my manual page it was marked as glibc extension, so other systems without can miss support of %z. How the time zone difference can be calculated there in a save way? Have to be used the following procedure or are there better ways?
There is. :-) <quote src=utils.c#13> The main difficulty is get the time zone offset. strftime() does this in ISO C99 (e.g. newer glibc) with %z, but we have to work with other systems (e.g. Solaris 2.5). So we must use localtime(), which sets the external variable timezone (either int or time_t) to the seconds since UTC. */ void printcreationdate() { time_t t; struct tm *tt; size_t size; char time_str[40]; int hours, minutes; /* get the time */ t = time(NULL); tt = localtime(&t); size = strftime(time_str, sizeof(time_str), "%Y%m%d%H%M%S", tt); /* expected format: "YYYYmmddHHMMSS" */ /* correction for seconds: %S can be in range 00..61, the PDF reference expects 00..59, therefore we map "60" and "61" to "59" */ if (time_str[12] == '6' && time_str[13] != 0) { time_str[12] == '5'; time_str[13] == '9'; } /* get the time zone offset */ hours = ((long int)timezone)/3600; minutes = labs((long int)timezone) - (abs(hours) * 3600L); sprintf (&time_str[size], "%+03i'%02d'", hours, minutes); /* print result */ pdf_printf("/CreationDate (D:%s)\n", time_str); } </quote> The offset is off by one hour on Suse 7.0/7.1, but I regard this as a minor misfeature. :-) Best regards Martin -- Martin Schröder, MS@ArtCom-GmbH.DE ArtCom GmbH, Lise-Meitner-Str 5, 28359 Bremen, Germany Voice +49 421 20419-44 / Fax +49 421 20419-10