r21559 - gnucash/trunk/src/libqof/qof - Add two more helper functions dealing with GDate.
Christian Stimming
cstim at code.gnucash.org
Fri Nov 11 16:57:53 EST 2011
Author: cstim
Date: 2011-11-11 16:57:52 -0500 (Fri, 11 Nov 2011)
New Revision: 21559
Trac: http://svn.gnucash.org/trac/changeset/21559
Modified:
gnucash/trunk/src/libqof/qof/gnc-date.c
gnucash/trunk/src/libqof/qof/gnc-date.h
Log:
Add two more helper functions dealing with GDate.
In particular, glib doesn't offer a function for easily accessing
the "today" date as a GDate. What a pity. It's added now as gnc_g_date_new_today().
Modified: gnucash/trunk/src/libqof/qof/gnc-date.c
===================================================================
--- gnucash/trunk/src/libqof/qof/gnc-date.c 2011-11-11 16:31:13 UTC (rev 21558)
+++ gnucash/trunk/src/libqof/qof/gnc-date.c 2011-11-11 21:57:52 UTC (rev 21559)
@@ -1476,6 +1476,15 @@
return gnc_dmy2timespec_internal (day, month, year, TRUE);
}
+GDate gnc_dmy2gdate (gint day, gint month, gint year)
+{
+ GDate result;
+ g_date_set_day (&result, day);
+ g_date_set_month (&result, month);
+ g_date_set_year (&result, year);
+ return result;
+}
+
Timespec
gnc_dmy2timespec_end (int day, int month, int year)
{
@@ -1542,6 +1551,13 @@
return result;
}
+GDate* gnc_g_date_new_today ()
+{
+ GDate *result = g_date_new();
+ g_date_set_time_t(result, time(NULL));
+ return result;
+}
+
Timespec gdate_to_timespec (GDate d)
{
return gnc_dmy2timespec(g_date_get_day(&d),
Modified: gnucash/trunk/src/libqof/qof/gnc-date.h
===================================================================
--- gnucash/trunk/src/libqof/qof/gnc-date.h 2011-11-11 16:31:13 UTC (rev 21558)
+++ gnucash/trunk/src/libqof/qof/gnc-date.h 2011-11-11 21:57:52 UTC (rev 21559)
@@ -221,12 +221,20 @@
/** Turns a Timespec into a time_t */
time_t timespecToTime_t (Timespec ts);
+/** Returns a newly allocated date of the current clock time, taken from
+ * time(2). The caller must g_date_free() the object afterwards. */
+GDate* gnc_g_date_new_today (void);
+
/** Turns a Timespec into a GDate */
GDate timespec_to_gdate (Timespec ts);
/** Turns a GDate into a Timespec */
Timespec gdate_to_timespec (GDate d);
+/** Convert a day, month, and year to a GDate. Similar to g_date_new_dmy() but
+ * returns by-value and not by pointer. */
+GDate gnc_dmy2gdate (gint day, gint month, gint year);
+
/** Convert a day, month, and year to a Timespec */
Timespec gnc_dmy2timespec (gint day, gint month, gint year);
More information about the gnucash-changes
mailing list