Skip site navigation (1)Skip section navigation (2)
Date:      Tue,  9 Apr 2002 23:24:34 -0700 (PDT)
From:      Sean Chittenden <sean@chittenden.org>
To:        FreeBSD-gnats-submit@FreeBSD.org
Subject:   ports/36954: PostgreSQL daylight savings fix...
Message-ID:  <20020410062434.F40E220F0A@mail.tgd.net>

next in thread | raw e-mail | index | archive | help

>Number:         36954
>Category:       ports
>Synopsis:       PostgreSQL daylight savings fix...
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-ports
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Apr 09 23:30:01 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     Sean Chittenden
>Release:        FreeBSD 4.5-STABLE i386
>Organization:
>Environment:
System: FreeBSD ninja1.internal 4.5-STABLE FreeBSD 4.5-STABLE #0: Fri Apr 5 18:08:12 PST 2002 root@ninja1.internal:/opt/obj/opt/src/sys/NINJA i386


	
>Description:
	PostgreSQL does not currently check the results of mktime().  On a
	border condition, mktime() fails and would populate invalid data
	into the database.

	Most other *NIX's seem to automatically account for this and
	automatically adjust the value when it gets passed to mktime(&tm).
	Should FreeBSD have it's mktime() in libc updated?
>How-To-Repeat:
	CREATE TABEL tt ( tt TIMESTAMP );
	INSERT INTO tt VALUES ('2002-4-7 2:0:0.0');
>Fix:
	Please add the following as a patch (databases/postgresql7/files/patch-ak-src::backend::utils::adt::datetime.c).


Index: src/backend/utils/adt/datetime.c
===================================================================
RCS file: /projects/cvsroot/pgsql/src/backend/utils/adt/datetime.c,v
retrieving revision 1.88
diff -u -r1.88 datetime.c
--- src/backend/utils/adt/datetime.c	2002/02/25 16:17:04	1.88
+++ src/backend/utils/adt/datetime.c	2002/04/10 06:12:45
@@ -1439,6 +1439,7 @@
 DetermineLocalTimeZone(struct tm * tm)
 {
 	int			tz;
+	time_t			t;
 
 	if (HasCTZSet)
 		tz = CTimeZone;
@@ -1463,7 +1464,23 @@
 		/* indicate timezone unknown */
 		tmp->tm_isdst = -1;
 
-		mktime(tmp);
+		t = mktime(tmp);
+		if (t == -1)
+		{
+			/* Bump time up by an hour to see if time was an
+			 * invalid time during a daylight savings switch */
+			tmp->tm_hour += 1;
+			t = mktime(tmp);
+
+			/* Assume UTC if mktime() still fails.
+			 *
+			 * If mktime() was successful with the adjusted time,
+			 * adjust the real time object. */
+			if (t == -1)
+				return 0;
+			else
+				tm->tm_hour += 1;
+		}
 
 		tm->tm_isdst = tmp->tm_isdst;
 
>Release-Note:
>Audit-Trail:
>Unformatted:

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-ports" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020410062434.F40E220F0A>