Date: Mon, 24 Jul 2000 22:07:47 +0000 From: pdp@nl.demon.net To: FreeBSD-gnats-submit@freebsd.org Subject: misc/20159: strftime() can't produce ISO8601 format timezone representation Message-ID: <E13GqO3-000HRe-00@samhain.noc.nl.demon.net>
next in thread | raw e-mail | index | archive | help
>Number: 20159 >Category: misc >Synopsis: strftime() can't produce ISO8601 format timezone representation >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Mon Jul 24 15:10:01 PDT 2000 >Closed-Date: >Last-Modified: >Originator: Phil Pennock >Release: FreeBSD 3.5-STABLE i386 >Organization: Demon Internet Netherlands >Environment: >Description: ISO 8601 defines date and time representations. See <http://www.iso.ch/markete/8601.pdf> It defines formats for representation of timezone. The one of interest is the [+-]nnnn representation, as used in various email headers. strftime() does not currently provide a way to get this, leaving it to the programmer to roll their own wrapper. Since %Z gives timezone, and %z is available for use, the patch below (against 3.5-STABLE) for /usr/src/lib/libc/stdtime/strftime.c will add the desired functionality, provided that ISO8601_TIMEZONES is defined. This is experimental, and there is no bounds checking for bad values in the struct tm, so the patch does nothing to define ISO8601_TIMEZONES. >How-To-Repeat: Use strftime(3). >Fix: --- /usr/src/lib/libc/stdtime/strftime.c Tue Mar 14 21:54:50 2000 +++ strftime.c Mon Jul 24 23:54:12 2000 @@ -388,6 +388,31 @@ pt = _conv(t->tm_year + TM_YEAR_BASE, "%04d", pt, ptlim); continue; +#ifdef ISO8601_TIMEZONES + case 'z': + { + long offabs; + int offhr; + int offmin; + char offsign[2]; + + offsign[1] = '\0'; + if (t->tm_gmtoff < 0) { + *offsign = '-'; + offabs = - t->tm_gmtoff; + } else { + *offsign = '+'; + offabs = t->tm_gmtoff; + } + offhr = offabs / 3600; + offmin = (offabs - offhr*3600) / 60; + + pt = _add(offsign, pt, ptlim); + pt = _conv(offhr, "%02d", pt, ptlim); + pt = _conv(offmin, "%02d", pt, ptlim); + } + continue; +#endif /* defined ISO8601_TIMEZONES */ case 'Z': if (t->tm_zone != NULL) pt = _add(t->tm_zone, pt, ptlim); >Release-Note: >Audit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?E13GqO3-000HRe-00>