r21560 - gnucash/trunk/src/engine - Add accessor/setter for the date of a GncEntry as a GDate.

Christian Stimming cstim at code.gnucash.org
Fri Nov 11 16:58:05 EST 2011


Author: cstim
Date: 2011-11-11 16:58:04 -0500 (Fri, 11 Nov 2011)
New Revision: 21560
Trac: http://svn.gnucash.org/trac/changeset/21560

Modified:
   gnucash/trunk/src/engine/gncEntry.c
   gnucash/trunk/src/engine/gncEntry.h
Log:
Add accessor/setter for the date of a GncEntry as a GDate.

This is much more suitable to avoid any ambiguities due to differently
chosen time-of-day in various parts of the code.

Modified: gnucash/trunk/src/engine/gncEntry.c
===================================================================
--- gnucash/trunk/src/engine/gncEntry.c	2011-11-11 21:57:52 UTC (rev 21559)
+++ gnucash/trunk/src/engine/gncEntry.c	2011-11-11 21:58:04 UTC (rev 21560)
@@ -445,6 +445,19 @@
     }
 }
 
+void gncEntrySetDateGDate (GncEntry *entry, const GDate* date)
+{
+    if (!entry || !date || !g_date_valid(date))
+        return;
+
+    /* Watch out: Here we are deviating from the initial convention that a
+    GDate always converts to the start time of the day. Instead, the GDate is
+    converted to "noon" on the respective date. This is not nice, but this
+    convention was used for the Timespec of GncEntry all the time, so we better
+    stick to it.*/
+    gncEntrySetDate(entry, timespecCanonicalDayTime(gdate_to_timespec(*date)));
+}
+
 void gncEntrySetDateEntered (GncEntry *entry, Timespec date)
 {
     if (!entry) return;
@@ -804,6 +817,11 @@
     return entry->date;
 }
 
+GDate gncEntryGetDateGDate(const GncEntry *entry)
+{
+    return timespec_to_gdate(gncEntryGetDate(entry));
+}
+
 Timespec gncEntryGetDateEntered (const GncEntry *entry)
 {
     Timespec ts;

Modified: gnucash/trunk/src/engine/gncEntry.h
===================================================================
--- gnucash/trunk/src/engine/gncEntry.h	2011-11-11 21:57:52 UTC (rev 21559)
+++ gnucash/trunk/src/engine/gncEntry.h	2011-11-11 21:58:04 UTC (rev 21560)
@@ -96,6 +96,11 @@
 
 /** @name Generic (shared) data
  @{ */
+/** Set the date of this entry */
+void gncEntrySetDateGDate (GncEntry *entry, const GDate* date);
+/** DEPRECATED - use gncEntrySetDateGDate() instead! (Because the time-of-day
+is a misleading extra information. We are only dealing with the day
+information! */
 void gncEntrySetDate (GncEntry *entry, Timespec date);
 void gncEntrySetDateEntered (GncEntry *entry, Timespec date);
 void gncEntrySetDescription (GncEntry *entry, const char *desc);
@@ -137,6 +142,11 @@
 /* GET FUNCTIONS */
 /** @name Generic (shared) data
  @{ */
+/** Returns the day of this entry */
+GDate gncEntryGetDateGDate (const GncEntry *entry);
+/** DEPRECATED - use gncEntryGetDateGDate() instead! (Because the time-of-day
+is a misleading extra information. We are only dealing with the day
+information! */
 Timespec gncEntryGetDate (const GncEntry *entry);
 Timespec gncEntryGetDateEntered (const GncEntry *entry);
 const char * gncEntryGetDescription (const GncEntry *entry);



More information about the gnucash-changes mailing list