This commit is contained in:
Geert Janssens 2017-08-29 22:24:43 +02:00
commit a670783eb6
35 changed files with 1639 additions and 857 deletions

View File

@ -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 <gnc-gdate-utils.h>
/* This static indicates the debugging module that this .o belongs to. */
static QofLogModule log_module = GNC_MOD_GUI;

View File

@ -43,7 +43,6 @@
#include <ctype.h> /* isdigit */
#include <stdio.h>
#include <gnc-gdate-utils.h>
#include "gnc-date.h"
#include "gnc-engine.h"
#include "dialog-utils.h"

View File

@ -33,11 +33,11 @@
#include "config.h"
#include <glib.h>
#include <glib-object.h>
#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 <gnc-gdate-utils.h>
struct _GncDenseCalStore
{

View File

@ -30,7 +30,7 @@
#include <gtk/gtk.h>
#include <math.h>
#include <stdlib.h>
#include <gnc-gdate-utils.h>
#include "gnc-date.h"
#include "dialog-utils.h"
/**

View File

@ -37,7 +37,6 @@
#include "gnc-date.h"
#include "gnc-period-select.h"
#include "gnc-prefs.h"
#include <gnc-gdate-utils.h>
#include "dialog-utils.h"
enum

View File

@ -29,11 +29,11 @@
#include <glib/gi18n.h>
#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;

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -32,13 +32,13 @@
#include "qof.h"
#include <gnc-gdate-utils.h>
#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"

View File

@ -32,6 +32,7 @@
#include <time.h>
#include "dialog-utils.h"
#include "gnc-accounting-period.h"
#include "gnc-amount-edit.h"
#include "gnc-commodity-edit.h"
#include "gnc-general-select.h"
@ -80,6 +81,10 @@ typedef struct
GtkWidget * edit_button;
GtkWidget * remove_button;
GtkWidget *remove_dialog;
GtkTreeView *remove_view;
gint remove_source;
} PricesDialog;
@ -175,13 +180,12 @@ gnc_prices_dialog_remove_clicked (GtkWidget *widget, gpointer data)
}
length = g_list_length(price_list);
if (length > 1)
if (length > 0)
{
gchar *message;
message = g_strdup_printf
(/* Translators: %d is the number of prices. This
is a ngettext(3) message. */
(/* Translators: %d is the number of prices. This is a ngettext(3) message. */
ngettext("Are you sure you want to delete the selected price?",
"Are you sure you want to delete the %d selected prices?",
length),
@ -216,53 +220,288 @@ gnc_prices_dialog_remove_clicked (GtkWidget *widget, gpointer data)
}
/** Enumeration for the price delete list-store */
enum GncPriceColumn {PRICED_FULL_NAME, PRICED_COMM, PRICED_DATE, PRICED_COUNT};
static Timespec
gnc_prices_dialog_load_view (GtkTreeView *view, GNCPriceDB *pdb)
{
GtkTreeModel *model = gtk_tree_view_get_model (view);
const gnc_commodity_table *commodity_table = gnc_get_current_commodities ();
GList *namespace_list = gnc_commodity_table_get_namespaces (commodity_table);
gnc_commodity *tmp_commodity = NULL;
char *tmp_namespace = NULL;
GList *commodity_list = NULL;
GtkTreeIter iter;
Timespec oldest_ts = timespec_now ();
oldest_ts.tv_nsec = 0;
namespace_list = g_list_first (namespace_list);
while (namespace_list != NULL)
{
tmp_namespace = namespace_list->data;
DEBUG("Looking at namespace %s", tmp_namespace);
commodity_list = gnc_commodity_table_get_commodities (commodity_table, tmp_namespace);
commodity_list = g_list_first (commodity_list);
while (commodity_list != NULL)
{
gint num = 0;
tmp_commodity = commodity_list->data;
num = gnc_pricedb_num_prices (pdb, tmp_commodity);
DEBUG("Looking at commodity %s, Number of prices %d", gnc_commodity_get_fullname (tmp_commodity), num);
if (num > 0)
{
PriceList *list = gnc_pricedb_get_prices (pdb, tmp_commodity, NULL);
GList *node = g_list_last (list);
GNCPrice *price = (GNCPrice*)node->data;
Timespec price_ts = gnc_price_get_time (price);
const gchar *name_str = gnc_commodity_get_printname (tmp_commodity);
gchar *date_str, *num_str;
if (timespec_cmp(&oldest_ts, &price_ts) >= 0)
oldest_ts.tv_sec = price_ts.tv_sec;
date_str = g_strdup (gnc_print_date (price_ts));
num_str = g_strdup_printf ("%d", num);
gtk_list_store_append (GTK_LIST_STORE(model), &iter);
gtk_list_store_set (GTK_LIST_STORE(model), &iter, PRICED_FULL_NAME, name_str,
PRICED_COMM, tmp_commodity, PRICED_DATE, date_str, PRICED_COUNT, num_str, -1);
g_free (date_str);
g_free (num_str);
gnc_price_unref (price);
}
commodity_list = g_list_next (commodity_list);
}
namespace_list = g_list_next (namespace_list);
}
g_list_free (commodity_list);
g_list_free (namespace_list);
return oldest_ts;
}
static GList *
gnc_prices_dialog_get_commodities (GtkTreeView *view)
{
GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW(view));
GtkTreeSelection *selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(view));
GList *list = gtk_tree_selection_get_selected_rows (selection, &model);
GList *row;
GList *comm_list = NULL;
GtkTreeIter iter;
gnc_commodity *comm;
// Walk the list
for (row = g_list_first (list); row; row = g_list_next (row))
{
if (gtk_tree_model_get_iter (model, &iter, row->data))
{
gtk_tree_model_get (model, &iter, PRICED_COMM, &comm, -1);
comm_list = g_list_append (comm_list, comm);
}
}
g_list_foreach (list, (GFunc) gtk_tree_path_free, NULL);
g_list_free (list);
return comm_list;
}
static void
change_source_flag (PriceRemoveSourceFlags source, gboolean set, gpointer data)
{
PricesDialog *pdb_dialog = data;
GtkWidget *w = gtk_dialog_get_widget_for_response (GTK_DIALOG(pdb_dialog->remove_dialog), GTK_RESPONSE_OK);
gboolean enable_button;
if (set)
pdb_dialog->remove_source = pdb_dialog->remove_source | source;
else
pdb_dialog->remove_source = pdb_dialog->remove_source & (~source);
// Check if we have the required options to enable OK button
enable_button = (pdb_dialog->remove_source > 8 ? TRUE : FALSE); // commodities flag is 8
gtk_widget_set_sensitive (w, enable_button);
DEBUG("Source is: %d, remove_source is %d", source, pdb_dialog->remove_source);
}
static void
check_event_fq_cb (GtkWidget *widget, gpointer data)
{
PricesDialog *pdb_dialog = data;
gboolean active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widget));
change_source_flag (PRICE_REMOVE_SOURCE_FQ, active, pdb_dialog);
}
static void
check_event_user_cb (GtkWidget *widget, gpointer data)
{
PricesDialog *pdb_dialog = data;
gboolean active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widget));
change_source_flag (PRICE_REMOVE_SOURCE_USER, active, pdb_dialog);
}
static void
check_event_app_cb (GtkWidget *widget, gpointer data)
{
PricesDialog *pdb_dialog = data;
gboolean active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widget));
change_source_flag (PRICE_REMOVE_SOURCE_APP, active, pdb_dialog);
}
static void
selection_changed_cb (GtkTreeSelection *selection, gpointer data)
{
PricesDialog *pdb_dialog = data;
GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW(pdb_dialog->remove_view));
GList *rows = gtk_tree_selection_get_selected_rows (selection, &model);
gboolean have_rows = (g_list_length (rows) > 0 ? TRUE : FALSE);
change_source_flag (PRICE_REMOVE_SOURCE_COMM, have_rows, pdb_dialog);
}
static GDate
get_fiscal_end_date (void)
{
Timespec ts_end;
GDate f_end;
timespecFromTime64 (&ts_end, gnc_accounting_period_fiscal_end());
f_end = timespec_to_gdate (ts_end);
PINFO("Fiscal end date is %s", qof_print_date (gnc_accounting_period_fiscal_end()));
return f_end;
}
void
gnc_prices_dialog_remove_old_clicked (GtkWidget *widget, gpointer data)
{
PricesDialog *pdb_dialog = data;
GtkBuilder *builder;
GtkWidget *dialog, *button, *date, *label, *box;
GtkWidget *date, *label, *box;
GtkWidget *button;
GtkTreeSelection *selection;
GtkTreeViewColumn *tree_column;
GtkCellRenderer *cr;
Timespec first_ts;
gint result;
gboolean delete_user, delete_last;
ENTER(" ");
builder = gtk_builder_new();
gnc_builder_add_from_file (builder, "dialog-price.glade", "liststore4");
gnc_builder_add_from_file (builder, "dialog-price.glade", "deletion_date_dialog");
dialog = GTK_WIDGET(gtk_builder_get_object (builder, "deletion_date_dialog"));
pdb_dialog->remove_dialog = GTK_WIDGET(gtk_builder_get_object (builder, "deletion_date_dialog"));
box = GTK_WIDGET(gtk_builder_get_object (builder, "date_hbox"));
date = gnc_date_edit_new (time (NULL), FALSE, FALSE);
gtk_box_pack_start (GTK_BOX (box), date, TRUE, TRUE, 0);
gtk_box_pack_start (GTK_BOX (box), date, FALSE, FALSE, 0);
gtk_widget_show (date);
gtk_entry_set_activates_default(GTK_ENTRY(GNC_DATE_EDIT(date)->date_entry), TRUE);
label = GTK_WIDGET(gtk_builder_get_object (builder, "date_label"));
gnc_date_make_mnemonic_target (GNC_DATE_EDIT(date), label);
// Setup the commodity view
pdb_dialog->remove_view = GTK_TREE_VIEW(gtk_builder_get_object (builder, "commodty_treeview"));
selection = gtk_tree_view_get_selection (pdb_dialog->remove_view);
gtk_tree_selection_set_mode (selection, GTK_SELECTION_MULTIPLE);
// Add Entries column this way as align does not seem to work from builder
tree_column = gtk_tree_view_column_new();
gtk_tree_view_column_set_title (tree_column, _("Entries"));
gtk_tree_view_append_column (GTK_TREE_VIEW(pdb_dialog->remove_view), tree_column);
gtk_tree_view_column_set_alignment (tree_column, 0.5);
gtk_tree_view_column_set_expand (tree_column, TRUE);
cr = gtk_cell_renderer_text_new();
gtk_tree_view_column_pack_start (tree_column, cr, TRUE);
// set 'xalign' property of the cell renderer
gtk_tree_view_column_set_attributes (tree_column, cr, "text", PRICED_COUNT, NULL);
gtk_cell_renderer_set_alignment (cr, 0.5, 0.5);
// Load the view and get the earliest date
first_ts = gnc_prices_dialog_load_view (pdb_dialog->remove_view, pdb_dialog->price_db);
gtk_tree_selection_select_all (selection);
g_signal_connect (selection, "changed", G_CALLBACK(selection_changed_cb), pdb_dialog);
gtk_builder_connect_signals_full (builder, gnc_builder_connect_full_func, pdb_dialog);
gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (pdb_dialog->dialog));
gtk_window_set_transient_for (GTK_WINDOW (pdb_dialog->remove_dialog), GTK_WINDOW (pdb_dialog->dialog));
result = gtk_dialog_run (GTK_DIALOG (dialog));
pdb_dialog->remove_source = 9; // FQ and Commodities highlighted
button = GTK_WIDGET(gtk_builder_get_object (builder, "checkbutton_fq"));
g_signal_connect (button, "toggled", G_CALLBACK (check_event_fq_cb), pdb_dialog);
button = GTK_WIDGET(gtk_builder_get_object (builder, "checkbutton_user"));
g_signal_connect (button, "toggled", G_CALLBACK (check_event_user_cb), pdb_dialog);
button = GTK_WIDGET(gtk_builder_get_object (builder, "checkbutton_app"));
g_signal_connect (button, "toggled", G_CALLBACK (check_event_app_cb), pdb_dialog);
result = gtk_dialog_run (GTK_DIALOG (pdb_dialog->remove_dialog));
if (result == GTK_RESPONSE_OK)
{
Timespec ts;
const char *fmt = _("Are you sure you want to delete these prices ?");
GList *comm_list = gnc_prices_dialog_get_commodities (pdb_dialog->remove_view);
DEBUG("deleting prices");
ts.tv_sec = gnc_date_edit_get_date (GNC_DATE_EDIT (date));
ts.tv_nsec = 0;
// Are you sure you want to delete the entries and we have commodities
if ((g_list_length (comm_list) != 0) && (gnc_verify_dialog (pdb_dialog->remove_dialog, FALSE, fmt, NULL)))
{
Timespec last_ts;
GDate fiscal_end_date = get_fiscal_end_date ();
PriceRemoveSourceFlags source = PRICE_REMOVE_SOURCE_FQ;
PriceRemoveKeepOptions keep = PRICE_REMOVE_KEEP_NONE;
button = GTK_WIDGET(gtk_builder_get_object (builder, "delete_manual"));
delete_user = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button));
button = GTK_WIDGET(gtk_builder_get_object (builder, "delete_last"));
delete_last = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button));
DEBUG("deleting prices");
last_ts.tv_sec = gnc_date_edit_get_date (GNC_DATE_EDIT (date));
last_ts.tv_nsec = 0;
gnc_pricedb_remove_old_prices(pdb_dialog->price_db, ts,
delete_user, delete_last);
button = GTK_WIDGET(gtk_builder_get_object (builder, "radiobutton_last_week"));
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button)))
keep = PRICE_REMOVE_KEEP_LAST_WEEKLY;
button = GTK_WIDGET(gtk_builder_get_object (builder, "radiobutton_last_month"));
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button)))
keep = PRICE_REMOVE_KEEP_LAST_MONTHLY;
button = GTK_WIDGET(gtk_builder_get_object (builder, "radiobutton_last_quarter"));
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button)))
keep = PRICE_REMOVE_KEEP_LAST_QUARTERLY;
button = GTK_WIDGET(gtk_builder_get_object (builder, "radiobutton_last_period"));
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button)))
keep = PRICE_REMOVE_KEEP_LAST_PERIOD;
button = GTK_WIDGET(gtk_builder_get_object (builder, "radiobutton_scaled"));
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button)))
keep = PRICE_REMOVE_KEEP_SCALED;
if (keep != PRICE_REMOVE_KEEP_SCALED)
gnc_pricedb_remove_old_prices (pdb_dialog->price_db, comm_list, &fiscal_end_date,
last_ts, pdb_dialog->remove_source, keep);
else
{
Timespec tmp_ts;
GDate tmp_date = timespec_to_gdate (last_ts);
g_date_subtract_months (&tmp_date, 6);
tmp_ts = gdate_to_timespec (tmp_date);
gnc_pricedb_remove_old_prices (pdb_dialog->price_db, comm_list, &fiscal_end_date, tmp_ts,
pdb_dialog->remove_source, PRICE_REMOVE_KEEP_LAST_WEEKLY);
g_date_subtract_months (&tmp_date, 6);
tmp_ts = gdate_to_timespec (tmp_date);
gnc_pricedb_remove_old_prices (pdb_dialog->price_db, comm_list, &fiscal_end_date, tmp_ts,
pdb_dialog->remove_source, PRICE_REMOVE_KEEP_LAST_MONTHLY);
}
}
g_list_free (comm_list);
}
gtk_widget_destroy(dialog);
gtk_widget_destroy (pdb_dialog->remove_dialog);
LEAVE(" ");
}

