Bug fixing:

- fix bug in weekly-freqspec parsing
- fix bug in date computation
- fix ages-old bug in "once" FreqSpecs :(
Update todo.


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@15603 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Joshua Sled
2007-02-18 19:32:07 +00:00
parent 47a10cabf8
commit 41089913e2
3 changed files with 37 additions and 23 deletions

View File

@@ -135,6 +135,7 @@ typedef struct
gint64 day; /* monthly or month-relative */
gint64 occurrence; /* month-relative */
GList *list; /* composite */
UIFreqType uift;
} fsParseData;
static void
@@ -302,6 +303,7 @@ fs_uift_handler( xmlNodePtr node, gpointer data)
for ( i=0; (tmp = uiFreqTypeStrs[i].str) != NULL; i++ ) {
if ( safe_strcmp( nodeTxt, tmp ) == 0 ) {
xaccFreqSpecSetUIType( fspd->fs, uiFreqTypeStrs[i].uift );
fspd->uift = uiFreqTypeStrs[i].uift;
g_free( nodeTxt );
return TRUE;
}
@@ -436,14 +438,6 @@ struct dom_tree_handler fs_union_dom_handlers[] = {
{ NULL, NULL, 0, 0 },
};
static void
compute_date(fsParseData *parsed, GDate *date)
{
g_date_clear(date, 1);
g_date_set_dmy(date, 1, 1, 1970);
g_date_add_days(date, parsed->offset);
}
static gboolean
fs_none_handler( xmlNodePtr node, gpointer data )
{
@@ -472,7 +466,6 @@ fs_once_handler( xmlNodePtr node, gpointer data )
return FALSE;
recurrenceSet(fspd->recurrence, 0, PERIOD_ONCE, &fspd->once_day);
fspd->fs->type = ONCE;
fspd->fs->s.once.date = fspd->once_day;
return TRUE;
@@ -488,7 +481,8 @@ fs_daily_handler(xmlNodePtr node, gpointer data)
if (!successful)
return FALSE;
compute_date(fspd, &offset_date);
g_date_clear(&offset_date, 1);
g_date_set_julian(&offset_date, fspd->offset);
recurrenceSet(fspd->recurrence, fspd->interval, PERIOD_DAY, &offset_date);
fspd->fs->type = DAILY;
@@ -510,8 +504,9 @@ fs_weekly_handler( xmlNodePtr node, gpointer data )
if ( !successful )
return FALSE;
compute_date(fspd, &offset_date);
recurrenceSet(fspd->recurrence, fspd->interval, PERIOD_DAY, &offset_date);
g_date_clear(&offset_date, 1);
g_date_set_julian(&offset_date, fspd->offset);
recurrenceSet(fspd->recurrence, fspd->interval, PERIOD_WEEK, &offset_date);
fspd->fs->type = WEEKLY;
fspd->fs->s.weekly.interval_weeks = fspd->interval;
@@ -532,10 +527,21 @@ fs_monthly_handler( xmlNodePtr node, gpointer data)
fspd );
if ( !successful )
return FALSE;
compute_date(fspd, &offset_date);
g_date_clear(&offset_date, 1);
g_date_set_julian(&offset_date, 1);
g_date_add_months(&offset_date, fspd->offset);
g_date_set_day(&offset_date, fspd->day);
recurrenceSet(fspd->recurrence, fspd->interval, PERIOD_MONTH, &offset_date);
if (fspd->uift == UIFREQ_ONCE)
{
// hack...
recurrenceSet(fspd->recurrence, fspd->interval, PERIOD_ONCE, &offset_date);
}
else
{
recurrenceSet(fspd->recurrence, fspd->interval, PERIOD_MONTH, &offset_date);
}
fspd->fs->type = MONTHLY;
fspd->fs->s.monthly.interval_months = fspd->interval;

View File

@@ -287,11 +287,10 @@ sx_name_handler( xmlNodePtr node, gpointer sx_pdata )
struct sx_pdata *pdata = sx_pdata;
SchedXaction *sx = pdata->sx;
gchar *tmp = dom_tree_to_text( node );
g_debug("sx named [%s]", tmp);
g_return_val_if_fail( tmp, FALSE );
xaccSchedXactionSetName( sx, tmp );
g_free( tmp );
return TRUE;
}
@@ -431,13 +430,20 @@ sx_freqspec_handler( xmlNodePtr node, gpointer sx_pdata )
g_return_val_if_fail( node, FALSE );
xaccSchedXactionSetFreqSpec(sx, dom_tree_to_freqSpec(node, pdata->book));
schedule = dom_tree_freqSpec_to_recurrences(node, pdata->book);
gnc_sx_set_schedule(sx, schedule);
for (; schedule != NULL; schedule = schedule->next)
g_debug("parsed from freqspec [%s]", recurrenceListToString(schedule));
if (g_list_length(schedule) == 1
&& recurrenceGetPeriodType((Recurrence*)g_list_nth_data(schedule, 0)) == PERIOD_ONCE)
{
g_debug("parsed from freqspec [%s]", recurrenceToString((Recurrence*)schedule->data));
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);
}
pdata->saw_freqspec = TRUE;
return TRUE;

View File

@@ -113,14 +113,16 @@ TODO
- use Recurrence instead of FreqSpec
! - [ ] XML migration, handling
- xml:freqSpec -> obj:Recurrence
- [ ] none (Recurrence doesn't support)
- [x] none (Recurrence doesn't support)
- [x] once
- [x] if once, fix Recurrence date to be SX start date. :p
- [x] daily
- [ ] daily [m-f] (composite)
- [x] daily [m-f] (composite)
- [x] weekly, single
- [ ] weekly, multiple (composite)
- [x] weekly, multiple (composite)
- [x] monthly (+quarterly, tri-anually, semi-annually, yearly)
- [ ] semi-monthly (composite)
- [x] semi-monthly (composite)
- [ ] write Recurrences into new-version SX
- gnc-frequency
! - [x] Support Recurrence
- [x] in