diff --git a/gnucash/gnome-utils/dialog-utils.c b/gnucash/gnome-utils/dialog-utils.c index 247b5d3c2c..ce62fe6c9f 100644 --- a/gnucash/gnome-utils/dialog-utils.c +++ b/gnucash/gnome-utils/dialog-utils.c @@ -35,6 +35,7 @@ #include "dialog-utils.h" #include "gnc-commodity.h" +#include "gnc-date.h" #include "gnc-path.h" #include "gnc-engine.h" #include "gnc-euro.h" @@ -43,7 +44,6 @@ #include "gnc-combott.h" #include "guile-util.h" #include "gnc-main-window.h" -#include /* This static indicates the debugging module that this .o belongs to. */ static QofLogModule log_module = GNC_MOD_GUI; diff --git a/gnucash/gnome-utils/gnc-date-edit.c b/gnucash/gnome-utils/gnc-date-edit.c index 1c9dcbee11..d700f6431e 100644 --- a/gnucash/gnome-utils/gnc-date-edit.c +++ b/gnucash/gnome-utils/gnc-date-edit.c @@ -43,7 +43,6 @@ #include /* isdigit */ #include -#include #include "gnc-date.h" #include "gnc-engine.h" #include "dialog-utils.h" diff --git a/gnucash/gnome-utils/gnc-dense-cal-store.c b/gnucash/gnome-utils/gnc-dense-cal-store.c index 9bfce1eb72..63553485f4 100644 --- a/gnucash/gnome-utils/gnc-dense-cal-store.c +++ b/gnucash/gnome-utils/gnc-dense-cal-store.c @@ -33,11 +33,11 @@ #include "config.h" #include #include +#include "gnc-date.h" #include "gnc-dense-cal.h" #include "gnc-dense-cal-model.h" #include "gnc-dense-cal-store.h" #include "Recurrence.h" -#include struct _GncDenseCalStore { diff --git a/gnucash/gnome-utils/gnc-dense-cal.c b/gnucash/gnome-utils/gnc-dense-cal.c index 8d2bc326df..1f4e81b870 100644 --- a/gnucash/gnome-utils/gnc-dense-cal.c +++ b/gnucash/gnome-utils/gnc-dense-cal.c @@ -30,7 +30,7 @@ #include #include #include -#include +#include "gnc-date.h" #include "dialog-utils.h" /** diff --git a/gnucash/gnome-utils/gnc-period-select.c b/gnucash/gnome-utils/gnc-period-select.c index 3fe2f429e6..179edf4514 100644 --- a/gnucash/gnome-utils/gnc-period-select.c +++ b/gnucash/gnome-utils/gnc-period-select.c @@ -37,7 +37,6 @@ #include "gnc-date.h" #include "gnc-period-select.h" #include "gnc-prefs.h" -#include #include "dialog-utils.h" enum diff --git a/gnucash/gnome-utils/gnc-recurrence.c b/gnucash/gnome-utils/gnc-recurrence.c index 67ff550576..f2e1197cd6 100644 --- a/gnucash/gnome-utils/gnc-recurrence.c +++ b/gnucash/gnome-utils/gnc-recurrence.c @@ -29,11 +29,11 @@ #include #include "dialog-utils.h" +#include "gnc-date.h" #include "gnc-recurrence.h" #include "gnc-date-edit.h" #include "Recurrence.h" #include "gnc-engine.h" -#include "gnc-gdate-utils.h" static QofLogModule log_module = GNC_MOD_GUI; diff --git a/gnucash/gnome-utils/gnc-tree-control-split-reg.c b/gnucash/gnome-utils/gnc-tree-control-split-reg.c index 25ee798e96..2383ddfc8b 100644 --- a/gnucash/gnome-utils/gnc-tree-control-split-reg.c +++ b/gnucash/gnome-utils/gnc-tree-control-split-reg.c @@ -36,9 +36,9 @@ #include "gnc-tree-util-split-reg.h" #include "gnc-tree-view-split-reg.h" #include "gnc-component-manager.h" +#include "gnc-date.h" #include "gnc-ui.h" #include "gnc-prefs.h" -#include "gnc-gdate-utils.h" #include "gnc-warnings.h" #include "dialog-utils.h" #include "dialog-dup-trans.h" diff --git a/gnucash/gnome/assistant-acct-period.c b/gnucash/gnome/assistant-acct-period.c index 9190119b66..ea6bd1b913 100644 --- a/gnucash/gnome/assistant-acct-period.c +++ b/gnucash/gnome/assistant-acct-period.c @@ -45,9 +45,9 @@ #include "assistant-acct-period.h" #include "gnc-component-manager.h" #include "qof.h" +#include "gnc-date.h" #include "gnc-file.h" #include "gnc-frequency.h" -#include "gnc-gdate-utils.h" #include "gnc-gui-query.h" #include "gnc-ui-util.h" #include "misc-gnome-utils.h" diff --git a/gnucash/gnome/assistant-loan.c b/gnucash/gnome/assistant-loan.c index af871fa6c5..7d7f616f25 100644 --- a/gnucash/gnome/assistant-loan.c +++ b/gnucash/gnome/assistant-loan.c @@ -41,7 +41,6 @@ #include "dialog-utils.h" #include "Account.h" #include "gnc-ui.h" -#include "gnc-gdate-utils.h" #include "gnc-gui-query.h" #include "gnc-ui-util.h" #include "gnc-frequency.h" diff --git a/gnucash/gnome/dialog-invoice.c b/gnucash/gnome/dialog-invoice.c index 6f591185cf..5388de8b06 100644 --- a/gnucash/gnome/dialog-invoice.c +++ b/gnucash/gnome/dialog-invoice.c @@ -32,13 +32,13 @@ #include "qof.h" -#include #include "dialog-utils.h" #include "gnc-component-manager.h" #include "gnc-ui.h" #include "gnc-gui-query.h" #include "gnc-prefs.h" #include "gnc-ui-util.h" +#include "gnc-date.h" #include "gnc-date-edit.h" #include "gnc-amount-edit.h" #include "gnucash-sheet.h" diff --git a/gnucash/gnome/dialog-print-check.c b/gnucash/gnome/dialog-print-check.c index 0c7f0f20e2..021b52f15f 100644 --- a/gnucash/gnome/dialog-print-check.c +++ b/gnucash/gnome/dialog-print-check.c @@ -36,7 +36,6 @@ #include #include -#include #include "qof.h" #include "gnc-date.h" #include "gnc-prefs.h" diff --git a/gnucash/gnome/dialog-sx-editor.c b/gnucash/gnome/dialog-sx-editor.c index 76b6948442..596d04bf2c 100644 --- a/gnucash/gnome/dialog-sx-editor.c +++ b/gnucash/gnome/dialog-sx-editor.c @@ -38,7 +38,6 @@ #include #include -#include #include "qof.h" #include "Account.h" #include "SchedXaction.h" diff --git a/gnucash/gnome/dialog-sx-editor2.c b/gnucash/gnome/dialog-sx-editor2.c index 74c704c8ba..e4c308cc4f 100644 --- a/gnucash/gnome/dialog-sx-editor2.c +++ b/gnucash/gnome/dialog-sx-editor2.c @@ -38,7 +38,6 @@ #include #include -#include #include "qof.h" #include "Account.h" #include "SchedXaction.h" diff --git a/gnucash/gnome/dialog-sx-from-trans.c b/gnucash/gnome/dialog-sx-from-trans.c index d9b8df5cb9..c3db976731 100644 --- a/gnucash/gnome/dialog-sx-from-trans.c +++ b/gnucash/gnome/dialog-sx-from-trans.c @@ -26,11 +26,11 @@ #include "config.h" -#include #include "dialog-sx-editor.h" #include "dialog-sx-from-trans.h" #include "dialog-utils.h" #include "gnc-component-manager.h" +#include "gnc-date.h" #include "gnc-date-edit.h" #include "gnc-dense-cal-store.h" #include "gnc-dense-cal.h" diff --git a/gnucash/gnome/gnc-plugin-page-sx-list.c b/gnucash/gnome/gnc-plugin-page-sx-list.c index 080558cff9..e59946eb85 100644 --- a/gnucash/gnome/gnc-plugin-page-sx-list.c +++ b/gnucash/gnome/gnc-plugin-page-sx-list.c @@ -47,7 +47,6 @@ #include #include -#include #include #include "SX-book.h" #include "Split.h" @@ -59,6 +58,7 @@ #include "dialog-utils.h" #include "gnc-commodity.h" #include "gnc-component-manager.h" +#include "gnc-date.h" #include "gnc-dense-cal.h" #include "gnc-engine.h" #include "gnc-event.h" diff --git a/gnucash/gnome/window-reconcile.c b/gnucash/gnome/window-reconcile.c index 2adcb3963f..086be20388 100644 --- a/gnucash/gnome/window-reconcile.c +++ b/gnucash/gnome/window-reconcile.c @@ -44,10 +44,10 @@ #include "dialog-utils.h" #include "gnc-amount-edit.h" #include "gnc-component-manager.h" +#include "gnc-date.h" #include "gnc-date-edit.h" #include "gnc-event.h" #include "gnc-filepath-utils.h" -#include #include "gnc-gnome-utils.h" #include "gnc-main-window.h" #include "gnc-plugin-page-register.h" diff --git a/gnucash/gnome/window-reconcile2.c b/gnucash/gnome/window-reconcile2.c index 3d49bbad48..8d58d3376b 100644 --- a/gnucash/gnome/window-reconcile2.c +++ b/gnucash/gnome/window-reconcile2.c @@ -44,10 +44,10 @@ #include "dialog-utils.h" #include "gnc-amount-edit.h" #include "gnc-component-manager.h" +#include "gnc-date.h" #include "gnc-date-edit.h" #include "gnc-event.h" #include "gnc-filepath-utils.h" -#include #include "gnc-gnome-utils.h" #include "gnc-main-window.h" #include "gnc-plugin-page-register2.h" diff --git a/gnucash/import-export/bi-import/dialog-bi-import.c b/gnucash/import-export/bi-import/dialog-bi-import.c index 33a0944691..3675a79b26 100644 --- a/gnucash/import-export/bi-import/dialog-bi-import.c +++ b/gnucash/import-export/bi-import/dialog-bi-import.c @@ -39,6 +39,7 @@ #include #include +#include "gnc-date.h" #include "gnc-ui.h" #include "gnc-ui-util.h" #include "gnc-gui-query.h" @@ -56,7 +57,6 @@ #include "gncIDSearch.h" #include "dialog-bi-import.h" #include "dialog-bi-import-helper.h" -#include // To open the invoices for editing #include "gnc-plugin-page-invoice.h" diff --git a/gnucash/register/ledger-core/split-register-util.c b/gnucash/register/ledger-core/split-register-util.c index 2211d222b7..53a4de7fb8 100644 --- a/gnucash/register/ledger-core/split-register-util.c +++ b/gnucash/register/ledger-core/split-register-util.c @@ -24,7 +24,7 @@ #include -#include +#include "gnc-date.h" #include "pricecell.h" #include "split-register-p.h" diff --git a/gnucash/register/ledger-core/split-register.c b/gnucash/register/ledger-core/split-register.c index ca5c9777fc..e1f38e3df8 100644 --- a/gnucash/register/ledger-core/split-register.c +++ b/gnucash/register/ledger-core/split-register.c @@ -28,12 +28,12 @@ #include #include -#include #include "combocell.h" #include "datecell.h" #include "dialog-utils.h" #include "gnc-component-manager.h" #include "split-register-p.h" +#include "gnc-date.h" #include "gnc-ledger-display.h" #include "gnc-prefs.h" #include "gnc-ui.h" diff --git a/libgnucash/app-utils/gnc-accounting-period.c b/libgnucash/app-utils/gnc-accounting-period.c index f947e71b39..41f75e5cbd 100644 --- a/libgnucash/app-utils/gnc-accounting-period.c +++ b/libgnucash/app-utils/gnc-accounting-period.c @@ -44,7 +44,6 @@ #include "config.h" #include #include "gnc-accounting-period.h" -#include "gnc-gdate-utils.h" #include "gnc-date.h" #include "gnc-prefs.h" #include "qof.h" diff --git a/libgnucash/app-utils/gnc-sx-instance-model.c b/libgnucash/app-utils/gnc-sx-instance-model.c index 62c4c736eb..bc5997a910 100644 --- a/libgnucash/app-utils/gnc-sx-instance-model.c +++ b/libgnucash/app-utils/gnc-sx-instance-model.c @@ -42,13 +42,13 @@ #include "Split.h" #include "Transaction.h" #include "gnc-commodity.h" +#include "gnc-date.h" #include "gnc-event.h" #include "gnc-exp-parser.h" #include "gnc-glib-utils.h" #include "gnc-sx-instance-model.h" #include "gnc-ui-util.h" #include "qof.h" -#include #undef G_LOG_DOMAIN #define G_LOG_DOMAIN "gnc.app-utils.sx" diff --git a/libgnucash/app-utils/test/test-sx.cpp b/libgnucash/app-utils/test/test-sx.cpp index 027731bc3b..71f36c0411 100644 --- a/libgnucash/app-utils/test/test-sx.cpp +++ b/libgnucash/app-utils/test/test-sx.cpp @@ -24,9 +24,9 @@ extern "C" #include #include #include "SX-book.h" +#include "gnc-date.h" #include "gnc-sx-instance-model.h" #include "gnc-ui-util.h" -#include #include "test-stuff.h" #include "test-engine-stuff.h" diff --git a/libgnucash/engine/CMakeLists.txt b/libgnucash/engine/CMakeLists.txt index b6d92d131a..041ef20d4c 100644 --- a/libgnucash/engine/CMakeLists.txt +++ b/libgnucash/engine/CMakeLists.txt @@ -54,7 +54,6 @@ SET (engine_HEADERS gnc-engine.h gnc-event.h gnc-features.h - gnc-gdate-utils.h gnc-hooks.h gnc-numeric.h gnc-numeric.hpp @@ -160,7 +159,6 @@ SET (engine_SOURCES gnc-engine.c gnc-event.c gnc-features.c - gnc-gdate-utils.c gnc-hooks.c gnc-int128.cpp gnc-lot.c diff --git a/libgnucash/engine/Makefile.am b/libgnucash/engine/Makefile.am index 56677e1910..4943aef68d 100644 --- a/libgnucash/engine/Makefile.am +++ b/libgnucash/engine/Makefile.am @@ -40,7 +40,6 @@ libgncmod_engine_la_SOURCES = \ gnc-engine.c \ gnc-event.c \ gnc-features.c \ - gnc-gdate-utils.c \ gnc-hooks.c \ gnc-int128.cpp \ gnc-lot.c \ @@ -125,7 +124,6 @@ gncinclude_HEADERS = \ gnc-engine.h \ gnc-event.h \ gnc-features.h \ - gnc-gdate-utils.h \ gnc-hooks.h \ gnc-numeric.h \ gnc-numeric.hpp \ diff --git a/libgnucash/engine/gnc-date.cpp b/libgnucash/engine/gnc-date.cpp index 1e88c32157..4f4a13b75f 100644 --- a/libgnucash/engine/gnc-date.cpp +++ b/libgnucash/engine/gnc-date.cpp @@ -3,6 +3,7 @@ * * * Copyright 1997 Robin D. Clark * * Copyright 1998-2000, 2003 Linas Vepstas * + * Copyright (C) 2005 David Hampton * * Copyright 2011-2015 John Ralls timespec_normalize = timespec_normalize; return tf; } + +/* ================================================= */ + +gboolean +gnc_gdate_equal(gconstpointer gda, gconstpointer gdb) +{ + return (g_date_compare( (GDate*)gda, (GDate*)gdb ) == 0 ? TRUE : FALSE); +} + +guint +gnc_gdate_hash( gconstpointer gd ) +{ + gint val = (g_date_get_year( (GDate*)gd ) * 10000) + + (g_date_get_month( (GDate*)gd ) * 100) + + g_date_get_day( (GDate*)gd ); + return g_int_hash( &val ); +} + +/* ================================================= */ + +time64 +gnc_time64_get_day_start_gdate (const GDate *date) +{ + struct tm stm; + time64 secs; + + /* First convert to a 'struct tm' */ + g_date_to_struct_tm (date, &stm); + + /* Then convert to number of seconds */ + secs = gnc_mktime (&stm); + return secs; +} + +time64 +gnc_time64_get_day_end_gdate (const GDate *date) +{ + struct tm stm; + time64 secs; + + /* First convert to a 'struct tm' */ + g_date_to_struct_tm(date, &stm); + + /* Force to th last second of the day */ + stm.tm_hour = 23; + stm.tm_min = 59; + stm.tm_sec = 59; + stm.tm_isdst = -1; + + /* Then convert to number of seconds */ + secs = gnc_mktime (&stm); + return secs; +} + +/* ================================================= */ + +void +gnc_gdate_set_month_start (GDate *date) +{ + g_date_set_day(date, 1); +} + +/** Convert a GDate to the last day of the month. This routine has no + * knowledge of how many days are in a month, whether its a leap + * year, etc. All that information is contained in the glib date + * functions. + * + * @param date The GDate to modify. + */ +void +gnc_gdate_set_month_end (GDate *date) +{ + /* First set the start of next month. */ + g_date_set_day(date, 1); + g_date_add_months(date, 1); + + /* Then back up one day */ + g_date_subtract_days(date, 1); +} + +/** Convert a GDate to the first day of the prebvious month. This + * routine has no knowledge of how many days are in a month, whether + * its a leap year, etc. All that information is contained in the + * glib date functions. + * + * @param date The GDate to modify. + */ +void +gnc_gdate_set_prev_month_start (GDate *date) +{ + g_date_set_day(date, 1); + g_date_subtract_months(date, 1); +} + +/** Convert a GDate to the last day of the prebvious month. This + * routine has no knowledge of how many days are in a month, whether + * its a leap year, etc. All that information is contained in the + * glib date functions. + * + * @param date The GDate to modify. + */ +void +gnc_gdate_set_prev_month_end (GDate *date) +{ + /* This will correctly handle the varying month lengths */ + g_date_set_day(date, 1); + g_date_subtract_days(date, 1); +} + +/* ================================================= */ + +void +gnc_gdate_set_quarter_start (GDate *date) +{ + gint months; + + /* Set the date to the first day of the specified month. */ + g_date_set_day(date, 1); + + /* Back up 0-2 months */ + months = (g_date_get_month(date) - G_DATE_JANUARY) % 3; + g_date_subtract_months(date, months); +} + +void +gnc_gdate_set_quarter_end (GDate *date) +{ + gint months; + + /* Set the date to the first day of the specified month. */ + g_date_set_day(date, 1); + + /* Add 1-3 months to get the first day of the next quarter.*/ + months = (g_date_get_month(date) - G_DATE_JANUARY) % 3; + g_date_add_months(date, 3 - months); + + /* Now back up one day */ + g_date_subtract_days(date, 1); +} + +void +gnc_gdate_set_prev_quarter_start (GDate *date) +{ + gnc_gdate_set_quarter_start(date); + g_date_subtract_months(date, 3); +} + +void +gnc_gdate_set_prev_quarter_end (GDate *date) +{ + gnc_gdate_set_quarter_end(date); + g_date_subtract_months(date, 3); +} + +/* ================================================= */ + +void +gnc_gdate_set_year_start (GDate *date) +{ + g_date_set_month(date, G_DATE_JANUARY); + g_date_set_day(date, 1); +} + +void +gnc_gdate_set_year_end (GDate *date) +{ + g_date_set_month(date, G_DATE_DECEMBER); + g_date_set_day(date, 31); +} + +void +gnc_gdate_set_prev_year_start (GDate *date) +{ + gnc_gdate_set_year_start(date); + g_date_subtract_years(date, 1); +} + +void +gnc_gdate_set_prev_year_end (GDate *date) +{ + gnc_gdate_set_year_end(date); + g_date_subtract_years(date, 1); +} + +/* ================================================= */ + +void +gnc_gdate_set_fiscal_year_start (GDate *date, + const GDate *fy_end) +{ + GDate temp; + gboolean new_fy; + + g_return_if_fail(date); + g_return_if_fail(fy_end); + + /* Compute the FY end that occurred this CY */ + temp = *fy_end; + g_date_set_year(&temp, g_date_get_year(date)); + + /* Has it already passed? */ + new_fy = (g_date_compare(date, &temp) > 0); + + /* Set start date */ + *date = temp; + g_date_add_days(date, 1); + if (!new_fy) + g_date_subtract_years(date, 1); +} + +void +gnc_gdate_set_fiscal_year_end (GDate *date, + const GDate *fy_end) +{ + GDate temp; + gboolean new_fy; + + g_return_if_fail(date); + g_return_if_fail(fy_end); + + /* Compute the FY end that occurred this CY */ + temp = *fy_end; + g_date_set_year(&temp, g_date_get_year(date)); + + /* Has it already passed? */ + new_fy = (g_date_compare(date, &temp) > 0); + + /* Set end date */ + *date = temp; + if (new_fy) + g_date_add_years(date, 1); +} + +void +gnc_gdate_set_prev_fiscal_year_start (GDate *date, + const GDate *fy_end) +{ + g_return_if_fail(date); + g_return_if_fail(fy_end); + + gnc_gdate_set_fiscal_year_start(date, fy_end); + g_date_subtract_years(date, 1); +} + +void +gnc_gdate_set_prev_fiscal_year_end (GDate *date, + const GDate *fy_end) +{ + g_return_if_fail(date); + g_return_if_fail(fy_end); + + gnc_gdate_set_fiscal_year_end(date, fy_end); + g_date_subtract_years(date, 1); +} diff --git a/libgnucash/engine/gnc-date.h b/libgnucash/engine/gnc-date.h index 432a00e992..aaff8d49b9 100644 --- a/libgnucash/engine/gnc-date.h +++ b/libgnucash/engine/gnc-date.h @@ -1,11 +1,12 @@ -/*************************************************************************** +/******************************************************************** * gnc-date.h (to be renamed qofdate.h) * * Copyright (C) 1997 Robin D. Clark * Copyright (C) 1998-2000, 2003 Linas Vepstas * Copyright 2005 Neil Williams + * Copyright (C) 2005 David Hampton * Copyright 2012 John Ralls - ****************************************************************************/ + ********************************************************************/ /********************************************************************\ * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * @@ -54,7 +55,7 @@ If a file-io backend needs date handling, it should do it itself, instead of depending on the routines here. - (to be renamed qofdate.h in libqof2.) + (to be renamed qofdate.h in libqof2.) @author Copyright (C) 1997 Robin D. Clark @author Copyright (C) 1998-2001,2003 Linas Vepstas @@ -153,6 +154,7 @@ typedef enum GNCDATE_MONTH_ABBREV, GNCDATE_MONTH_NAME } GNCDateMonthFormat; + /* Replacements for POSIX functions which use time_t. Time_t is still * 32 bits in Microsoft Windows, Apple OSX, and some BSD versions even * when the rest of the system is 64-bits, as well as all 32-bit @@ -348,7 +350,6 @@ GDate timespec_to_gdate (Timespec ts); /** Turns a GDate into a Timespec, returning the first second of the day */ Timespec gdate_to_timespec (GDate d); - /** Convert a day, month, and year to a Timespec, returning the first second of the day */ Timespec gnc_dmy2timespec (gint day, gint month, gint year); @@ -410,7 +411,8 @@ void gnc_timespec2dmy (Timespec ts, gint *day, gint *month, gint *year); // @} -/* ------------------------------------------------------------------------ */ +/* ======================================================== */ + /** \name QofDateFormat functions */ // @{ /** The qof_date_format_get routine returns the date format that @@ -448,6 +450,8 @@ const gchar *qof_date_format_get_string(QofDateFormat df); const gchar *qof_date_text_format_get_string(QofDateFormat df); // @} +/* ======================================================== */ + /** * The qof_date_completion_set() routing sets the date completion method to * one of QOF_DATE_COMPLETION_THISYEAR (for completing the year to @@ -467,6 +471,8 @@ void qof_date_completion_set(QofDateCompletion dc, int backmonths); */ gchar dateSeparator(void); +/* ======================================================== */ + /** \name Date Printing/Scanning functions */ // @{ @@ -568,6 +574,9 @@ size_t qof_print_date_time_buff (char * buff, size_t len, time64 secs); gboolean qof_scan_date (const char *buff, int *day, int *month, int *year); // @} + +/* ======================================================== */ + /** \name Date Start/End Adjustment routines * Given a time value, adjust it to be the beginning or end of that day. */ @@ -665,6 +674,196 @@ char * gnc_date_timestamp (void); void gnc_dow_abbrev(gchar *buf, int buf_len, int dow); //@} + +/* ======================================================== */ + +/** \name GDate hash table support */ +// @{ + +/** Compares two GDate*'s for equality; useful for using GDate*'s as + * GHashTable keys. */ +gint gnc_gdate_equal(gconstpointer gda, gconstpointer gdb); + + +/** Provides a "hash" of a GDate* value; useful for using GDate*'s as + * GHashTable keys. */ +guint gnc_gdate_hash( gconstpointer gd ); + +//@} + +/* ======================================================== */ + +/** \name GDate to time64 conversions */ +// @{ + +/** The gnc_time64_get_day_start() routine will take the given time in + * GLib GDate format and adjust it to the first second of that day. + */ +time64 gnc_time64_get_day_start_gdate (const GDate *date); + +/** The gnc_time64_get_day_end() routine will take the given time in + * GLib GDate format and adjust it to the last second of that day. + */ +time64 gnc_time64_get_day_end_gdate (const GDate *date); + +//@} + +/* ======================================================== */ + +/** \name Date Manipulation */ +// @{ + +/** This function modifies a GDate to set it to the first day of the + * month in which it falls. For example, if this function is called + * with a date of 2003-09-24 the date will be modified to 2003-09-01. + * + * @param date The GDate to modify. */ +void gnc_gdate_set_month_start (GDate *date); + + +/** This function modifies a GDate to set it to the last day of the + * month in which it falls. For example, if this function is called + * with a date of 2003-09-24 the date will be modified to 2003-09-30. + * + * @param date The GDate to modify. */ +void gnc_gdate_set_month_end (GDate *date); + + +/** This function modifies a GDate to set it to the first day of the + * month prior to the one in which it falls. For example, if this + * function is called with a date of 2003-09-24 the date will be + * modified to 2003-08-01. + * + * @param date The GDate to modify. */ +void gnc_gdate_set_prev_month_start (GDate *date); + + +/** This function modifies a GDate to set it to the last day of the + * month prior to the one in which it falls. For example, if this + * function is called with a date of 2003-09-24 the date will be + * modified to 2003-08-31. + * + * @param date The GDate to modify. */ +void gnc_gdate_set_prev_month_end (GDate *date); + + +/** This function modifies a GDate to set it to the first day of the + * quarter in which it falls. For example, if this function is called + * with a date of 2003-09-24 the date will be modified to 2003-09-01. + * + * @param date The GDate to modify. */ +void gnc_gdate_set_quarter_start (GDate *date); + + +/** This function modifies a GDate to set it to the last day of the + * quarter in which it falls. For example, if this function is called + * with a date of 2003-09-24 the date will be modified to 2003-12-31. + * + * @param date The GDate to modify. */ +void gnc_gdate_set_quarter_end (GDate *date); + + +/** This function modifies a GDate to set it to the first day of the + * quarter prior to the one in which it falls. For example, if this + * function is called with a date of 2003-09-24 the date will be + * modified to 2003-06-01. + * + * @param date The GDate to modify. */ +void gnc_gdate_set_prev_quarter_start (GDate *date); + + +/** This function modifies a GDate to set it to the last day of the + * quarter prior to the one in which it falls. For example, if this + * function is called with a date of 2003-09-24 the date will be + * modified to 2003-07-31. + * + * @param date The GDate to modify. */ +void gnc_gdate_set_prev_quarter_end (GDate *date); + + +/** This function modifies a GDate to set it to the first day of the + * year in which it falls. For example, if this function is called + * with a date of 2003-09-24 the date will be modified to 2003-01-01. + * + * @param date The GDate to modify. */ +void gnc_gdate_set_year_start (GDate *date); + + +/** This function modifies a GDate to set it to the last day of the + * year in which it falls. For example, if this function is called + * with a date of 2003-09-24 the date will be modified to 2003-12-31. + * + * @param date The GDate to modify. */ +void gnc_gdate_set_year_end (GDate *date); + + +/** This function modifies a GDate to set it to the first day of the + * year prior to the one in which it falls. For example, if this + * function is called with a date of 2003-09-24 the date will be + * modified to 2002-01-01. + * + * @param date The GDate to modify. */ +void gnc_gdate_set_prev_year_start (GDate *date); + + +/** This function modifies a GDate to set it to the last day of the + * year prior to the one in which it falls. For example, if this + * function is called with a date of 2003-09-24 the date will be + * modified to 2002-12-31. + * + * @param date The GDate to modify. */ +void gnc_gdate_set_prev_year_end (GDate *date); + + +/** This function modifies a GDate to set it to the first day of the + * fiscal year in which it falls. For example, if this function is + * called with a date of 2003-09-24 and a fiscal year ending July + * 31st, the date will be modified to 2003-08-01. + * + * @param date The GDate to modify. + * + * @param year_end A GDate containing the last month and day of the + * fiscal year. The year field of this argument is ignored. */ +void gnc_gdate_set_fiscal_year_start (GDate *date, const GDate *year_end); + + +/** This function modifies a GDate to set it to the last day of the + * fiscal year in which it falls. For example, if this function is + * called with a date of 2003-09-24 and a fiscal year ending July + * 31st, the date will be modified to 2004-07-31. + * + * @param date The GDate to modify. + * + * @param year_end A GDate containing the last month and day of the + * fiscal year. The year field of this argument is ignored. */ +void gnc_gdate_set_fiscal_year_end (GDate *date, const GDate *year_end); + + +/** This function modifies a GDate to set it to the first day of the + * fiscal year prior to the one in which it falls. For example, if + * this function is called with a date of 2003-09-24 and a fiscal + * year ending July 31st, the date will be modified to 2002-08-01. + * + * @param date The GDate to modify. + * + * @param year_end A GDate containing the last month and day of the + * fiscal year. The year field of this argument is ignored. */ +void gnc_gdate_set_prev_fiscal_year_start (GDate *date, const GDate *year_end); + + +/** This function modifies a GDate to set it to the last day of the + * fiscal year prior to the one in which it falls. For example, if + * this function is called with a date of 2003-09-24 and a fiscal + * year ending July 31st, the date will be modified to 2003-07-31. + * + * @param date The GDate to modify. + * + * @param year_end A GDate containing the last month and day of the + * fiscal year. The year field of this argument is ignored. */ +void gnc_gdate_set_prev_fiscal_year_end (GDate *date, const GDate *year_end); + +//@} + //@} #ifdef __cplusplus } diff --git a/libgnucash/engine/gnc-gdate-utils.c b/libgnucash/engine/gnc-gdate-utils.c deleted file mode 100644 index 014a0e2369..0000000000 --- a/libgnucash/engine/gnc-gdate-utils.c +++ /dev/null @@ -1,286 +0,0 @@ -/* - * gnc-gdate-utils.c -- utility functions for manipulating - * GDate data structures from GLib - * Copyright (C) 2005 David Hampton - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, contact: - * - * Free Software Foundation Voice: +1-617-542-5942 - * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 - * Boston, MA 02110-1301, USA gnu@gnu.org - */ - -#include "config.h" -#include - -#include "gnc-gdate-utils.h" - -gboolean -gnc_gdate_equal(gconstpointer gda, gconstpointer gdb) -{ - return (g_date_compare( (GDate*)gda, (GDate*)gdb ) == 0 ? TRUE : FALSE); -} - -guint -gnc_gdate_hash( gconstpointer gd ) -{ - gint val = (g_date_get_year( (GDate*)gd ) * 10000) - + (g_date_get_month( (GDate*)gd ) * 100) - + g_date_get_day( (GDate*)gd ); - return g_int_hash( &val ); -} - - -time64 -gnc_time64_get_day_start_gdate (const GDate *date) -{ - struct tm stm; - time64 secs; - - /* First convert to a 'struct tm' */ - g_date_to_struct_tm (date, &stm); - - /* Then convert to number of seconds */ - secs = gnc_mktime (&stm); - return secs; -} - -time64 -gnc_time64_get_day_end_gdate (const GDate *date) -{ - struct tm stm; - time64 secs; - - /* First convert to a 'struct tm' */ - g_date_to_struct_tm(date, &stm); - - /* Force to th last second of the day */ - stm.tm_hour = 23; - stm.tm_min = 59; - stm.tm_sec = 59; - stm.tm_isdst = -1; - - /* Then convert to number of seconds */ - secs = gnc_mktime (&stm); - return secs; -} - - -void -gnc_gdate_set_month_start (GDate *date) -{ - g_date_set_day(date, 1); -} - - -/** Convert a GDate to the last day of the month. This routine has no - * knowledge of how many days are in a month, whether its a leap - * year, etc. All that information is contained in the glib date - * functions. - * - * @param date The GDate to modify. - */ -void -gnc_gdate_set_month_end (GDate *date) -{ - /* First set the start of next month. */ - g_date_set_day(date, 1); - g_date_add_months(date, 1); - - /* Then back up one day */ - g_date_subtract_days(date, 1); -} - - -/** Convert a GDate to the first day of the prebvious month. This - * routine has no knowledge of how many days are in a month, whether - * its a leap year, etc. All that information is contained in the - * glib date functions. - * - * @param date The GDate to modify. - */ -void -gnc_gdate_set_prev_month_start (GDate *date) -{ - g_date_set_day(date, 1); - g_date_subtract_months(date, 1); -} - - -/** Convert a GDate to the last day of the prebvious month. This - * routine has no knowledge of how many days are in a month, whether - * its a leap year, etc. All that information is contained in the - * glib date functions. - * - * @param date The GDate to modify. - */ -void -gnc_gdate_set_prev_month_end (GDate *date) -{ - /* This will correctly handle the varying month lengths */ - g_date_set_day(date, 1); - g_date_subtract_days(date, 1); -} - -/* ========== */ - -void -gnc_gdate_set_quarter_start (GDate *date) -{ - gint months; - - /* Set the date to the first day of the specified month. */ - g_date_set_day(date, 1); - - /* Back up 0-2 months */ - months = (g_date_get_month(date) - G_DATE_JANUARY) % 3; - g_date_subtract_months(date, months); -} - - -void -gnc_gdate_set_quarter_end (GDate *date) -{ - gint months; - - /* Set the date to the first day of the specified month. */ - g_date_set_day(date, 1); - - /* Add 1-3 months to get the first day of the next quarter.*/ - months = (g_date_get_month(date) - G_DATE_JANUARY) % 3; - g_date_add_months(date, 3 - months); - - /* Now back up one day */ - g_date_subtract_days(date, 1); -} - - -void -gnc_gdate_set_prev_quarter_start (GDate *date) -{ - gnc_gdate_set_quarter_start(date); - g_date_subtract_months(date, 3); -} - - -void -gnc_gdate_set_prev_quarter_end (GDate *date) -{ - gnc_gdate_set_quarter_end(date); - g_date_subtract_months(date, 3); -} - -/* ========== */ - -void -gnc_gdate_set_year_start (GDate *date) -{ - g_date_set_month(date, G_DATE_JANUARY); - g_date_set_day(date, 1); -} - - -void -gnc_gdate_set_year_end (GDate *date) -{ - g_date_set_month(date, G_DATE_DECEMBER); - g_date_set_day(date, 31); -} - - -void -gnc_gdate_set_prev_year_start (GDate *date) -{ - gnc_gdate_set_year_start(date); - g_date_subtract_years(date, 1); -} - - -void -gnc_gdate_set_prev_year_end (GDate *date) -{ - gnc_gdate_set_year_end(date); - g_date_subtract_years(date, 1); -} - -/* ========== */ - -void -gnc_gdate_set_fiscal_year_start (GDate *date, - const GDate *fy_end) -{ - GDate temp; - gboolean new_fy; - - g_return_if_fail(date); - g_return_if_fail(fy_end); - - /* Compute the FY end that occurred this CY */ - temp = *fy_end; - g_date_set_year(&temp, g_date_get_year(date)); - - /* Has it already passed? */ - new_fy = (g_date_compare(date, &temp) > 0); - - /* Set start date */ - *date = temp; - g_date_add_days(date, 1); - if (!new_fy) - g_date_subtract_years(date, 1); -} - -void -gnc_gdate_set_fiscal_year_end (GDate *date, - const GDate *fy_end) -{ - GDate temp; - gboolean new_fy; - - g_return_if_fail(date); - g_return_if_fail(fy_end); - - /* Compute the FY end that occurred this CY */ - temp = *fy_end; - g_date_set_year(&temp, g_date_get_year(date)); - - /* Has it already passed? */ - new_fy = (g_date_compare(date, &temp) > 0); - - /* Set end date */ - *date = temp; - if (new_fy) - g_date_add_years(date, 1); -} - -void -gnc_gdate_set_prev_fiscal_year_start (GDate *date, - const GDate *fy_end) -{ - g_return_if_fail(date); - g_return_if_fail(fy_end); - - gnc_gdate_set_fiscal_year_start(date, fy_end); - g_date_subtract_years(date, 1); -} - -void -gnc_gdate_set_prev_fiscal_year_end (GDate *date, - const GDate *fy_end) -{ - g_return_if_fail(date); - g_return_if_fail(fy_end); - - gnc_gdate_set_fiscal_year_end(date, fy_end); - g_date_subtract_years(date, 1); -} diff --git a/libgnucash/engine/gnc-gdate-utils.h b/libgnucash/engine/gnc-gdate-utils.h deleted file mode 100644 index 3fd8830119..0000000000 --- a/libgnucash/engine/gnc-gdate-utils.h +++ /dev/null @@ -1,228 +0,0 @@ -/* - * gnc-gdate-utils.h -- utility functions for manipulating - * GDate data structures from GLib - * Copyright (C) 2005 David Hampton - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, contact: - * - * Free Software Foundation Voice: +1-617-542-5942 - * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 - * Boston, MA 02110-1301, USA gnu@gnu.org - */ - -/** @addtogroup GLib - @{ */ -/** @addtogroup GDate GDate Utilities - - This file provides routines that help make it easier to use GDates - from within Gnucash. A GDate is a data strucutre provided by GLib - that handles dates from year 1 to year 9999. - - @{ */ -/** @file gnc-gdate-utils.h - * @brief GDate helper routines. - * @author Copyright (C) 2005 David Hampton - */ - -#ifndef GNC_GDATE_UTILS_H -#define GNC_GDATE_UTILS_H - -#include - -/** @name GDate hash table support - @{ */ - -/** Compares two GDate*'s for equality; useful for using GDate*'s as - * GHashTable keys. */ -gint gnc_gdate_equal(gconstpointer gda, gconstpointer gdb); - - -/** Provides a "hash" of a GDate* value; useful for using GDate*'s as - * GHashTable keys. */ -guint gnc_gdate_hash( gconstpointer gd ); - -/** @} */ - -/** @name GDate to time64 conversions - @{ */ - -/** The gnc_time64_get_day_start() routine will take the given time in - * GLib GDate format and adjust it to the first second of that day. - */ -time64 gnc_time64_get_day_start_gdate (const GDate *date); - -/** The gnc_time64_get_day_end() routine will take the given time in - * GLib GDate format and adjust it to the last second of that day. - */ -time64 gnc_time64_get_day_end_gdate (const GDate *date); - -/** @} */ - -/** @name Date Manipulation - @{ */ - -/** This function modifies a GDate to set it to the first day of the - * month in which it falls. For example, if this function is called - * with a date of 2003-09-24 the date will be modified to 2003-09-01. - * - * @param date The GDate to modify. */ -void gnc_gdate_set_month_start (GDate *date); - - -/** This function modifies a GDate to set it to the last day of the - * month in which it falls. For example, if this function is called - * with a date of 2003-09-24 the date will be modified to 2003-09-30. - * - * @param date The GDate to modify. */ -void gnc_gdate_set_month_end (GDate *date); - - -/** This function modifies a GDate to set it to the first day of the - * month prior to the one in which it falls. For example, if this - * function is called with a date of 2003-09-24 the date will be - * modified to 2003-08-01. - * - * @param date The GDate to modify. */ -void gnc_gdate_set_prev_month_start (GDate *date); - - -/** This function modifies a GDate to set it to the last day of the - * month prior to the one in which it falls. For example, if this - * function is called with a date of 2003-09-24 the date will be - * modified to 2003-08-31. - * - * @param date The GDate to modify. */ -void gnc_gdate_set_prev_month_end (GDate *date); - - -/** This function modifies a GDate to set it to the first day of the - * quarter in which it falls. For example, if this function is called - * with a date of 2003-09-24 the date will be modified to 2003-09-01. - * - * @param date The GDate to modify. */ -void gnc_gdate_set_quarter_start (GDate *date); - - -/** This function modifies a GDate to set it to the last day of the - * quarter in which it falls. For example, if this function is called - * with a date of 2003-09-24 the date will be modified to 2003-12-31. - * - * @param date The GDate to modify. */ -void gnc_gdate_set_quarter_end (GDate *date); - - -/** This function modifies a GDate to set it to the first day of the - * quarter prior to the one in which it falls. For example, if this - * function is called with a date of 2003-09-24 the date will be - * modified to 2003-06-01. - * - * @param date The GDate to modify. */ -void gnc_gdate_set_prev_quarter_start (GDate *date); - - -/** This function modifies a GDate to set it to the last day of the - * quarter prior to the one in which it falls. For example, if this - * function is called with a date of 2003-09-24 the date will be - * modified to 2003-07-31. - * - * @param date The GDate to modify. */ -void gnc_gdate_set_prev_quarter_end (GDate *date); - - -/** This function modifies a GDate to set it to the first day of the - * year in which it falls. For example, if this function is called - * with a date of 2003-09-24 the date will be modified to 2003-01-01. - * - * @param date The GDate to modify. */ -void gnc_gdate_set_year_start (GDate *date); - - -/** This function modifies a GDate to set it to the last day of the - * year in which it falls. For example, if this function is called - * with a date of 2003-09-24 the date will be modified to 2003-12-31. - * - * @param date The GDate to modify. */ -void gnc_gdate_set_year_end (GDate *date); - - -/** This function modifies a GDate to set it to the first day of the - * year prior to the one in which it falls. For example, if this - * function is called with a date of 2003-09-24 the date will be - * modified to 2002-01-01. - * - * @param date The GDate to modify. */ -void gnc_gdate_set_prev_year_start (GDate *date); - - -/** This function modifies a GDate to set it to the last day of the - * year prior to the one in which it falls. For example, if this - * function is called with a date of 2003-09-24 the date will be - * modified to 2002-12-31. - * - * @param date The GDate to modify. */ -void gnc_gdate_set_prev_year_end (GDate *date); - - -/** This function modifies a GDate to set it to the first day of the - * fiscal year in which it falls. For example, if this function is - * called with a date of 2003-09-24 and a fiscal year ending July - * 31st, the date will be modified to 2003-08-01. - * - * @param date The GDate to modify. - * - * @param year_end A GDate containing the last month and day of the - * fiscal year. The year field of this argument is ignored. */ -void gnc_gdate_set_fiscal_year_start (GDate *date, const GDate *year_end); - - -/** This function modifies a GDate to set it to the last day of the - * fiscal year in which it falls. For example, if this function is - * called with a date of 2003-09-24 and a fiscal year ending July - * 31st, the date will be modified to 2004-07-31. - * - * @param date The GDate to modify. - * - * @param year_end A GDate containing the last month and day of the - * fiscal year. The year field of this argument is ignored. */ -void gnc_gdate_set_fiscal_year_end (GDate *date, const GDate *year_end); - - -/** This function modifies a GDate to set it to the first day of the - * fiscal year prior to the one in which it falls. For example, if - * this function is called with a date of 2003-09-24 and a fiscal - * year ending July 31st, the date will be modified to 2002-08-01. - * - * @param date The GDate to modify. - * - * @param year_end A GDate containing the last month and day of the - * fiscal year. The year field of this argument is ignored. */ -void gnc_gdate_set_prev_fiscal_year_start (GDate *date, const GDate *year_end); - - -/** This function modifies a GDate to set it to the last day of the - * fiscal year prior to the one in which it falls. For example, if - * this function is called with a date of 2003-09-24 and a fiscal - * year ending July 31st, the date will be modified to 2003-07-31. - * - * @param date The GDate to modify. - * - * @param year_end A GDate containing the last month and day of the - * fiscal year. The year field of this argument is ignored. */ -void gnc_gdate_set_prev_fiscal_year_end (GDate *date, const GDate *year_end); - -/** @} */ - -#endif /* GNC_GDATE_UTILS_H */ -/** @} */ -/** @} */ diff --git a/libgnucash/engine/gnc-pricedb.c b/libgnucash/engine/gnc-pricedb.c index 32fcd3192f..bd4653c155 100644 --- a/libgnucash/engine/gnc-pricedb.c +++ b/libgnucash/engine/gnc-pricedb.c @@ -26,9 +26,9 @@ #include #include +#include "gnc-date.h" #include "gnc-pricedb-p.h" #include -#include "gnc-gdate-utils.h" /* This static indicates the debugging module that this .o belongs to. */ static QofLogModule log_module = GNC_MOD_PRICE; diff --git a/po/POTFILES.in b/po/POTFILES.in index 8068953c43..51e94f54e4 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -486,7 +486,6 @@ libgnucash/app-utils/gnc-component-manager.c libgnucash/app-utils/gnc-entry-quickfill.c libgnucash/app-utils/gnc-euro.c libgnucash/app-utils/gnc-exp-parser.c -libgnucash/app-utils/gnc-gdate-utils.c libgnucash/app-utils/gnc-gettext-util.c libgnucash/app-utils/gnc-gsettings.c libgnucash/app-utils/gnc-helpers.c