View File

@ -36,7 +36,6 @@
#include <locale.h>
#include <math.h>
#include <gnc-gdate-utils.h>
#include "qof.h"
#include "gnc-date.h"
#include "gnc-prefs.h"

View File

@ -38,7 +38,6 @@
#include <glib/gi18n.h>
#include <locale.h>
#include <gnc-gdate-utils.h>
#include "qof.h"
#include "Account.h"
#include "SchedXaction.h"

View File

@ -38,7 +38,6 @@
#include <glib/gi18n.h>
#include <locale.h>
#include <gnc-gdate-utils.h>
#include "qof.h"
#include "Account.h"
#include "SchedXaction.h"

View File

@ -26,11 +26,11 @@
#include "config.h"
#include <gnc-gdate-utils.h>
#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"

View File

@ -47,7 +47,6 @@
#include <glib.h>
#include <glib/gi18n.h>
#include <gnc-gdate-utils.h>
#include <gnc-gobject-utils.h>
#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"

View File

@ -2,173 +2,6 @@
<!-- Generated with glade 3.20.0 -->
<interface>
<requires lib="gtk+" version="3.10"/>
<object class="GtkDialog" id="deletion_date_dialog">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="border_width">6</property>
<property name="type_hint">dialog</property>
<child internal-child="vbox">
<object class="GtkBox" id="dialog-vbox19">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">6</property>
<child internal-child="action_area">
<object class="GtkButtonBox" id="dialog-action_area19">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="layout_style">end</property>
<child>
<object class="GtkButton" id="cancel_button">
<property name="label" translatable="yes">_Cancel</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="can_default">True</property>
<property name="receives_default">False</property>
<property name="use_underline">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="ok_button">
<property name="label" translatable="yes">_OK</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="can_default">True</property>
<property name="receives_default">False</property>
<property name="use_underline">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">end</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkGrid" id="table2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="valign">start</property>
<property name="row_spacing">6</property>
<property name="column_spacing">12</property>
<child>
<object class="GtkLabel" id="label8477429">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="valign">start</property>
<property name="label" translatable="yes">Delete all stock prices before the date below based upon the following criteria:</property>
<property name="wrap">True</property>
<property name="width_chars">40</property>
<property name="max_width_chars">40</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
<property name="width">2</property>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="delete_manual">
<property name="label" translatable="yes">Delete _manually entered prices</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="tooltip_text" translatable="yes">If activated, delete manually entered stock prices dated earlier than the specified date. Otherwise only stock prices added by Finance::Quote will be deleted.</property>
<property name="halign">start</property>
<property name="use_underline">True</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">3</property>
<property name="width">2</property>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="delete_last">
<property name="label" translatable="yes">Delete _last price for a stock</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="tooltip_text" translatable="yes">If activated, delete all prices before the specified date. Otherwise the last stock price dated before the date will be kept and all earlier quotes deleted.</property>
<property name="halign">start</property>
<property name="use_underline">True</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">4</property>
<property name="width">2</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label8477431">
<property name="visible">True</property>
<property name="can_focus">False</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">1</property>
<property name="width">2</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="date_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">_Date:</property>
<property name="use_underline">True</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">2</property>
</packing>
</child>
<child>
<object class="GtkBox" id="date_hbox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="valign">start</property>
<property name="hexpand">True</property>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">2</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">2</property>
</packing>
</child>
</object>
</child>
<action-widgets>
<action-widget response="-6">cancel_button</action-widget>
<action-widget response="-5">ok_button</action-widget>
</action-widgets>
</object>
<object class="GtkListStore" id="liststore1">
<columns>
<!-- column-name item -->
@ -279,9 +112,8 @@
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="pack_type">end</property>
<property name="position">0</property>
</packing>
</child>
@ -473,8 +305,7 @@
<signal name="changed" handler="pedit_commodity_ns_changed_cb" swapped="no"/>
<child internal-child="entry">
<object class="GtkEntry" id="combobox-entry3">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="can_focus">False</property>
</object>
</child>
</object>
@ -493,8 +324,7 @@
<signal name="changed" handler="pedit_commodity_changed_cb" swapped="no"/>
<child internal-child="entry">
<object class="GtkEntry" id="combobox-entry2">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="can_focus">False</property>
</object>
</child>
</object>
@ -518,6 +348,437 @@
<action-widget response="-5">pd_ok_button</action-widget>
</action-widgets>
</object>
<object class="GtkListStore" id="liststore4">
<columns>
<!-- column-name full_name -->
<column type="gchararray"/>
<!-- column-name commodity -->
<column type="gpointer"/>
<!-- column-name first_date -->
<column type="gchararray"/>
<!-- column-name number -->
<column type="gchararray"/>
</columns>
</object>
<object class="GtkDialog" id="deletion_date_dialog">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="border_width">6</property>
<property name="title" translatable="yes">Remove Old Prices</property>
<property name="default_height">500</property>
<property name="type_hint">dialog</property>
<child internal-child="vbox">
<object class="GtkBox" id="dialog-vbox2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">2</property>
<child internal-child="action_area">
<object class="GtkButtonBox" id="dialog-action_area2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="layout_style">end</property>
<child>
<object class="GtkButton" id="cancel_button">
<property name="label">_Cancel</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="can_default">True</property>
<property name="receives_default">False</property>
<property name="use_underline">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="ok_button">
<property name="label">_OK</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="can_default">True</property>
<property name="receives_default">False</property>
<property name="use_underline">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkGrid" id="table2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="row_spacing">10</property>
<property name="column_spacing">12</property>
<child>
<object class="GtkLabel" id="label8477429">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">Delete prices that meet the following criteria:</property>
<property name="wrap">True</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
<property name="width">2</property>
</packing>
</child>
<child>
<object class="GtkBox" id="hbox2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<child>
<object class="GtkRadioButton" id="radiobutton_none">
<property name="label" translatable="yes">_None</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="tooltip_text" translatable="yes">Remove all prices before date.</property>
<property name="use_underline">True</property>
<property name="active">True</property>
<property name="draw_indicator">True</property>
<property name="group">radiobutton_last_week</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkRadioButton" id="radiobutton_last_week">
<property name="label" translatable="yes">Last of _Week</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="tooltip_text" translatable="yes">Keep the last price of each week if present before date.</property>
<property name="use_underline">True</property>
<property name="active">True</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkRadioButton" id="radiobutton_last_month">
<property name="label" translatable="yes">Last of _Month</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="tooltip_text" translatable="yes">Keep the last price of each month if present before date.</property>
<property name="use_underline">True</property>
<property name="draw_indicator">True</property>
<property name="group">radiobutton_last_week</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkRadioButton" id="radiobutton_last_quarter">
<property name="label" translatable="yes">Last of _Quarter</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="tooltip_text" translatable="yes">Keep the last price of each fiscal quarter if present before date. The fiscal quarter is derived from the accounting period end date.</property>
<property name="use_underline">True</property>
<property name="draw_indicator">True</property>
<property name="group">radiobutton_last_week</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">3</property>
</packing>
</child>
<child>
<object class="GtkRadioButton" id="radiobutton_last_period">
<property name="label" translatable="yes">Last of _Period</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="tooltip_text" translatable="yes">Keep the last price of each fiscal period if present before date. The fiscal period is derived from the accounting period end date.</property>
<property name="use_underline">True</property>
<property name="draw_indicator">True</property>
<property name="group">radiobutton_last_week</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">4</property>
</packing>
</child>
<child>
<object class="GtkRadioButton" id="radiobutton_scaled">
<property name="label" translatable="yes">_Scaled</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="tooltip_text" translatable="yes">With the scaled option, prices are removed relative to the date selected. 'One a month' is used for dates older than a year and 'One a week' is used for dates older than six months to a year.</property>
<property name="use_underline">True</property>
<property name="draw_indicator">True</property>
<property name="group">radiobutton_last_week</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">5</property>
</packing>
</child>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">6</property>
<property name="width">2</property>
</packing>
</child>
<child>
<object class="GtkBox" id="hbox3">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="vexpand">True</property>
<child>
<object class="GtkScrolledWindow" id="scrolledwindow1">
<property name="visible">True</property>
<property name="can_focus">True</property>
<child>
<object class="GtkTreeView" id="commodty_treeview">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="model">liststore4</property>
<child internal-child="selection">
<object class="GtkTreeSelection" id="selection1"/>
</child>
<child>
<object class="GtkTreeViewColumn" id="name_column">
<property name="title" translatable="yes">Commodity</property>
<child>
<object class="GtkCellRendererText" id="name_cellr"/>
<attributes>
<attribute name="text">0</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="date_column">
<property name="title" translatable="yes">First Date</property>
<child>
<object class="GtkCellRendererText" id="date_cellr"/>
<attributes>
<attribute name="text">2</attribute>
</attributes>
</child>
</object>
</child>
</object>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">4</property>
<property name="width">2</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label3">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">From these Commodities:</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">3</property>
<property name="width">2</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">Keeping the last available price for option:</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">5</property>
<property name="width">2</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="valign">start</property>
<property name="hexpand">False</property>
<property name="label" translatable="yes">Source:</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">1</property>
</packing>
</child>
<child>
<object class="GtkBox" id="vbox1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="hexpand">True</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkCheckButton" id="checkbutton_fq">
<property name="label" translatable="yes">Include _Fetched online prices</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="tooltip_text" translatable="yes">If activated, prices added by Finance::Quote will be included.</property>
<property name="halign">start</property>
<property name="use_underline">True</property>
<property name="active">True</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="checkbutton_user">
<property name="label" translatable="yes">Include manually _Entered prices</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="tooltip_text" translatable="yes">If activated, include manually entered prices.</property>
<property name="halign">start</property>
<property name="use_underline">True</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkBox" id="hbox4">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkCheckButton" id="checkbutton_app">
<property name="label" translatable="yes">_Added by the application</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="tooltip_text" translatable="yes">If activated, include application added prices.
These prices were added so that there's always a "nearest in time" price for every multi-commodity transaction so that the Accounts page and reports are able to correctly report values so removing them may make this less reliable.</property>
<property name="halign">start</property>
<property name="use_underline">True</property>
<property name="image_position">right</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkImage" id="image_source">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="stock">gtk-dialog-warning</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">1</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="date_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">Before _Date:</property>
<property name="use_underline">True</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">2</property>
</packing>
</child>
<child>
<object class="GtkBox" id="date_hbox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="hexpand">True</property>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">2</property>
</packing>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
</child>
<action-widgets>
<action-widget response="-6">cancel_button</action-widget>
<action-widget response="-5">ok_button</action-widget>
</action-widgets>
</object>
<object class="GtkDialog" id="prices_dialog">
<property name="can_focus">False</property>
<property name="border_width">6</property>
@ -590,6 +851,23 @@
<property name="border_width">5</property>
<property name="orientation">vertical</property>
<property name="layout_style">spread</property>
<child>
<object class="GtkButton" id="get_quotes_button">
<property name="label" translatable="yes">_Get Quotes</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="can_default">True</property>
<property name="receives_default">False</property>
<property name="tooltip_text" translatable="yes">Get new online quotes for stock accounts.</property>
<property name="use_underline">True</property>
<signal name="clicked" handler="gnc_prices_dialog_get_quotes_clicked" swapped="no"/>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="add_button">
<property name="label" translatable="yes">_Add</property>
@ -660,27 +938,10 @@
<property name="position">3</property>
</packing>
</child>
<child>
<object class="GtkButton" id="get_quotes_button">
<property name="label" translatable="yes">_Get Quotes</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="can_default">True</property>
<property name="receives_default">False</property>
<property name="tooltip_text" translatable="yes">Get new online quotes for stock accounts.</property>
<property name="use_underline">True</property>
<signal name="clicked" handler="gnc_prices_dialog_get_quotes_clicked" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">4</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>

