Index: libs/std/date.c
===================================================================
RCS file: /cvsroot/neko/libs/std/date.c,v
retrieving revision 1.12
diff -u -r1.12 date.c
--- libs/std/date.c	25 Jun 2008 14:40:15 -0000	1.12
+++ libs/std/date.c	14 Jul 2008 15:56:38 -0000
@@ -43,6 +43,13 @@
 	*r = *r2;
 	return r;
 }
+
+static struct tm *gmtime_r( time_t *t, struct tm *r ) {
+	struct tm *r2 = gmtime(t);
+	if( r2 == NULL ) return NULL;
+	*r = *r2;
+	return r;
+}
 #endif
 
 /**
@@ -207,6 +214,30 @@
 	return r;
 }
 
+/**
+  *  Returns the timezone offset in seconds
+  */
+static value date_get_tz_offset() {
+	struct tm local;
+	struct tm gmt;
+	int diff;
+	time_t raw = time(NULL);
+
+	if (localtime_r(&raw, &local) == NULL || gmtime_r(&raw, &gmt) == NULL)
+		neko_error();
+
+	diff = (gmt.tm_hour - local.tm_hour) * 3600 + (gmt.tm_min - local.tm_min) * 60;
+	
+	// now adjust for different days/years
+	if (gmt.tm_year > local.tm_year || gmt.tm_yday > local.tm_yday) {
+		diff += 86400;
+	} else if (gmt.tm_year < local.tm_year || gmt.tm_yday < local.tm_yday) {
+		diff -= 86400;
+	}
+
+	return alloc_int(diff);
+}
+
 DEFINE_PRIM(date_now,0);
 DEFINE_PRIM(date_new,1);
 DEFINE_PRIM(date_format,2);
@@ -214,5 +245,6 @@
 DEFINE_PRIM(date_set_day,4);
 DEFINE_PRIM(date_get_hour,1);
 DEFINE_PRIM(date_get_day,1);
+DEFINE_PRIM(date_get_tz_offset,0);
 
 /* ************************************************************************ */
