r23670 - gnucash/trunk/src/libqof/qof - Bug 721251 - Incorrect Transaction Dates

John Ralls jralls at code.gnucash.org
Sun Jan 5 15:42:38 EST 2014


Author: jralls
Date: 2014-01-05 15:42:38 -0500 (Sun, 05 Jan 2014)
New Revision: 23670
Trac: http://svn.gnucash.org/trac/changeset/23670

Modified:
   gnucash/trunk/src/libqof/qof/gnc-date.c
Log:
Bug 721251 - Incorrect Transaction Dates

Fix g_gnc_time_zone_adjust_for_dst to handle southern-hemisphere DST

Modified: gnucash/trunk/src/libqof/qof/gnc-date.c
===================================================================
--- gnucash/trunk/src/libqof/qof/gnc-date.c	2014-01-05 20:14:00 UTC (rev 23669)
+++ gnucash/trunk/src/libqof/qof/gnc-date.c	2014-01-05 20:42:38 UTC (rev 23670)
@@ -118,27 +118,53 @@
 #endif
 }
 
+#ifdef G_OS_WIN32
+static gboolean
+win32_in_dst (GDateTime *date, TIME_ZONE_INFORMATION *tzinfo)
+{
+    guint year, month, day;
+    SYSTEMTIME *std, *dlt;
+
+    if (tzinfo == NULL || tzinfo->StandardDate.wMonth == 0)
+      return FALSE;
+
+    year = g_date_time_get_year (date);
+    month = g_date_time_get_month (date);
+    day = g_date_time_get_day_of_month (date);
+
+    std = &(tzinfo->StandardDate);
+    dlt = &(tzinfo->DaylightDate);
+
+    if (std->wMonth < dlt->wMonth)
+    {
+         if ((month > dlt->wMonth || month < std->wMonth) ||
+	     (month == dlt->wMonth && day > dlt->wDay) ||
+	     (month == std->wMonth && day < std->wDay))
+	     return TRUE;
+    }
+    else
+    {
+         if ((month > dlt->wMonth && month < std->wMonth) ||
+	     (month == dlt->wMonth && day > dlt->wDay) ||
+	     (month == std->wMonth && day < std->wDay))
+	     return TRUE;
+    }
+    return FALSE;
+}
+#endif
+
 static GTimeZone*
 gnc_g_time_zone_adjust_for_dst (GTimeZone* tz, GDateTime *date)
 {
 #ifdef G_OS_WIN32
     TIME_ZONE_INFORMATION tzinfo;
     gint64 dst = GetTimeZoneInformation (&tzinfo);
-    guint year = g_date_time_get_year (date);
-    guint month = g_date_time_get_month (date);
-    guint day = g_date_time_get_day_of_month (date);
     gint bias, hours, minutes;
     gchar *tzstr;
     g_return_val_if_fail (date != NULL, NULL);
-    if (dst > 0 && tzinfo.StandardDate.wMonth > 0
-	&& ((month > tzinfo.DaylightDate.wMonth
-	     && month < tzinfo.StandardDate.wMonth)
-	    || (month == tzinfo.DaylightDate.wMonth
-		&& day >= tzinfo.DaylightDate.wDay)
-	    || (month == tzinfo.StandardDate.wMonth
-		&& day < tzinfo.StandardDate.wDay)))
+    if (dst > 0 && win32_in_dst (date, &tzinfo))
     {
-	g_time_zone_unref (tz);
+        g_time_zone_unref (tz);
 	bias = tzinfo.Bias + tzinfo.DaylightBias;
 	hours = -bias / 60; // 60 minutes per hour
 	minutes = (bias < 0 ? -bias : bias) % 60;



More information about the gnucash-changes mailing list