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().

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@21559 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Christian Stimming 2011-11-11 21:57:52 +00:00
parent 2f51419545
commit bbb529263b
2 changed files with 24 additions and 0 deletions

View File

@ -1476,6 +1476,15 @@ gnc_dmy2timespec (int day, int month, int year)
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 @@ GDate timespec_to_gdate (Timespec ts)
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),

View File

@ -221,12 +221,20 @@ void timespecFromTime_t( Timespec *ts, time_t t );
/** 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);