From owner-freebsd-bugs Mon Jul 24 15:10: 8 2000 Delivered-To: freebsd-bugs@freebsd.org Received: from freefall.freebsd.org (freefall.FreeBSD.ORG [204.216.27.21]) by hub.freebsd.org (Postfix) with ESMTP id 9EF5937BD0A for ; Mon, 24 Jul 2000 15:10:04 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.9.3/8.9.2) id PAA15995; Mon, 24 Jul 2000 15:10:04 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: from hermes.mail.nl.demon.net (hermes.mail.nl.demon.net [194.159.72.197]) by hub.freebsd.org (Postfix) with ESMTP id C663E37BBBF for ; Mon, 24 Jul 2000 15:07:59 -0700 (PDT) (envelope-from pdp@nl.demon.net) Received: from samhain.noc.nl.demon.net ([194.159.72.214] ident=exim) by hermes.mail.nl.demon.net with esmtp (Exim 3.16 #1) id 13GqO4-000M94-00 for FreeBSD-gnats-submit@freebsd.org; Tue, 25 Jul 2000 00:07:48 +0200 Received: from pdp by samhain.noc.nl.demon.net with local id 13GqO3-000HRe-00 for FreeBSD-gnats-submit@freebsd.org; Mon, 24 Jul 2000 22:07:47 +0000 Message-Id: Date: Mon, 24 Jul 2000 22:07:47 +0000 From: pdp@nl.demon.net Reply-To: pdp@nl.demon.net To: FreeBSD-gnats-submit@freebsd.org X-Send-Pr-Version: 3.2 Subject: misc/20159: strftime() can't produce ISO8601 format timezone representation Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org >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 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