View File

@ -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 <gnc-gdate-utils.h>
#include "gnc-gnome-utils.h"
#include "gnc-main-window.h"
#include "gnc-plugin-page-register.h"

View File

@ -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 <gnc-gdate-utils.h>
#include "gnc-gnome-utils.h"
#include "gnc-main-window.h"
#include "gnc-plugin-page-register2.h"

View File

@ -39,6 +39,7 @@
#include <glib.h>
#include <glib/gstdio.h>
#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 <gnc-gdate-utils.h>
// To open the invoices for editing
#include "gnc-plugin-page-invoice.h"

View File

@ -24,7 +24,7 @@
#include <glib.h>
#include <gnc-gdate-utils.h>
#include "gnc-date.h"
#include "pricecell.h"
#include "split-register-p.h"

View File

@ -28,12 +28,12 @@
#include <glib/gi18n.h>
#include <libguile.h>
#include <gnc-gdate-utils.h>
#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"

View File

@ -22,7 +22,6 @@ 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
@ -64,7 +63,6 @@ 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

View File

@ -51,7 +51,6 @@ 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 \
@ -79,7 +78,6 @@ 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 \

View File

@ -44,7 +44,6 @@
#include "config.h"
#include <string.h>
#include "gnc-accounting-period.h"
#include "gnc-gdate-utils.h"
#include "gnc-date.h"
#include "gnc-prefs.h"
#include "qof.h"

