From pdp@nl.demon.net  Mon Jul 24 15:08:06 2000
Return-Path: <pdp@nl.demon.net>
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 <FreeBSD-gnats-submit@freebsd.org>; 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: <E13GqO3-000HRe-00@samhain.noc.nl.demon.net>
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
Subject: strftime() can't produce ISO8601 format timezone representation
X-Send-Pr-Version: 3.2

>Number:         20159
>Category:       misc
>Synopsis:       strftime() can't produce ISO8601 format timezone representation
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Mon Jul 24 15:10:01 PDT 2000
>Closed-Date:    Fri Aug 09 16:59:04 PDT 2002
>Last-Modified:  Fri Aug 09 16:59:04 PDT 2002
>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:
State-Changed-From-To: open->closed 
State-Changed-By: iedowse 
State-Changed-When: Fri Aug 9 16:57:24 PDT 2002 
State-Changed-Why:  

A similar change to this was made quite some time ago. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=20159 
>Unformatted:
