git: 9front

Download patch

ref: db8b443588db1c9644c58adef5f4a581b8be690d
parent: b8d3b7d0a164f8927f01bde90566674ca04c5c12
author: cinap_lenrek <cinap_lenrek@gmx.de>
date: Sat Aug 10 22:19:02 EDT 2013

tm2sec: assume local timezone when Tm.zone[0] == 0 (fixes dossrv, zipfs timestamps)

from the manual:

Tm2sec converts a broken-down time to seconds since the
start of the epoch.  It ignores wday, and assumes the local
time zone if zone is not GMT.

so we can assume localtime if Tm.zone is not set to GMT.

all code that wants no localtime conversion should set
Tm.zone explicitely to GMT. (see previous commits)

tm2sec() now does the reverse of localtime() when Tm.zone[0] == 0
which seems to be what the calling code (dossrv, zipfs) assumes.
this also makes sense because theres no simple way todo it
outside of libc as theres otherwise no access to the timezone
structure with the daylight saving periods.

--- a/sys/src/libc/9sys/tm2sec.c
+++ b/sys/src/libc/9sys/tm2sec.c
@@ -50,7 +50,7 @@
 long
 tm2sec(Tm *tm)
 {
-	long secs;
+	long secs, *p;
 	int i, yday, year, *d2m;
 
 	if(strcmp(tm->zone, "GMT") != 0 && timezone.stname[0] == 0)
@@ -95,8 +95,16 @@
 		secs -= timezone.stdiff;
 	else if(strcmp(tm->zone, timezone.dlname) == 0)
 		secs -= timezone.dldiff;
-	if(secs < 0)
-		secs = 0;
+	else if(tm->zone[0] == 0){
+		secs -= timezone.dldiff;
+		for(p = timezone.dlpairs; *p; p += 2)
+			if(secs >= p[0] && secs < p[1])
+				break;
+		if(*p == 0){
+			secs += timezone.dldiff;
+			secs -= timezone.stdiff;
+		}
+	}
 	return secs;
 }
 
--