View File

@ -1,286 +0,0 @@
/*
* gnc-gdate-utils.c -- utility functions for manipulating
* GDate data structures from GLib
* Copyright (C) 2005 David Hampton <hampton@employees.org>
*
* 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 <glib.h>
#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);
}

View File

@ -1,228 +0,0 @@
/*
* gnc-gdate-utils.h -- utility functions for manipulating
* GDate data structures from GLib
* Copyright (C) 2005 David Hampton <hampton@employees.org>
*
* 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 <hampton@employees.org>
*/
#ifndef GNC_GDATE_UTILS_H
#define GNC_GDATE_UTILS_H
#include <gnc-date.h>
/** @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 */
/** @} */
/** @} */

View File

@ -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 <gnc-gdate-utils.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "gnc.app-utils.sx"

View File

@ -24,9 +24,9 @@ extern "C"
#include <stdlib.h>
#include <glib.h>
#include "SX-book.h"
#include "gnc-date.h"
#include "gnc-sx-instance-model.h"
#include "gnc-ui-util.h"
#include <gnc-gdate-utils.h>
#include "test-stuff.h"
#include "test-engine-stuff.h"

View File

@ -3,6 +3,7 @@
* *
* Copyright 1997 Robin D. Clark <rclark@cs.hmc.edu> *
* Copyright 1998-2000, 2003 Linas Vepstas <linas@linas.org> *
* Copyright (C) 2005 David Hampton <hampton@employees.org> *
* Copyright 2011-2015 John Ralls <jralls@ceridwen.us *
* *
* This program is free software; you can redistribute it and/or *
@ -116,8 +117,8 @@ gnc_localtime (const time64 *secs)
auto time = static_cast<struct tm*>(calloc(1, sizeof(struct tm)));
if (gnc_localtime_r (secs, time) == NULL)
{
gnc_tm_free (time);
return NULL;
gnc_tm_free (time);
return NULL;
}
return time;
}
@ -127,12 +128,12 @@ gnc_localtime_r (const time64 *secs, struct tm* time)
{
try
{
*time = static_cast<struct tm>(GncDateTime(*secs));
return time;
*time = static_cast<struct tm>(GncDateTime(*secs));
return time;
}
catch(std::invalid_argument)
{
return NULL;
return NULL;
}
}
@ -199,14 +200,14 @@ gnc_gmtime (const time64 *secs)
{
try
{
auto time = static_cast<struct tm*>(calloc(1, sizeof(struct tm)));
GncDateTime gncdt(*secs);
*time = gncdt.utc_tm();
return time;
auto time = static_cast<struct tm*>(calloc(1, sizeof(struct tm)));
GncDateTime gncdt(*secs);
*time = gncdt.utc_tm();
return time;
}
catch(std::invalid_argument)
{
return NULL;
return NULL;
}
}
@ -216,13 +217,13 @@ gnc_mktime (struct tm* time)
{
try
{
normalize_struct_tm (time);
GncDateTime gncdt(*time);
return static_cast<time64>(gncdt) - gncdt.offset();
normalize_struct_tm (time);
GncDateTime gncdt(*time);
return static_cast<time64>(gncdt) - gncdt.offset();
}
catch(std::invalid_argument)
{
return 0;
return 0;
}
}
@ -231,12 +232,12 @@ gnc_timegm (struct tm* time)
{
try
{
normalize_struct_tm(time);
return static_cast<time64>(GncDateTime(*time));
normalize_struct_tm(time);
return static_cast<time64>(GncDateTime(*time));
}
catch(std::invalid_argument)
{
return 0;
return 0;
}
}
@ -259,12 +260,11 @@ gnc_time (time64 *tbuf)
gdouble
gnc_difftime (const time64 secs1, const time64 secs2)
{
return (double)secs1 - (double)secs2;
return (double)secs1 - (double)secs2;
}
/****************************************************************************/
const char*
gnc_date_dateformat_to_string(QofDateFormat format)
{
@ -319,7 +319,6 @@ gnc_date_string_to_dateformat(const char* fmt_str, QofDateFormat *format)
return FALSE;
}
const char*
gnc_date_monthformat_to_string(GNCDateMonthFormat format)
{
@ -411,7 +410,6 @@ timespec_normalize(Timespec *t)
return;
}
gboolean
timespec_equal (const Timespec *ta, const Timespec *tb)
{
@ -738,14 +736,14 @@ floordiv(int a, int b)
Fully formatted UTC timestamp strings are converted separately.
param buff - pointer to date string
param day - will store day of the month as 1 ... 31
param month - will store month of the year as 1 ... 12
param year - will store the year (4-digit)
param buff - pointer to date string
param day - will store day of the month as 1 ... 31
param month - will store month of the year as 1 ... 12
param year - will store the year (4-digit)
return TRUE if date appeared to be valid.
return TRUE if date appeared to be valid.
Globals: global dateFormat value
Globals: global dateFormat value
*/
static gboolean
qof_scan_date_internal (const char *buff, int *day, int *month, int *year,
@ -1045,7 +1043,6 @@ char dateSeparator (void)
}
break;
}
return '\0';
}
@ -1179,7 +1176,6 @@ qof_strftime(gchar *buf, gsize max, const gchar *format, const struct tm *tm)
return retval;
}
/********************************************************************\
\********************************************************************/
@ -1248,7 +1244,6 @@ gnc_timespec_to_iso8601_buff (Timespec ts, char * buff)
PWARN("Error processing time64 %" PRId64 ": %s", ts.tv_sec, err.what());
return buff;
}
}
void
@ -1287,7 +1282,6 @@ gnc_dmy2timespec_internal (int day, int month, int year, DayPart day_part)
}
}
Timespec
gnc_dmy2timespec (int day, int month, int year)
{
@ -1372,11 +1366,8 @@ gnc_gdate_set_time64 (GDate* gd, time64 time)
g_date_set_dmy (gd, tm.tm_mday,
static_cast<GDateMonth>(tm.tm_mon + 1),
tm.tm_year + 1900);
}
Timespec gdate_to_timespec (GDate d)
{
return gnc_dmy2timespec_neutral (g_date_get_day(&d),
@ -1424,7 +1415,6 @@ gnc_time64_get_day_end (time64 time_val)
return new_time;
}
/* ======================================================== */
void
@ -1501,7 +1491,6 @@ timespec_get_type( void )
timespec_boxed_copy_func,
timespec_boxed_free_func );
}
return type;
}
@ -1512,3 +1501,257 @@ gnc_date_load_funcs (void)
tf->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);
}

