r15722 - gnucash/trunk/src - Fix Recurrence start-date bugs in conversion of FreqSpecs.

Josh Sled jsled at cvs.gnucash.org
Wed Mar 14 22:41:21 EDT 2007


Author: jsled
Date: 2007-03-14 22:41:20 -0400 (Wed, 14 Mar 2007)
New Revision: 15722
Trac: http://svn.gnucash.org/trac/changeset/15722

Modified:
   gnucash/trunk/src/backend/file/gnc-schedxaction-xml-v2.c
   gnucash/trunk/src/doc/sx.rst
Log:
Fix Recurrence start-date bugs in conversion of FreqSpecs.


Modified: gnucash/trunk/src/backend/file/gnc-schedxaction-xml-v2.c
===================================================================
--- gnucash/trunk/src/backend/file/gnc-schedxaction-xml-v2.c	2007-03-15 02:39:54 UTC (rev 15721)
+++ gnucash/trunk/src/backend/file/gnc-schedxaction-xml-v2.c	2007-03-15 02:41:20 UTC (rev 15722)
@@ -447,6 +447,54 @@
     return sx_set_date( node, sx, xaccSchedXactionSetEndDate );
 }
 
+static void
+_fixup_recurrence_start_dates(GDate *sx_start_date, GList *schedule)
+{
+    GList *iter;
+    for (iter = schedule; iter != NULL; iter = iter->next) {
+        Recurrence *r;
+        GDate start, next;
+
+        r = (Recurrence*)iter->data;
+
+        start = *sx_start_date;
+        g_date_subtract_days(&start, 1);
+
+        g_date_clear(&next, 1);
+
+        recurrenceNextInstance(r, &start, &next);
+
+        if (recurrenceGetPeriodType(r) == PERIOD_MONTH)
+            g_date_set_month(&next, 1);
+
+        {
+            gchar date_str[128];
+            gchar *sched_str;
+
+            g_date_strftime(date_str, 127, "%x", &next);
+            sched_str = recurrenceToString(r);
+            g_debug("setting recurrence [%s] start date to [%s]",
+                    sched_str, date_str);
+            g_free(sched_str);
+        }
+
+        recurrenceSet(r,
+                      recurrenceGetMultiplier(r),
+                      recurrenceGetPeriodType(r), 
+                      &next);
+    }
+
+    if (g_list_length(schedule) == 1
+        && recurrenceGetPeriodType((Recurrence*)g_list_nth_data(schedule, 0)) == PERIOD_ONCE)
+    {
+        char date_buf[128];
+        Recurrence *fixup = (Recurrence*)g_list_nth_data(schedule, 0);
+        g_date_strftime(date_buf, 127, "%x", sx_start_date);
+        recurrenceSet(fixup, 1, PERIOD_ONCE, sx_start_date);
+        g_debug("fixed up period=ONCE Recurrence to date [%s]", date_buf);
+    }
+}
+
 static gboolean
 sx_freqspec_handler( xmlNodePtr node, gpointer sx_pdata )
 {
@@ -461,16 +509,8 @@
     schedule = dom_tree_freqSpec_to_recurrences(node, pdata->book);
     gnc_sx_set_schedule(sx, schedule);
     g_debug("parsed from freqspec [%s]", recurrenceListToString(schedule));
-    if (g_list_length(schedule) == 1
-        && recurrenceGetPeriodType((Recurrence*)g_list_nth_data(schedule, 0)) == PERIOD_ONCE)
-    {
-        char date_buf[128];
-        Recurrence *fixup = (Recurrence*)g_list_nth_data(schedule, 0);
-        g_date_strftime(date_buf, 127, "%x", xaccSchedXactionGetStartDate(sx));
-        recurrenceSet(fixup, 1, PERIOD_ONCE, xaccSchedXactionGetStartDate(sx));
-        g_debug("fixed up period=ONCE Recurrence to date [%s]", date_buf);
-    }
 
+    _fixup_recurrence_start_dates(xaccSchedXactionGetStartDate(sx), schedule);
     pdata->saw_freqspec = TRUE;
 
     return TRUE;

Modified: gnucash/trunk/src/doc/sx.rst
===================================================================
--- gnucash/trunk/src/doc/sx.rst	2007-03-15 02:39:54 UTC (rev 15721)
+++ gnucash/trunk/src/doc/sx.rst	2007-03-15 02:41:20 UTC (rev 15722)
@@ -50,11 +50,13 @@
 
 - bugs
 
-! - [ ] parse from 1.8 file doesn't setup start date correctly;
+! - [ ] with SLR open (with instances), add variables to SX; only newly-created instances will have appropriate variable tables.
+
+! - [x] parse from 1.8 file doesn't setup start date correctly;
     daily-auto-yes-notify.xac has start date of 2006-09-26, but new TXN is
     for $today.
 
-! - [ ] with SLR open (with instances), add variables to SX; only newly-created instances will have appropriate variable tables.
+    - [x] this causes phantom "SX has been changed, confirm cancel?" problems.
 
   - [x] created/review txns disappear, eventual crash [ve20070303]_
 



More information about the gnucash-changes mailing list