r15499 - gnucash/trunk - Remove basically-unused qof date manipulation code better provided by GDate.

Josh Sled jsled at cvs.gnucash.org
Sun Feb 4 11:50:28 EST 2007


Author: jsled
Date: 2007-02-04 11:50:27 -0500 (Sun, 04 Feb 2007)
New Revision: 15499
Trac: http://svn.gnucash.org/trac/changeset/15499

Modified:
   gnucash/trunk/lib/libqof/qof/gnc-date.c
   gnucash/trunk/lib/libqof/qof/gnc-date.h
   gnucash/trunk/src/gnome/window-reconcile.c
Log:
Remove basically-unused qof date manipulation code better provided by GDate.


Modified: gnucash/trunk/lib/libqof/qof/gnc-date.c
===================================================================
--- gnucash/trunk/lib/libqof/qof/gnc-date.c	2007-02-04 15:21:10 UTC (rev 15498)
+++ gnucash/trunk/lib/libqof/qof/gnc-date.c	2007-02-04 16:50:27 UTC (rev 15499)
@@ -297,41 +297,6 @@
   return(tm->tm_mday == date_get_last_mday(tm));
 }
 
-/* Add a number of months to a time value
-
- Add a number of months to a time value, and normalize.  Optionally
- also track the last day of the month, i.e. 1/31 -> 2/28 -> 3/30.
-
-param  tm: base time value
-param  months: The number of months to add to this time
-param  track_last_day: Coerce the date value if necessary.
-
-return void
-*/
-void date_add_months (struct tm *tm, int months, gboolean track_last_day)
-{
-  gboolean was_last_day;
-  int new_last_mday;
-
-  /* Have to do this now */
-  was_last_day = date_is_last_mday(tm);
-
-  /* Add in the months and normalize */
-  tm->tm_mon += months;
-  while (tm->tm_mon > 11) {
-    tm->tm_mon -= 12;
-    tm->tm_year++;
-  }
-
-  if (!track_last_day)
-    return;
-
-  /* Track last day of the month, i.e. 1/31 -> 2/28 -> 3/31 */
-  new_last_mday = date_get_last_mday(tm);
-  if (was_last_day || (tm->tm_mday > new_last_mday))
-    tm->tm_mday = new_last_mday;
-}
-
 /* Return the set dateFormat.
 
 return QofDateFormat: enumeration indicating preferred format
@@ -1429,61 +1394,5 @@
   return mktime(&tm);
 }
 
-gboolean
-qof_date_add_days(Timespec *ts, gint days)
-{
-	struct tm tm;
-	time_t    tt;
-
-	g_return_val_if_fail(ts, FALSE);
-	tt = timespecToTime_t(*ts);
-#ifdef HAVE_GMTIME_R
-	tm = *gmtime_r(&tt, &tm);
-#else
-	tm = *gmtime(&tt);
-#endif
-	tm.tm_mday += days;
-	/* let mktime normalise the months and year
-	because we aren't tracking last_day_of_month */
-	tt = mktime(&tm);
-	if(tt < 0) { return FALSE; }
-	timespecFromTime_t(ts, tt);
-	return TRUE;
-}
-
-gboolean
-qof_date_add_months(Timespec *ts, gint months, gboolean track_last_day)
-{
-	struct tm tm;
-	time_t    tt;
-	gint new_last_mday;
-	gboolean was_last_day;
-
-	g_return_val_if_fail(ts, FALSE);
-	tt = timespecToTime_t(*ts);
-#ifdef HAVE_GMTIME_R
-	tm = *gmtime_r(&tt, &tm);
-#else
-	tm = *gmtime(&tt);
-#endif
-	was_last_day = date_is_last_mday(&tm);
-	tm.tm_mon += months;
-	while (tm.tm_mon > 11) {
-		tm.tm_mon -= 12;
-		tm.tm_year++;
-	}
-	if (track_last_day) {
-		/* Track last day of the month, i.e. 1/31 -> 2/28 -> 3/31 */
-		new_last_mday = date_get_last_mday(&tm);
-		if (was_last_day || (tm.tm_mday > new_last_mday)) {
-			tm.tm_mday = new_last_mday;
-		}
-	}
-	tt = mktime(&tm);
-	if(tt < 0) { return FALSE; }
-	timespecFromTime_t(ts, tt);
-	return TRUE;
-}
-
 /********************** END OF FILE *********************************\
 \********************************************************************/

Modified: gnucash/trunk/lib/libqof/qof/gnc-date.h
===================================================================
--- gnucash/trunk/lib/libqof/qof/gnc-date.h	2007-02-04 15:21:10 UTC (rev 15498)
+++ gnucash/trunk/lib/libqof/qof/gnc-date.h	2007-02-04 16:50:27 UTC (rev 15499)
@@ -243,28 +243,6 @@
  * routine might return incorrect values for dates before 1970.  */
 void gnc_timespec2dmy (Timespec ts, gint *day, gint *month, gint *year);
 
-/** \brief Add a number of days to a Timespec and normalise.
-
-Together with qof_date_add_months, replaces date_add_months.
-
-\return FALSE on error, otherwise TRUE.
-*/
-gboolean qof_date_add_days(Timespec *ts, gint days);
-
-/** \brief Add a number of months to a Timespec and normalise.
-
-Optionally track the last day of the month so that adding one
-month to 31st January returns 28th February (29th in a leap year)
-and adding three months returns 30th April.
-
-\return FALSE on error, otherwise TRUE.
-*/
-gboolean qof_date_add_months(Timespec *ts, gint months, gboolean track_last_day);
-
-/** \deprecated Add a number of months to a time value and normalize.  Optionally
- * also track the last day of the month, i.e. 1/31 -> 2/28 -> 3/31. */
-void date_add_months (struct tm *tm, gint months, gboolean track_last_day);
-
 /** \warning hack alert XXX FIXME -- these date routines return incorrect
  * values for dates before 1970.  Most of them are good only up 
  * till 2038.  This needs fixing ... 

Modified: gnucash/trunk/src/gnome/window-reconcile.c
===================================================================
--- gnucash/trunk/src/gnome/window-reconcile.c	2007-02-04 15:21:10 UTC (rev 15498)
+++ gnucash/trunk/src/gnome/window-reconcile.c	2007-02-04 16:50:27 UTC (rev 15499)
@@ -1284,30 +1284,27 @@
                         gnc_numeric *new_ending,
                         time_t *statement_date)
 {
+  GDate date;
   time_t today;
   struct tm tm;
 
+  g_date_clear(&date, 1);
+
   if (xaccAccountGetReconcileLastDate (account, statement_date))
   {
     int months = 1, days = 0;
 
-    tm = * localtime (statement_date);
+    g_date_set_time_t(&date, *statement_date);
 
-    /* How far should the date be moved?  Args unchanged on failure. */
     xaccAccountGetReconcileLastInterval (account, &months, &days);
 
     if (months) {
-      /*
-       * Add in the months and normalize
-       */
-      date_add_months(&tm, months, TRUE);
+      g_date_add_months(&date, months);
     } else {
-      /*
-       * Add in the days (weeks if multiple of seven).
-       */
-      tm.tm_mday += days;
+      g_date_add_days(&date, days);
     }
-    tm.tm_isdst = -1;
+
+    g_date_to_struct_tm(&date, &tm);
     gnc_tm_set_day_end (&tm);
     *statement_date = mktime (&tm);
 



More information about the gnucash-changes mailing list