View File

@ -1,11 +1,12 @@
/***************************************************************************
/********************************************************************
* gnc-date.h (to be renamed qofdate.h)
*
* Copyright (C) 1997 Robin D. Clark <rclark@cs.hmc.edu>
* Copyright (C) 1998-2000, 2003 Linas Vepstas <linas@linas.org>
* Copyright 2005 Neil Williams <linux@codehelp.co.uk>
* Copyright (C) 2005 David Hampton <hampton@employees.org>
* Copyright 2012 John Ralls <jralls@ceridwen.us>
****************************************************************************/
********************************************************************/
/********************************************************************\
* 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 <rclark@cs.hmc.edu>
@author Copyright (C) 1998-2001,2003 Linas Vepstas <linas@linas.org>
@ -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
}

View File

@ -26,6 +26,7 @@
#include <glib.h>
#include <string.h>
#include "gnc-date.h"
#include "gnc-pricedb-p.h"
#include <qofinstance-p.h>
@ -1275,6 +1276,10 @@ gnc_pricedb_remove_price(GNCPriceDB *db, GNCPrice *p)
qof_instance_get_destroying(p));
gnc_price_ref(p);
DEBUG("Remove Date is %s, Commodity is %s, Source is %s", gnc_print_date (gnc_price_get_time (p)),
gnc_commodity_get_fullname (gnc_price_get_commodity (p)), gnc_price_get_source_string (p));
rc = remove_price (db, p, TRUE);
gnc_pricedb_begin_edit(db);
qof_instance_set_dirty(&db->inst);
@ -1294,8 +1299,9 @@ typedef struct
{
GNCPriceDB *db;
Timespec cutoff;
gboolean delete_fq;
gboolean delete_user;
gboolean delete_last;
gboolean delete_app;
GSList *list;
} remove_info;
@ -1309,14 +1315,19 @@ check_one_price_date (GNCPrice *price, gpointer user_data)
ENTER("price %p (%s), data %p", price,
gnc_commodity_get_mnemonic(gnc_price_get_commodity(price)),
user_data);
if (!data->delete_user)
source = gnc_price_get_source (price);
if ((source == PRICE_SOURCE_FQ) && data->delete_fq)
PINFO ("Delete Quote Source");
else if ((source == PRICE_SOURCE_USER_PRICE) && data->delete_user)
PINFO ("Delete User Source");
else if ((source != PRICE_SOURCE_FQ) && (source != PRICE_SOURCE_USER_PRICE) && data->delete_app)
PINFO ("Delete App Source");
else
{
source = gnc_price_get_source (price);
if (source != PRICE_SOURCE_FQ)
{
LEAVE("Not an automatic quote");
return TRUE;
}
LEAVE("Not a matching source");
return TRUE;
}
pt = gnc_price_get_time (price);
@ -1345,68 +1356,302 @@ pricedb_remove_foreach_pricelist (gpointer key,
ENTER("key %p, value %p, data %p", key, val, user_data);
/* The most recent price is the first in the list */
if (!data->delete_last)
node = g_list_next(node);
/* now check each item in the list */
g_list_foreach(node, (GFunc)check_one_price_date, data);
LEAVE(" ");
}
static void
pricedb_remove_foreach_currencies_hash (gpointer key,
gpointer val,
gpointer user_data)
static gint
compare_prices_by_commodity_date (gconstpointer a, gconstpointer b)
{
GHashTable *currencies_hash = (GHashTable *) val;
Timespec time_a;
Timespec time_b;
gnc_commodity *comma;
gnc_commodity *commb;
gnc_commodity *curra;
gnc_commodity *currb;
gint result;
ENTER("key %p, value %p, data %p", key, val, user_data);
g_hash_table_foreach(currencies_hash,
pricedb_remove_foreach_pricelist, user_data);
LEAVE(" ");
if (!a && !b) return 0;
/* nothing is always less than something */
if (!a) return -1;
if (!b) return 1;
comma = gnc_price_get_commodity ((GNCPrice *) a);
commb = gnc_price_get_commodity ((GNCPrice *) b);
if (!gnc_commodity_equal(comma, commb))
return gnc_commodity_compare(comma, commb);
curra = gnc_price_get_currency ((GNCPrice *) a);
currb = gnc_price_get_currency ((GNCPrice *) b);
if (!gnc_commodity_equal(curra, currb))
return gnc_commodity_compare(curra, currb);
time_a = gnc_price_get_time((GNCPrice *) a);
time_b = gnc_price_get_time((GNCPrice *) b);
result = -timespec_cmp(&time_a, &time_b);
if (result) return result;
/* For a stable sort */
return guid_compare (gnc_price_get_guid((GNCPrice *) a),
gnc_price_get_guid((GNCPrice *) b));
}
gboolean
gnc_pricedb_remove_old_prices(GNCPriceDB *db,
Timespec cutoff,
gboolean delete_user,
gboolean delete_last)
static gboolean
price_commodity_and_currency_equal (GNCPrice *a, GNCPrice *b)
{
remove_info data;
GSList *item;
gboolean ret_comm = FALSE;
gboolean ret_curr = FALSE;
data.db = db;
data.cutoff = cutoff;
data.delete_user = delete_user;
data.delete_last = delete_last;
data.list = NULL;
if (gnc_commodity_equal (gnc_price_get_commodity(a), gnc_price_get_commodity (b)))
ret_comm = TRUE;
ENTER("db %p, delet_user %d, delete_last %d", db, delete_user, delete_last);
if (gnc_commodity_equal (gnc_price_get_currency(a), gnc_price_get_currency (b)))
ret_curr = TRUE;
return (ret_comm && ret_curr);
}
static void
gnc_pricedb_remove_old_prices_pinfo (GNCPrice *price, gboolean keep_message)
{
GDate price_date = timespec_to_gdate (gnc_price_get_time (price));
char date_buf[MAX_DATE_LENGTH+1];
if (g_date_valid (&price_date))
{
gchar buf[40];
gnc_timespec_to_iso8601_buff(cutoff, buf);
DEBUG("checking date %s", buf);
qof_print_gdate (date_buf, MAX_DATE_LENGTH, &price_date);
if (keep_message)
{
PINFO("#### Keep price with date %s, commodity is %s, currency is %s", date_buf,
gnc_commodity_get_printname(gnc_price_get_commodity(price)),
gnc_commodity_get_printname(gnc_price_get_currency(price)));
}
else
PINFO("## Remove price with date %s", date_buf);
}
else
PINFO("Keep price date is invalid");
}
/* Traverse the database once building up an external list of prices
* to be deleted */
g_hash_table_foreach(db->commodity_hash,
pricedb_remove_foreach_currencies_hash,
&data);
static void
clone_price (GNCPrice **price, GNCPrice *source_price)
{
QofBook *book;
if (data.list == NULL)
return FALSE;
if (!source_price) return;
if (price == NULL) return;
book = qof_instance_get_book (QOF_INSTANCE(source_price));
if (*price)
gnc_price_unref (*price);
*price = gnc_price_clone (source_price, book);
gnc_pricedb_remove_old_prices_pinfo (source_price, TRUE);
}
static gint
roundUp (gint numToRound, gint multiple)
{
gint remainder;
if (multiple == 0)
return numToRound;
remainder = numToRound % multiple;
if (remainder == 0)
return numToRound;
return numToRound + multiple - remainder;
}
static gint
get_fiscal_quarter (GDate *date, GDateMonth fiscal_start)
{
GDateMonth month = g_date_get_month (date);
gint q = ((roundUp (22 - fiscal_start + month, 3)/3) % 4) + 1;
PINFO("Return fiscal quarter is %d", q);
return q;
}
static void
gnc_pricedb_process_removal_list (GNCPriceDB *db, GDate *fiscal_end_date,
remove_info data, PriceRemoveKeepOptions keep)
{
GSList *item;
gboolean save_first_price = FALSE;
gint saved_test_value = 0, next_test_value = 0;
GNCPrice *cloned_price = NULL;
GDateMonth fiscal_month_end = g_date_get_month (fiscal_end_date);
GDateMonth fiscal_month_start;
GDate *tmp_date = g_date_new_dmy (g_date_get_day (fiscal_end_date),
g_date_get_month (fiscal_end_date),
g_date_get_year (fiscal_end_date));
// get the fiscal start month
g_date_subtract_months (tmp_date, 12);
fiscal_month_start = g_date_get_month (tmp_date) + 1;
g_date_free (tmp_date);
// sort the list by commodity / currency / date
data.list = g_slist_sort (data.list, compare_prices_by_commodity_date);
/* Now run this external list deleting prices */
for (item = data.list; item; item = g_slist_next(item))
{
gnc_pricedb_remove_price(db, item->data);
GDate saved_price_date;
GDate next_price_date;
// Keep None
if (keep == PRICE_REMOVE_KEEP_NONE)
{
gnc_pricedb_remove_old_prices_pinfo (item->data, FALSE);
gnc_pricedb_remove_price (db, item->data);
continue;
}
save_first_price = !price_commodity_and_currency_equal (item->data, cloned_price); // Not Equal
if (save_first_price == TRUE)
{
clone_price (&cloned_price, item->data);
save_first_price = FALSE;
continue;
}
// get the price dates
saved_price_date = timespec_to_gdate (gnc_price_get_time (cloned_price));
next_price_date = timespec_to_gdate (gnc_price_get_time (item->data));
// Keep last price in fiscal year
if (keep == PRICE_REMOVE_KEEP_LAST_PERIOD && save_first_price == FALSE)
{
GDate *saved_fiscal_end = g_date_new_dmy (g_date_get_day (&saved_price_date),
g_date_get_month (&saved_price_date),
g_date_get_year (&saved_price_date));
GDate *next_fiscal_end = g_date_new_dmy (g_date_get_day (&next_price_date),
g_date_get_month (&next_price_date),
g_date_get_year (&next_price_date));
gnc_gdate_set_fiscal_year_end (saved_fiscal_end, fiscal_end_date);
gnc_gdate_set_fiscal_year_end (next_fiscal_end, fiscal_end_date);
saved_test_value = g_date_get_year (saved_fiscal_end);
next_test_value = g_date_get_year (next_fiscal_end);
PINFO("Keep last price in fiscal year");
g_date_free (saved_fiscal_end);
g_date_free (next_fiscal_end);
}
// Keep last price in fiscal quarter
if (keep == PRICE_REMOVE_KEEP_LAST_QUARTERLY && save_first_price == FALSE)
{
saved_test_value = get_fiscal_quarter (&saved_price_date, fiscal_month_start);
next_test_value = get_fiscal_quarter (&next_price_date, fiscal_month_start);
PINFO("Keep last price in fiscal quarter");
}
// Keep last price of every month
if (keep == PRICE_REMOVE_KEEP_LAST_MONTHLY && save_first_price == FALSE)
{
saved_test_value = g_date_get_month (&saved_price_date);
next_test_value = g_date_get_month (&next_price_date);
PINFO("Keep last price of every month");
}
// Keep last price of every week
if (keep == PRICE_REMOVE_KEEP_LAST_WEEKLY && save_first_price == FALSE)
{
saved_test_value = g_date_get_iso8601_week_of_year (&saved_price_date);
next_test_value = g_date_get_iso8601_week_of_year (&next_price_date);
PINFO("Keep last price of every week");
}
// Now compare the values
if (saved_test_value == next_test_value)
{
gnc_pricedb_remove_old_prices_pinfo (item->data, FALSE);
gnc_pricedb_remove_price (db, item->data);
}
else
clone_price (&cloned_price, item->data);
}
if (cloned_price)
gnc_price_unref (cloned_price);
}
gboolean
gnc_pricedb_remove_old_prices (GNCPriceDB *db, GList *comm_list,
GDate *fiscal_end_date, Timespec cutoff,
PriceRemoveSourceFlags source,
PriceRemoveKeepOptions keep)
{
remove_info data;
GList *node;
data.db = db;
data.cutoff = cutoff;
data.list = NULL;
data.delete_fq = FALSE;
data.delete_user = FALSE;
data.delete_app = FALSE;
ENTER("Remove Prices for Source %d, keeping %d", source, keep);
// setup the source options
if (source & PRICE_REMOVE_SOURCE_APP)
data.delete_app = TRUE;
if (source & PRICE_REMOVE_SOURCE_FQ)
data.delete_fq = TRUE;
if (source & PRICE_REMOVE_SOURCE_USER)
data.delete_user = TRUE;
// Walk the list of commodities
for (node = g_list_first (comm_list); node; node = g_list_next (node))
{
GHashTable *currencies_hash = g_hash_table_lookup (db->commodity_hash, node->data);
g_hash_table_foreach (currencies_hash, pricedb_remove_foreach_pricelist, &data);
}
g_slist_free(data.list);
if (data.list == NULL)
{
LEAVE("Empty price list");
return FALSE;
}
DEBUG("Number of Prices in list is %d, Cutoff date is %s", g_slist_length (data.list), gnc_print_date (cutoff));
// Check for a valid fiscal end of year date
if (fiscal_end_date == NULL)
{
GDateYear year_now = g_date_get_year (gnc_g_date_new_today ());
fiscal_end_date = g_date_new ();
g_date_set_dmy (fiscal_end_date, 31, 12, year_now);
}
else if (g_date_valid (fiscal_end_date) == FALSE)
{
GDateYear year_now = g_date_get_year (gnc_g_date_new_today ());
g_date_clear (fiscal_end_date, 1);
g_date_set_dmy (fiscal_end_date, 31, 12, year_now);
}
gnc_pricedb_process_removal_list (db, fiscal_end_date, data, keep);
g_slist_free (data.list);
LEAVE(" ");
return TRUE;
}

