diff --git a/src/xpdev/datewrap.c b/src/xpdev/datewrap.c
index 3c055e2fc1a231ad2a1a7256dfc03901737ddde6..ac9b0d3e085326075a77b14bd2c7449ac22effe6 100644
--- a/src/xpdev/datewrap.c
+++ b/src/xpdev/datewrap.c
@@ -8,7 +8,7 @@
  * @format.tab-size 4		(Plain Text/Source Code File Header)			*
  * @format.use-tabs true	(see http://www.synchro.net/ptsc_hdr.html)		*
  *																			*
- * Copyright 2011 Rob Swindell - http://www.synchro.net/copyright.html		*
+ * Copyright Rob Swindell - http://www.synchro.net/copyright.html			*
  *																			*
  * This library is free software; you can redistribute it and/or			*
  * modify it under the terms of the GNU Lesser General Public License		*
@@ -64,6 +64,18 @@ time_t DLLCALL sane_mktime(struct tm* tm)
 	return mktime(tm);
 }
 
+/* Compensates for struct tm "weirdness" */
+time_t DLLCALL sane_timegm(struct tm* tm)
+{
+	if(tm->tm_year>=1900)
+		tm->tm_year-=1900;
+	if(tm->tm_mon)		/* Month is zero-based */
+		tm->tm_mon--;
+	tm->tm_isdst=0;		/* Don't adjust for DST */
+
+	return timegm(tm);
+}
+
 time32_t DLLCALL time32(time32_t* tp)
 {
 	time_t t;
diff --git a/src/xpdev/datewrap.h b/src/xpdev/datewrap.h
index 34b967c298b80f9e36dd34e569e49432fc098ec8..7ffd3cbff53320374aca5c864d953304a2f3686f 100644
--- a/src/xpdev/datewrap.h
+++ b/src/xpdev/datewrap.h
@@ -8,7 +8,7 @@
  * @format.tab-size 4		(Plain Text/Source Code File Header)			*
  * @format.use-tabs true	(see http://www.synchro.net/ptsc_hdr.html)		*
  *																			*
- * Copyright 2011 Rob Swindell - http://www.synchro.net/copyright.html		*
+ * Copyright Rob Swindell - http://www.synchro.net/copyright.html			*
  *																			*
  * This library is free software; you can redistribute it and/or			*
  * modify it under the terms of the GNU Lesser General Public License		*
@@ -47,8 +47,9 @@ extern "C" {
 /* Return difference (in seconds) in time() result from standard (0 on success) */
 DLLEXPORT time_t		DLLCALL		checktime(void);
 
-/* Implementation of mktime() that handles common tm element conversions for you */
+/* Implementation of mktime()/timegm() that handles common tm element conversions for you */
 DLLEXPORT time_t		DLLCALL		sane_mktime(struct tm*);
+DLLEXPORT time_t		DLLCALL		sane_timegm(struct tm*);
 
 /* Legacy (32-bit time_t) versions of time() and mktime() */
 DLLEXPORT time32_t		DLLCALL		time32(time32_t* tp);
@@ -71,6 +72,11 @@ DLLEXPORT struct tm*	DLLCALL		localtime32(const time32_t* t, struct tm* tm);
 
 #endif
 
+/* Microsoft's equivalent of GLIBC/BSD timegm() */
+#ifdef _MSC_VER
+	#define timegm _mkgmtime
+#endif
+
 /***********************************/
 /* Borland DOS date/time functions */
 /***********************************/