diff --git a/po/POTFILES.in b/po/POTFILES.in index 0ec2b3fcc1..135a8ee49d 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -27,6 +27,7 @@ src/app-utils/gnc-component-manager.c src/app-utils/gnc-entry-quickfill.c src/app-utils/gnc-euro.c src/app-utils/gnc-exp-parser.c +src/app-utils/gnc-gdate-utils.c src/app-utils/gnc-gettext-util.c src/app-utils/gnc-gsettings.c src/app-utils/gnc-helpers.c @@ -113,9 +114,7 @@ src/bin/gnucash-bin.c src/core-utils/binreloc.c src/core-utils/core-utils.scm src/core-utils/gnc-environment.c -src/core-utils/gnc-features.c src/core-utils/gnc-filepath-utils.c -src/core-utils/gnc-gdate-utils.c src/core-utils/gnc-gkeyfile-utils.c src/core-utils/gnc-glib-utils.c src/core-utils/gnc-guile-utils.c @@ -123,7 +122,6 @@ src/core-utils/gnc-jalali.c src/core-utils/gnc-locale-utils.c src/core-utils/gnc-path.c src/core-utils/gnc-prefs.c -src/core-utils/gnc-uri-utils.c src/doc/doxygen_main_page.c src/engine/Account.c src/engine/business-core.scm @@ -146,6 +144,7 @@ src/engine/gncEmployee.c src/engine/gnc-engine.c src/engine/gncEntry.c src/engine/gnc-event.c +src/engine/gnc-features.c src/engine/gnc-hooks.c src/engine/gncIDSearch.c src/engine/gncInvoice.c @@ -158,6 +157,7 @@ src/engine/gncOwner.c src/engine/gnc-pricedb.c src/engine/gnc-session.c src/engine/gncTaxTable.c +src/engine/gnc-uri-utils.c src/engine/gncVendor.c src/engine/kvp-scm.cpp src/engine/policy.c diff --git a/src/app-utils/CMakeLists.txt b/src/app-utils/CMakeLists.txt index b3e780be7c..f27cbf4a1f 100644 --- a/src/app-utils/CMakeLists.txt +++ b/src/app-utils/CMakeLists.txt @@ -22,6 +22,7 @@ SET (app_utils_HEADERS gnc-entry-quickfill.h gnc-euro.h gnc-exp-parser.h + gnc-gdate-utils.h gnc-gettext-util.h gnc-gsettings.h gnc-help-utils.h @@ -63,6 +64,7 @@ SET (app_utils_SOURCES gnc-entry-quickfill.c gnc-euro.c gnc-exp-parser.c + gnc-gdate-utils.c gnc-gettext-util.c gnc-gsettings.c gnc-helpers.c diff --git a/src/app-utils/Makefile.am b/src/app-utils/Makefile.am index 26660604fb..10d6836848 100644 --- a/src/app-utils/Makefile.am +++ b/src/app-utils/Makefile.am @@ -53,6 +53,7 @@ libgncmod_app_utils_la_SOURCES = \ gnc-entry-quickfill.c \ gnc-euro.c \ gnc-exp-parser.c \ + gnc-gdate-utils.c \ gnc-gettext-util.c \ gnc-gsettings.c \ gnc-helpers.c \ @@ -80,6 +81,7 @@ gncinclude_HEADERS = \ gnc-entry-quickfill.h \ gnc-euro.h \ gnc-exp-parser.h \ + gnc-gdate-utils.h \ gnc-gettext-util.h \ gnc-gsettings.h \ gnc-help-utils.h \ diff --git a/src/core-utils/gnc-gdate-utils.c b/src/app-utils/gnc-gdate-utils.c similarity index 95% rename from src/core-utils/gnc-gdate-utils.c rename to src/app-utils/gnc-gdate-utils.c index 1ab4ed7c29..014a0e2369 100644 --- a/src/core-utils/gnc-gdate-utils.c +++ b/src/app-utils/gnc-gdate-utils.c @@ -26,23 +26,6 @@ #include "gnc-gdate-utils.h" -void -gnc_gdate_set_today (GDate* gd) -{ - GDate *today = gnc_g_date_new_today (); - g_date_set_julian (gd, g_date_get_julian (today)); - g_date_free (today); -} - -void -gnc_gdate_set_time64 (GDate* gd, time64 time) -{ - struct tm tm; - gnc_localtime_r(&time, &tm); - g_date_set_dmy (gd, tm.tm_mday, tm.tm_mon + 1, tm.tm_year + 1900); - -} - gboolean gnc_gdate_equal(gconstpointer gda, gconstpointer gdb) { diff --git a/src/core-utils/gnc-gdate-utils.h b/src/app-utils/gnc-gdate-utils.h similarity index 96% rename from src/core-utils/gnc-gdate-utils.h rename to src/app-utils/gnc-gdate-utils.h index a9e3c74461..3fd8830119 100644 --- a/src/core-utils/gnc-gdate-utils.h +++ b/src/app-utils/gnc-gdate-utils.h @@ -40,21 +40,6 @@ #include -/** @name GDate time64 setters - @{ */ -/** Set a GDate to the current day - * @param theGDate: The date to act on - */ -void gnc_gdate_set_today (GDate* gd); - -/** Set a GDate to a time64 - * @param theGDate: the date to act on - * @param time: the time to set it to. - */ -void gnc_gdate_set_time64 (GDate* gd, time64 time); - -/** @} */ - /** @name GDate hash table support @{ */ diff --git a/src/core-utils/CMakeLists.txt b/src/core-utils/CMakeLists.txt index fdb386491a..cd7072ade6 100644 --- a/src/core-utils/CMakeLists.txt +++ b/src/core-utils/CMakeLists.txt @@ -17,15 +17,12 @@ SET (core_utils_SOURCES gnc-prefs.c gnc-environment.c gnc-filepath-utils.c - gnc-features.c - gnc-gdate-utils.c gnc-gkeyfile-utils.c gnc-glib-utils.c gnc-guile-utils.c gnc-jalali.c gnc-locale-utils.c gnc-path.c - gnc-uri-utils.c ) # Add dependency on config.h @@ -110,16 +107,13 @@ SET(core_utils_noinst_HEADERS gnc-prefs.h gnc-prefs-p.h gnc-environment.h - gnc-features.h gnc-filepath-utils.h - gnc-gdate-utils.h gnc-gkeyfile-utils.h gnc-glib-utils.h gnc-guile-utils.h gnc-jalali.h gnc-locale-utils.h gnc-path.h - gnc-uri-utils.h ) SET(core_utils_ALL_SOURCES ${core_utils_SOURCES} ${core_utils_noinst_HEADERS}) diff --git a/src/core-utils/Makefile.am b/src/core-utils/Makefile.am index 38b6178616..86c2b429b1 100644 --- a/src/core-utils/Makefile.am +++ b/src/core-utils/Makefile.am @@ -6,16 +6,13 @@ libgnc_core_utils_la_SOURCES = \ binreloc.c \ gnc-prefs.c \ gnc-environment.c \ - gnc-features.c \ gnc-filepath-utils.c \ - gnc-gdate-utils.c \ gnc-gkeyfile-utils.c \ gnc-glib-utils.c \ gnc-guile-utils.c \ gnc-jalali.c \ gnc-locale-utils.c \ gnc-path.c \ - gnc-uri-utils.c \ swig-core-utils-guile.c libgnc_core_utils_la_LIBADD = \ @@ -31,16 +28,13 @@ noinst_HEADERS = \ gnc-prefs.h \ gnc-prefs-p.h \ gnc-environment.h \ - gnc-features.h \ gnc-filepath-utils.h \ - gnc-gdate-utils.h \ gnc-gkeyfile-utils.h \ gnc-glib-utils.h \ gnc-guile-utils.h \ gnc-jalali.h \ gnc-locale-utils.h \ - gnc-path.h \ - gnc-uri-utils.h + gnc-path.h if BUILDING_FROM_VCS swig-core-utils-guile.c: core-utils.i ${top_srcdir}/src/base-typemaps.i diff --git a/src/core-utils/test/CMakeLists.txt b/src/core-utils/test/CMakeLists.txt index 697c66fd4c..cbb07e4568 100644 --- a/src/core-utils/test/CMakeLists.txt +++ b/src/core-utils/test/CMakeLists.txt @@ -14,7 +14,6 @@ MACRO(ADD_CORE_UTILS_TEST _TARGET _SOURCE_FILES) ENDMACRO() ADD_CORE_UTILS_TEST(test-gnc-glib-utils test-gnc-glib-utils.c) -ADD_CORE_UTILS_TEST(test-gnc-uri-utils test-gnc-uri-utils.c) ADD_CORE_UTILS_TEST(test-resolve-file-path test-resolve-file-path.c) -SET_DIST_LIST(test_core_utils_DIST CMakeLists.txt Makefile.am test-gnc-glib-utils.c test-gnc-uri-utils.c test-resolve-file-path.c) \ No newline at end of file +SET_DIST_LIST(test_core_utils_DIST CMakeLists.txt Makefile.am test-gnc-glib-utils.c test-resolve-file-path.c) diff --git a/src/core-utils/test/Makefile.am b/src/core-utils/test/Makefile.am index 1c78d346ae..75d6067024 100644 --- a/src/core-utils/test/Makefile.am +++ b/src/core-utils/test/Makefile.am @@ -21,7 +21,6 @@ LDADD = \ # TESTS = \ - test-gnc-uri-utils \ test-resolve-file-path \ test-gnc-glib-utils diff --git a/src/engine/CMakeLists.txt b/src/engine/CMakeLists.txt index e2c54d8789..9029f3283c 100644 --- a/src/engine/CMakeLists.txt +++ b/src/engine/CMakeLists.txt @@ -41,9 +41,11 @@ SET (engine_HEADERS gnc-commodity.h gnc-engine.h gnc-event.h + gnc-features.h gnc-hooks.h gnc-pricedb.h gnc-session.h + gnc-uri-utils.h kvp-scm.h policy.h gncAddress.h @@ -111,10 +113,12 @@ SET (engine_SOURCES gnc-commodity.c gnc-engine.c gnc-event.c + gnc-features.c gnc-hooks.c gnc-lot.c gnc-pricedb.c gnc-session.c + gnc-uri-utils.c gncmod-engine.c kvp-scm.cpp engine-helpers.c diff --git a/src/engine/Makefile.am b/src/engine/Makefile.am index a37c4bc306..f533b76560 100644 --- a/src/engine/Makefile.am +++ b/src/engine/Makefile.am @@ -34,10 +34,12 @@ libgncmod_engine_la_SOURCES = \ gnc-commodity.c \ gnc-engine.c \ gnc-event.c \ + gnc-features.c \ gnc-hooks.c \ gnc-lot.c \ gnc-pricedb.c \ gnc-session.c \ + gnc-uri-utils.c \ gncmod-engine.c \ swig-engine.c \ kvp-scm.cpp \ @@ -86,9 +88,11 @@ gncinclude_HEADERS = \ gnc-commodity.h \ gnc-engine.h \ gnc-event.h \ + gnc-features.h \ gnc-hooks.h \ gnc-pricedb.h \ gnc-session.h \ + gnc-uri-utils.h \ kvp-scm.h \ policy.h \ gncAddress.h \ diff --git a/src/engine/Recurrence.c b/src/engine/Recurrence.c index c9bc78a001..8ac955b112 100644 --- a/src/engine/Recurrence.c +++ b/src/engine/Recurrence.c @@ -27,7 +27,7 @@ #include "gnc-date.h" #include "qof.h" #include "gnc-engine.h" -#include "gnc-gdate-utils.h" +#include "gnc-date.h" #include "Account.h" #define LOG_MOD "gnc.engine.recurrence" @@ -381,16 +381,23 @@ time64 recurrenceGetPeriodTime(const Recurrence *r, guint period_num, gboolean end) { GDate date; + Timespec ts; recurrenceNthInstance(r, period_num + (end ? 1 : 0), &date); if (end) { g_date_subtract_days(&date, 1); - return gnc_time64_get_day_end_gdate(&date); + ts = gnc_dmy2timespec_end (g_date_get_day(&date), + g_date_get_month(&date), + g_date_get_year (&date)); + } else { - return gnc_time64_get_day_start_gdate(&date); + ts = gnc_dmy2timespec (g_date_get_day(&date), + g_date_get_month(&date), + g_date_get_year (&date)); } + return timespecToTime64(ts); } gnc_numeric diff --git a/src/engine/Transaction.c b/src/engine/Transaction.c index 4ac15be527..a0b4c158bc 100644 --- a/src/engine/Transaction.c +++ b/src/engine/Transaction.c @@ -62,7 +62,7 @@ struct timeval #include "gnc-engine.h" #include "gnc-lot.h" #include "gnc-event.h" -#include +#include #include "SchedXaction.h" #include "gncBusiness.h" #include diff --git a/src/engine/gnc-budget.c b/src/engine/gnc-budget.c index f748f7565f..c49af4ef0b 100644 --- a/src/engine/gnc-budget.c +++ b/src/engine/gnc-budget.c @@ -29,7 +29,6 @@ #include #include #include -#include #include #include "Account.h" @@ -89,16 +88,17 @@ static void gnc_budget_init(GncBudget* budget) { BudgetPrivate* priv; - GDate date; + GDate *date; priv = GET_PRIVATE(budget); priv->name = CACHE_INSERT(_("Unnamed Budget")); priv->description = CACHE_INSERT(""); priv->num_periods = 12; - gnc_gdate_set_today (&date); - g_date_subtract_days(&date, g_date_get_day(&date) - 1); - recurrenceSet(&priv->recurrence, 1, PERIOD_MONTH, &date, WEEKEND_ADJ_NONE); + date = gnc_g_date_new_today (); + g_date_subtract_days(date, g_date_get_day(date) - 1); + recurrenceSet(&priv->recurrence, 1, PERIOD_MONTH, date, WEEKEND_ADJ_NONE); + g_date_free (date); } static void diff --git a/src/core-utils/gnc-features.c b/src/engine/gnc-features.c similarity index 100% rename from src/core-utils/gnc-features.c rename to src/engine/gnc-features.c diff --git a/src/core-utils/gnc-features.h b/src/engine/gnc-features.h similarity index 100% rename from src/core-utils/gnc-features.h rename to src/engine/gnc-features.h diff --git a/src/core-utils/gnc-uri-utils.c b/src/engine/gnc-uri-utils.c similarity index 100% rename from src/core-utils/gnc-uri-utils.c rename to src/engine/gnc-uri-utils.c diff --git a/src/core-utils/gnc-uri-utils.h b/src/engine/gnc-uri-utils.h similarity index 100% rename from src/core-utils/gnc-uri-utils.h rename to src/engine/gnc-uri-utils.h diff --git a/src/engine/test/CMakeLists.txt b/src/engine/test/CMakeLists.txt index 7fb75f91fc..19dafe7a58 100644 --- a/src/engine/test/CMakeLists.txt +++ b/src/engine/test/CMakeLists.txt @@ -35,6 +35,7 @@ ADD_ENGINE_TEST(test-commodities test-commodities.cpp) SET(test_engine_SOURCES test-engine.c + test-gnc-uri-utils.c utest-Account.cpp utest-Budget.c utest-Entry.c @@ -109,6 +110,7 @@ SET(test_engine_SOURCES_DIST test-employee.c test-engine-kvp-properties.c test-engine.c + test-gnc-uri-utils.c test-group-vs-book.cpp test-guid.cpp test-job.c diff --git a/src/engine/test/Makefile.am b/src/engine/test/Makefile.am index fa264f393f..a363e53d4a 100644 --- a/src/engine/test/Makefile.am +++ b/src/engine/test/Makefile.am @@ -148,6 +148,7 @@ noinst_DATA: .scm-links test_engine_SOURCES = \ test-engine.c \ + test-gnc-uri-utils.c \ utest-Account.cpp \ utest-Budget.c \ utest-Entry.c \ diff --git a/src/core-utils/test/test-gnc-uri-utils.c b/src/engine/test/test-gnc-uri-utils.c similarity index 70% rename from src/core-utils/test/test-gnc-uri-utils.c rename to src/engine/test/test-gnc-uri-utils.c index c94fe6c753..5764c94acc 100644 --- a/src/core-utils/test/test-gnc-uri-utils.c +++ b/src/engine/test/test-gnc-uri-utils.c @@ -27,9 +27,12 @@ #include #include "qof.h" -#include "test-stuff.h" +#include #include "gnc-uri-utils.h" +static const gchar *suitename = "engine/uri-utils"; +void test_suite_gnc_uri_utils(void); + struct test_strings_struct { gchar *uri; @@ -194,14 +197,11 @@ test_strings strs[] = { NULL, FALSE, NULL, NULL, NULL, NULL, NULL, 0, NULL, FALSE }, }; -int -main(int argc, char **argv) +/* TEST: gnc_uri_get_components */ +static void +test_gnc_uri_get_components() { int i; - - qof_init(); - - /* TEST: gnc_uri_get_components */ for (i = 0; strs[i].uri != NULL; i++) { gchar *tprotocol = NULL; @@ -210,141 +210,124 @@ main(int argc, char **argv) gchar *tpassword = NULL; gchar *tpath = NULL; gint32 tport = 0; - gboolean testresult; gnc_uri_get_components( strs[i].uri, &tprotocol, &thostname, &tport, &tusername, &tpassword, &tpath ); - testresult = ( g_strcmp0 ( tprotocol, strs[i].protocol ) == 0 ) & - ( g_strcmp0 ( thostname, strs[i].hostname ) == 0 ) & - ( g_strcmp0 ( tusername, strs[i].username ) == 0 ) & - ( g_strcmp0 ( tpassword, strs[i].password ) == 0 ) & - ( g_strcmp0 ( tpath, strs[i].path ) == 0 ) & - ( tport == strs[i].port ); - do_test_args(testresult, - "gnc_uri_get_components", - __FILE__, __LINE__, - "\n %s:\n" - " Expected: %s, %s, %s, %s, %s, %d\n" - " Got : %s, %s, %s, %s, %s, %d\n", - strs[i].uri, strs[i].protocol, strs[i].hostname, - strs[i].username, strs[i].password, strs[i].path, strs[i].port, - tprotocol, thostname, tusername, tpassword, tpath, tport); + g_assert_cmpstr ( tprotocol, ==, strs[i].protocol ); + g_assert_cmpstr ( thostname, ==, strs[i].hostname ); + g_assert_cmpstr ( tusername, ==, strs[i].username ); + g_assert_cmpstr ( tpassword, ==, strs[i].password ); + g_assert_cmpstr ( tpath, ==, strs[i].path ); + g_assert_cmpint ( tport, ==, strs[i].port ); + g_free(tprotocol); g_free(thostname); g_free(tusername); g_free(tpassword); g_free(tpath); } +} - /* TEST: gnc_uri_get_protocol */ +/* TEST: gnc_uri_get_protocol */ +static void +test_gnc_uri_get_protocol() +{ + int i; for (i = 0; strs[i].uri != NULL; i++) { gchar *tprotocol = NULL; - gboolean testresult; tprotocol = gnc_uri_get_protocol( strs[i].uri ); - testresult = ( g_strcmp0 ( tprotocol, strs[i].protocol ) == 0 ); - do_test_args(testresult, - "gnc_uri_get_protocol", - __FILE__, __LINE__, - "\n %s:\n" - " Expected: %s\n" - " Got : %s\n", - strs[i].uri, strs[i].protocol, tprotocol ); + g_assert_cmpstr ( tprotocol, ==, strs[i].protocol ); g_free(tprotocol); } +} - /* TEST: gnc_uri_get_path */ +/* TEST: gnc_uri_get_path */ +static void +test_gnc_uri_get_path() +{ + int i; for (i = 0; strs[i].uri != NULL; i++) { gchar *tpath = NULL; - gboolean testresult; tpath = gnc_uri_get_path( strs[i].uri ); - testresult = ( g_strcmp0 ( tpath, strs[i].path ) == 0 ); - do_test_args(testresult, - "gnc_uri_get_path", - __FILE__, __LINE__, - "\n %s:\n" - " Expected: %s\n" - " Got : %s\n", - strs[i].uri, strs[i].path, tpath ); + g_assert_cmpstr ( tpath, ==, strs[i].path ); g_free(tpath); } +} - /* TEST: gnc_uri_create_uri */ +/* TEST: gnc_uri_create_uri */ +static void +test_gnc_uri_create_uri() +{ + int i; for (i = 0; strs[i].uri != NULL; i++) { gchar *turi = NULL; - gboolean testresult; turi = gnc_uri_create_uri( strs[i].protocol, strs[i].hostname, strs[i].port, strs[i].username, strs[i].password, strs[i].path ); - testresult = ( g_strcmp0 ( turi, strs[i].created_uri ) == 0 ); - do_test_args(testresult, - "gnc_uri_create_uri", - __FILE__, __LINE__, - "\n %s, %s, %s, %s, %s, %d:\n" - " Expected: %s\n" - " Got : %s\n", - strs[i].protocol, strs[i].hostname, - strs[i].username, strs[i].password, strs[i].path, strs[i].port, - strs[i].created_uri, turi); + g_assert_cmpstr ( turi, ==, strs[i].created_uri ); g_free(turi); } +} + +/* TEST: gnc_uri_normalize_uri */ +static void +test_gnc_uri_normalize_uri() +{ + int i; /* TEST: gnc_uri_normalize_uri */ for (i = 0; strs[i].uri != NULL; i++) { gchar *turi = NULL; - gboolean testresult; turi = gnc_uri_normalize_uri( strs[i].uri, strs[i].want_password ); - testresult = ( g_strcmp0 ( turi, strs[i].normalized_uri ) == 0 ); - do_test_args(testresult, - "gnc_uri_normalize_uri", - __FILE__, __LINE__, - "\n %s:\n" - " Expected: %s\n" - " Got : %s\n", - strs[i].uri, strs[i].normalized_uri, turi ); + g_assert_cmpstr ( turi, ==, strs[i].normalized_uri ); g_free(turi); } +} - /* TEST: gnc_uri_is_file_protocol */ +/* TEST: gnc_uri_is_file_protocol */ +static void +test_gnc_uri_is_file_protocol() +{ + int i; for (i = 0; strs[i].uri != NULL; i++) { gboolean tis_file_protocol; - gboolean testresult; tis_file_protocol = gnc_uri_is_file_protocol( strs[i].protocol ); - testresult = ( tis_file_protocol == strs[i].is_file_protocol ); - do_test_args(testresult, - "gnc_uri_is_file_protocol", - __FILE__, __LINE__, - "\n %s:\n" - " Expected: %s\n" - " Got : %s\n", - strs[i].uri, strs[i].is_file_protocol, tis_file_protocol ); + g_assert_true ( tis_file_protocol == strs[i].is_file_protocol );; } +} - /* TEST: gnc_uri_is_file_uri */ +/* TEST: gnc_uri_is_file_uri */ +static void +test_gnc_uri_is_file_uri() +{ + int i; for (i = 0; strs[i].uri != NULL; i++) { gboolean tis_file_uri; - gboolean testresult; tis_file_uri = gnc_uri_is_file_uri( strs[i].uri ); - testresult = ( tis_file_uri == strs[i].is_file_protocol ); - do_test_args(testresult, - "gnc_uri_is_file_uri", - __FILE__, __LINE__, - "\n %s:\n" - " Expected: %s\n" - " Got : %s\n", - strs[i].uri, strs[i].is_file_protocol, tis_file_uri ); + g_assert_true ( tis_file_uri == strs[i].is_file_protocol ); } - - print_test_results(); - return get_rv(); +} + +void +test_suite_gnc_uri_utils(void) +{ + GNC_TEST_ADD_FUNC(suitename, "gnc_uri_get_components()", test_gnc_uri_get_components); + GNC_TEST_ADD_FUNC(suitename, "gnc_uri_get_protocol()", test_gnc_uri_get_protocol); + GNC_TEST_ADD_FUNC(suitename, "gnc_uri_get_path()", test_gnc_uri_get_path); + GNC_TEST_ADD_FUNC(suitename, "gnc_uri_create_uri()", test_gnc_uri_create_uri); + GNC_TEST_ADD_FUNC(suitename, "gnc_uri_normalize_uri()", test_gnc_uri_normalize_uri); + GNC_TEST_ADD_FUNC(suitename, "gnc_uri_is_file_protocol()", test_gnc_uri_is_file_protocol); + GNC_TEST_ADD_FUNC(suitename, "gnc_uri_is_file_uri()", test_gnc_uri_is_file_uri); + } diff --git a/src/engine/test/utest-Account.cpp b/src/engine/test/utest-Account.cpp index a0e9c40bc8..b49966933f 100644 --- a/src/engine/test/utest-Account.cpp +++ b/src/engine/test/utest-Account.cpp @@ -26,7 +26,7 @@ extern "C" #include #include #include -#include +#include #include /* Add specific headers for this class */ #include "../Account.h" diff --git a/src/libqof/qof/gnc-date.cpp b/src/libqof/qof/gnc-date.cpp index ad4881086e..9fe89ee829 100644 --- a/src/libqof/qof/gnc-date.cpp +++ b/src/libqof/qof/gnc-date.cpp @@ -1354,8 +1354,28 @@ GDate* gnc_g_date_new_today () auto result = g_date_new_dmy (ymd.day, month, ymd.year); g_assert(g_date_valid (result)); return result; +}void + +gnc_gdate_set_today (GDate* gd) +{ + GDate *today = gnc_g_date_new_today (); + g_date_set_julian (gd, g_date_get_julian (today)); + g_date_free (today); } +void +gnc_gdate_set_time64 (GDate* gd, time64 time) +{ + struct tm tm; + gnc_localtime_r(&time, &tm); + g_date_set_dmy (gd, tm.tm_mday, + static_cast(tm.tm_mon + 1), + tm.tm_year + 1900); + +} + + + Timespec gdate_to_timespec (GDate d) { return gnc_dmy2timespec_neutral (g_date_get_day(&d), diff --git a/src/libqof/qof/gnc-date.h b/src/libqof/qof/gnc-date.h index a8b2a633e1..432a00e992 100644 --- a/src/libqof/qof/gnc-date.h +++ b/src/libqof/qof/gnc-date.h @@ -259,18 +259,32 @@ gboolean gnc_date_string_to_monthformat(const gchar *format_string, GNCDateMonthFormat *format); /** \brief print a time64 as a date string per format - * \param time + * \param time The time64 to print * \param format A date format conforming to the strftime format rules. * \return a raw heap-allocated char* which must be freed. */ char* gnc_print_time64(time64 time, const char* format); +// @} + +/** @name GDate time64 setters + * @{ */ /** 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); +/** Set a GDate to the current day + * @param gd The date to act on + */ +void gnc_gdate_set_today (GDate* gd); -// @} +/** Set a GDate to a time64 + * @param gd the date to act on + * @param time the time to set it to. + */ +void gnc_gdate_set_time64 (GDate* gd, time64 time); + +/** @} */ /* Datatypes *******************************************************/