View File

@ -372,17 +372,37 @@ gboolean gnc_pricedb_add_price(GNCPriceDB *db, GNCPrice *p);
*/
gboolean gnc_pricedb_remove_price(GNCPriceDB *db, GNCPrice *p);
typedef enum
{
PRICE_REMOVE_SOURCE_FQ = 1, // this flag is set when added by F:Q checked
PRICE_REMOVE_SOURCE_USER = 2, // this flag is set when added by the user checked
PRICE_REMOVE_SOURCE_APP = 4, // this flag is set when added by the app checked
PRICE_REMOVE_SOURCE_COMM = 8, // this flag is set when we have commodities selected
} PriceRemoveSourceFlags;
typedef enum
{
PRICE_REMOVE_KEEP_NONE, // keep none
PRICE_REMOVE_KEEP_LAST_WEEKLY, // leave last one of every week
PRICE_REMOVE_KEEP_LAST_MONTHLY, // leave last one of every month
PRICE_REMOVE_KEEP_LAST_QUARTERLY, // leave last one of every quarter
PRICE_REMOVE_KEEP_LAST_PERIOD, // leave last one of every annual period
PRICE_REMOVE_KEEP_SCALED, // leave one every week then one a month
} PriceRemoveKeepOptions;
/** @brief Remove and unref prices older than a certain time.
* @param db The pricedb
* @param comm_list A list of commodities
* @param fiscal_end_date the end date of the current accounting period
* @param cutoff The time before which prices should be deleted.
* @param delete_user Whether user-created (i.e. not Finance::Quote) prices
* should be deleted.
* @param delete_last Whether a price should be deleted if it's the only
* remaining price for its commodity.
* @param source Whether Finance::Quote, user or all prices should be deleted.
* @param keep Whether scaled, monthly, weekly or no prices should be left.
* @return True if there were prices to process, False if not.
*/
gboolean gnc_pricedb_remove_old_prices(GNCPriceDB *db, Timespec cutoff,
const gboolean delete_user,
gboolean delete_last);
gboolean gnc_pricedb_remove_old_prices(GNCPriceDB *db, GList *comm_list,
GDate *fiscal_end_date, Timespec cutoff,
PriceRemoveSourceFlags source,
PriceRemoveKeepOptions keep);
/** @brief Find the most recent price between the two commodities.
*

View File

@ -1,5 +1,5 @@
/********************************************************************
* utest-gnc-pricedb.c: GLib g_test test suite for gnc-pricedb.c. *
* utest-gnc-pricedb.c: GLib g_test test suite for gnc-pricedb.c. *
* Copyright 2015 John Ralls <jralls@ceridwen.us> *
* *
* This program is free software; you can redistribute it and/or *
@ -415,6 +415,10 @@ create_some_prices (PriceDBFixture *fixture)
gnc_dmy2timespec(11, 4, 2009),
PRICE_SOURCE_FQ,
gnc_numeric_create(131190, 10000)));
gnc_pricedb_add_price(db, construct_price(book, c->usd, c->aud,
gnc_dmy2timespec(12, 4, 2009),
PRICE_SOURCE_USER_PRICE,
gnc_numeric_create(131190, 10000)));
gnc_pricedb_add_price(db, construct_price(book, c->usd, c->aud,
gnc_dmy2timespec(21, 8, 2010),
PRICE_SOURCE_FQ,
@ -539,6 +543,42 @@ create_some_prices (PriceDBFixture *fixture)
gnc_dmy2timespec(12, 11, 2014),
PRICE_SOURCE_FQ,
gnc_numeric_create(31151, 100)));
gnc_pricedb_add_price(db, construct_price(book, c->gbp, c->eur,
gnc_dmy2timespec(12, 05, 2007),
PRICE_SOURCE_USER_PRICE,
gnc_numeric_create(126836, 100000)));
gnc_pricedb_add_price(db, construct_price(book, c->gbp, c->eur,
gnc_dmy2timespec(12, 05, 2008),
PRICE_SOURCE_FQ,
gnc_numeric_create(126836, 100000)));
gnc_pricedb_add_price(db, construct_price(book, c->gbp, c->eur,
gnc_dmy2timespec(13, 05, 2008),
PRICE_SOURCE_USER_PRICE,
gnc_numeric_create(126836, 100000)));
gnc_pricedb_add_price(db, construct_price(book, c->gbp, c->eur,
gnc_dmy2timespec(14, 05, 2008),
PRICE_SOURCE_USER_PRICE,
gnc_numeric_create(126836, 100000)));
gnc_pricedb_add_price(db, construct_price(book, c->gbp, c->eur,
gnc_dmy2timespec(19, 05, 2008),
PRICE_SOURCE_FQ,
gnc_numeric_create(126836, 100000)));
gnc_pricedb_add_price(db, construct_price(book, c->gbp, c->eur,
gnc_dmy2timespec(22, 05, 2008),
PRICE_SOURCE_FQ,
gnc_numeric_create(126836, 100000)));
gnc_pricedb_add_price(db, construct_price(book, c->gbp, c->eur,
gnc_dmy2timespec(12, 06, 2008),
PRICE_SOURCE_FQ,
gnc_numeric_create(126836, 100000)));
gnc_pricedb_add_price(db, construct_price(book, c->gbp, c->eur,
gnc_dmy2timespec(12, 07, 2008),
PRICE_SOURCE_FQ,
gnc_numeric_create(126836, 100000)));
gnc_pricedb_add_price(db, construct_price(book, c->gbp, c->eur,
gnc_dmy2timespec(12, 11, 2008),
PRICE_SOURCE_FQ,
gnc_numeric_create(126836, 100000)));
gnc_pricedb_set_bulk_update(db, FALSE);
}
@ -650,7 +690,7 @@ static void
test_gnc_pricedb_get_num_prices (PriceDBFixture *fixture, gconstpointer pData)
{
int num = gnc_pricedb_get_num_prices(fixture->pricedb);
g_assert_cmpint(num, ==, 32);
g_assert_cmpint(num, ==, 42);
}
/* pricedb_equal_foreach_pricelist
static void
@ -743,11 +783,72 @@ gnc_pricedb_remove_old_prices(GNCPriceDB *db,// C: 1 Local: 0:0:0
*/
static void test_gnc_pricedb_remove_old_prices (PriceDBFixture *fixture, gconstpointer pData)
{
Timespec t = gnc_dmy2timespec(1, 1, 2013);
g_assert(gnc_pricedb_remove_old_prices(fixture->pricedb, t, FALSE, FALSE));
g_assert_cmpint(gnc_pricedb_get_num_prices(fixture->pricedb), ==, 11);
g_assert(gnc_pricedb_remove_old_prices(fixture->pricedb, t, FALSE, TRUE));
g_assert_cmpint(gnc_pricedb_get_num_prices(fixture->pricedb), ==, 10);
GList *comm_list = NULL;
Commodities *c = fixture->com;
PriceRemoveSourceFlags source_all = PRICE_REMOVE_SOURCE_FQ |
PRICE_REMOVE_SOURCE_USER |
PRICE_REMOVE_SOURCE_APP;
Timespec t_cut = gnc_dmy2timespec(1, 1, 2008);
Timespec t_cut1 = gnc_dmy2timespec(1, 1, 2009);
Timespec t_cut2 = gnc_dmy2timespec(1, 1, 2010);
GDate *fiscal_end_date = g_date_new ();
g_date_set_dmy (fiscal_end_date, 31, 12, 2017);
comm_list = g_list_append (comm_list, c->usd);
comm_list = g_list_append (comm_list, c->gbp);
g_assert_cmpint (gnc_pricedb_num_prices(fixture->pricedb, c->gbp), ==, 23);
g_assert_cmpint (gnc_pricedb_num_prices(fixture->pricedb, c->usd), ==, 11);
g_assert_cmpint (gnc_pricedb_get_num_prices(fixture->pricedb), ==, 42);
g_assert (gnc_pricedb_remove_old_prices(fixture->pricedb, comm_list,
fiscal_end_date, t_cut1,
PRICE_REMOVE_SOURCE_USER, // source is USER
PRICE_REMOVE_KEEP_NONE)); // keep none
g_assert_cmpint (gnc_pricedb_get_num_prices(fixture->pricedb), ==, 39);
// there should be no prices before cutoff, returns false
g_assert (!gnc_pricedb_remove_old_prices(fixture->pricedb, comm_list,
NULL, t_cut,
PRICE_REMOVE_SOURCE_FQ, // source is FQ
PRICE_REMOVE_KEEP_NONE)); // keep none
g_assert_cmpint (gnc_pricedb_get_num_prices(fixture->pricedb), ==, 39);
g_assert (gnc_pricedb_remove_old_prices(fixture->pricedb, comm_list,
fiscal_end_date, t_cut1,
source_all, // source is ALL
PRICE_REMOVE_KEEP_LAST_WEEKLY)); // keep last of week
g_assert_cmpint (gnc_pricedb_get_num_prices(fixture->pricedb), ==, 38);
g_assert (gnc_pricedb_remove_old_prices(fixture->pricedb, comm_list,
fiscal_end_date, t_cut2,
PRICE_REMOVE_SOURCE_FQ, // source is FQ
PRICE_REMOVE_KEEP_LAST_MONTHLY)); // keep last of month
g_assert_cmpint (gnc_pricedb_get_num_prices(fixture->pricedb), ==, 37);
g_assert (gnc_pricedb_remove_old_prices(fixture->pricedb, comm_list,
fiscal_end_date, t_cut2,
source_all, // source is all
PRICE_REMOVE_KEEP_LAST_QUARTERLY)); // keep last of quarter
g_assert_cmpint (gnc_pricedb_get_num_prices(fixture->pricedb), ==, 35);
g_assert (gnc_pricedb_remove_old_prices(fixture->pricedb, comm_list,
fiscal_end_date, t_cut2,
source_all, // source is all
PRICE_REMOVE_KEEP_LAST_PERIOD)); // keep last of period
g_assert_cmpint (gnc_pricedb_get_num_prices(fixture->pricedb), ==, 33);
g_list_free (comm_list);
g_date_free (fiscal_end_date);
}
/* price_list_from_hashtable
static PriceList *
@ -958,7 +1059,7 @@ test_gnc_pricedb_get_prices (PriceDBFixture *fixture, gconstpointer pData)
PriceList *prices = gnc_pricedb_get_prices(fixture->pricedb,
fixture->com->usd,
fixture->com->aud);
g_assert_cmpint(g_list_length(prices), ==, 4);
g_assert_cmpint(g_list_length(prices), ==, 5);
gnc_price_list_destroy(prices);
}
/* gnc_pricedb_lookup_day

View File

@ -512,7 +512,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