예제 #1
0
/**
 * try to find a reconcile wich contains the date given in param
 * for the given account
 *
 * \param date
 * \param account_number
 *
 * \return the number of the found reconcile or 0 if not found
 * */
gint gsb_data_reconcile_get_number_by_date ( const GDate *date,
                        gint account_number )
{
    GList *tmp_list;

    if (!date
	||
	!g_date_valid (date))
	return 0;

    /* check all the reconciles */
    tmp_list = reconcile_list;
    while (tmp_list)
    {
	struct_reconcile *reconcile;

	reconcile = tmp_list -> data;

	if (reconcile -> account_number == account_number
	    &&
	    g_date_compare ( reconcile -> reconcile_init_date,
			     date ) <= 0
	    &&
	    g_date_compare ( date,
			     reconcile -> reconcile_final_date ) <= 0 )
	    return reconcile -> reconcile_number;
	tmp_list = tmp_list -> next;
    }
    return 0;
}
예제 #2
0
/**
 * get the archive corresponding to the given date
 * if there is more than 1 archive corresponding to that date, return -1
 *
 * \param date
 *
 * \return the number of archive, 0 if none on that date, -1 if more than 1 on that date
 * */
gint gsb_data_archive_get_from_date ( const GDate *date )
{
    GSList *tmp_list;
    gint return_value = 0;

    if (!date)
	return 0;

    tmp_list = archive_list;
    while (tmp_list)
    {
	struct_archive *archive;

	archive = tmp_list -> data;

	/* check the archive only if the dates are valid */
	if (archive -> beginning_date && archive -> end_date)
	{
	    if ( g_date_compare ( date, archive -> beginning_date) >= 0
		 &&
		 g_date_compare ( date, archive -> end_date) <= 0 )
	    {
		if (return_value)
		    return_value = -1;
		else
		    return_value = archive -> archive_number;
	    }
	}
	tmp_list = tmp_list -> next;
    }
    return return_value;
}
예제 #3
0
static gboolean
ap_validate_menu (GnomeDruidPage *druidpage,
                  GtkWidget *druid,
                  gpointer user_data)
{
    GDate date_now;
    AcctPeriodInfo *info = user_data;
    ENTER("info=%p", info);

    /* Pull info from widget, push into freq spec */
    //gnc_frequency_save_state (info->period_menu, info->period, &info->closing_date);
    recurrenceListFree(&info->period);
    gnc_frequency_save_to_recurrence(info->period_menu, &info->period, &info->closing_date);

    if (0 <= g_date_compare(&info->prev_closing_date, &info->closing_date))
    {
        const char *msg = _("You must select closing date that "
                            "is greater than the closing date "
                            "of the previous book.");
        gnc_error_dialog (info->window, "%s", msg);
        return TRUE;
    }

    g_date_clear (&date_now, 1);
    g_date_set_time_t (&date_now, time(NULL));
    if (0 < g_date_compare(&info->closing_date, &date_now))
    {
        const char *msg = _("You must select closing date "
                            "that is not in the future.");
        gnc_error_dialog (info->window, "%s", msg);
        return TRUE;
    }
    return FALSE;
}
예제 #4
0
gboolean
ap_validate_menu (GtkAssistant *assistant, gpointer user_data)
{
    GDate date_now;
    AcctPeriodInfo *info = user_data;
    ENTER("info=%p", info);

    /* Pull info from widget, push into freq spec */
    //gnc_frequency_save_state (info->period_menu, info->period, &info->closing_date);
    recurrenceListFree(&info->period);
    gnc_frequency_save_to_recurrence(info->period_menu, &info->period, &info->closing_date);

    if (0 <= g_date_compare(&info->prev_closing_date, &info->closing_date))
    {
        /* Closing date must be greater than closing date of previous book */
        return FALSE;
    }

    g_date_clear (&date_now, 1);
    gnc_gdate_set_today (&date_now);
    if (0 < g_date_compare(&info->closing_date, &date_now))
    {
        /* Closing date must be in the future */
        return FALSE;
    }
    return TRUE;
}
예제 #5
0
gint 
days_compare (gconstpointer a, gconstpointer b)
{
  const Day *day1 = a, *day2 = b;

  return g_date_compare (day1->date, day2->date);
}
예제 #6
0
static void
gdcs_generic_update_recurrences(GncDenseCalStore *trans, GDate *start, GList *recurrences)
{
    int i;
    GDate date, next;

    date = *start;
    /* go one day before what's in the box so we can get the correct start
     * date. */
    g_date_subtract_days(&date, 1);
    recurrenceListNextInstance(recurrences, &date, &next);

    i = 0;
    while ((i < trans->num_marks)
            && g_date_valid(&next)
            /* Do checking against end restriction. */
            && ((trans->end_type == NEVER_END)
                || (trans->end_type == END_ON_DATE
                    && g_date_compare(&next, &trans->end_date) <= 0)
                || (trans->end_type == END_AFTER_N_OCCS
                    && i < trans->n_occurrences)))
    {
        *trans->cal_marks[i++] = next;
        date = next;
        recurrenceListNextInstance(recurrences, &date, &next);
    }
    trans->num_real_marks = i;
    /* cstim: Previously this was i-1 but that's just plain wrong for
     * occurrences which are coming to an end, because then i contains
     * the number of (rest) occurrences exactly! Subtracting one means
     * we will miss the last one. */

    g_signal_emit_by_name(trans, "update", GUINT_TO_POINTER(1));
}
static void
chat_text_maybe_append_date_and_time (EmpathyChatTextView *view,
				      time_t               timestamp)
{
	EmpathyChatTextViewPriv *priv = GET_PRIV (view);
	GDate                   *date, *last_date;
	gboolean                 append_date = FALSE;
	gboolean                 append_time = FALSE;

	/* Get the date from last message */
	last_date = g_date_new ();
	g_date_set_time_t (last_date, priv->last_timestamp);

	/* Get the date of the message we are appending */
	date = g_date_new ();
	g_date_set_time_t (date, timestamp);

	/* If last message was from another day we append date and time */
	if (g_date_compare (date, last_date) > 0) {
		append_date = TRUE;
		append_time = TRUE;
	}
	
	g_date_free (last_date);
	g_date_free (date);

	/* If last message is 'old' append the time */
	if (timestamp - priv->last_timestamp >= TIMESTAMP_INTERVAL) {
		append_time = TRUE;
	}

	if (append_date || (!priv->only_if_date && append_time)) {
		chat_text_view_append_timestamp (view, timestamp, append_date);
	}
}
예제 #8
0
static gboolean
check_readonly_threshold (const gchar *datestr, GDate *d)
{
    GDate *readonly_threshold = qof_book_get_autoreadonly_gdate(gnc_get_current_book());
    if (g_date_compare(d, readonly_threshold) < 0)
    {
#if 0
	gchar *dialog_msg = _("The entered date of the new transaction is "
			      "older than the \"Read-Only Threshold\" set for "
			      "this book. This setting can be changed in "
			      "File -> Properties -> Accounts.");
	gchar *dialog_title = _("Cannot store a transaction at this date");
	GtkWidget *dialog = gtk_message_dialog_new(NULL,
						   0,
						   GTK_MESSAGE_ERROR,
						   GTK_BUTTONS_OK,
						   "%s", dialog_title);
	gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),
						 "%s", dialog_msg);
	gtk_dialog_run(GTK_DIALOG(dialog));
	gtk_widget_destroy(dialog);
#endif
	g_warning("Entered date %s is before the \"auto-read-only threshold\";"
		  " resetting to the threshold.", datestr);

	// Reset the date to the threshold date
	g_date_set_julian (d, g_date_get_julian (readonly_threshold));
	g_date_free (readonly_threshold);
	return TRUE;
    }
    g_date_free (readonly_threshold);
    return FALSE;
}
예제 #9
0
파일: export_csv.c 프로젝트: jbq/grisbi
/**
 * used to compare 2 iters and sort the by value date or date if not exist
 * always put the white line below
 *
 * \param iter_1
 * \param iter_2
 *
 * \return -1 if iter_1 is before iter_2
 * */
gint gsb_csv_export_sort_by_value_date_or_date ( gpointer transaction_pointer_1,
                        gpointer transaction_pointer_2 )
{
    gint transaction_number_1;
    gint transaction_number_2;
    const GDate *value_date_1;
    const GDate *value_date_2;

    transaction_number_1 = gsb_data_transaction_get_transaction_number (
                        transaction_pointer_1 );
    transaction_number_2 = gsb_data_transaction_get_transaction_number (
                        transaction_pointer_2 );

    value_date_1 = gsb_data_transaction_get_value_date ( transaction_number_1 );
    if ( ! value_date_1 )
        value_date_1 = gsb_data_transaction_get_date ( transaction_number_1 );

    value_date_2 = gsb_data_transaction_get_value_date ( transaction_number_2 );
    if ( ! value_date_2 )
        value_date_2 = gsb_data_transaction_get_date ( transaction_number_2 );

    if ( value_date_1 )
        return ( g_date_compare ( value_date_1, value_date_2 ) );
    else
        return -1;
}
예제 #10
0
/**
 * used to compare the 2 dates first, and if they are the same
 * the 2 no of transactions to find the good return for sort
 * called at the end of each sort test, if they are equal
 *
 * \param none but the local variables transaction_number_1 and transaction_number_2 MUST be set
 *
 * \return -1 if transaction_number_1 is above transaction_number_2
 * */
gint gsb_transactions_list_sort_by_date_and_no ( gint transaction_number_1,
                        gint transaction_number_2 )
{
    gint return_value;

    if ( !gsb_data_transaction_get_date (transaction_number_1) )
    {
    return 1;
    }
    if ( !gsb_data_transaction_get_date (transaction_number_2) )
    {
    return -1;
    }

    /* i tried to set in the transactions a value for date as a gint as yyyymmdd
     * and here only do (gint transaction_1_date) - (gint transaction_2_date)
     * to increase the speed, but change nothing (perhaps 0,05sec for 250000 rows...)
     * so let like that */
    return_value = g_date_compare ( gsb_data_transaction_get_date (transaction_number_1),
                        gsb_data_transaction_get_date (transaction_number_2));

    /* no difference in the dates, sort by number of transaction */
    if ( !return_value )
    return_value = transaction_number_1 - transaction_number_2;

    return return_value;
}
예제 #11
0
/**
 * compared by date and by party
 *
 * \param none but the local variables transaction_number_1 and transaction_number_2 MUST be set
 *
 * \return -1 if amount_2 is above amount_number_1
 * */
gint gsb_transactions_list_sort_by_date_and_party ( gint transaction_number_1,
                        gint transaction_number_2 )
{
    gint return_value;
    gsb_real amount_1;
    gsb_real amount_2;

    if ( !gsb_data_transaction_get_date (transaction_number_1) )
    {
        return 1;
    }
    if ( !gsb_data_transaction_get_date (transaction_number_2) )
    {
        return -1;
    }

    return_value = g_date_compare ( gsb_data_transaction_get_date (transaction_number_1),
                        gsb_data_transaction_get_date (transaction_number_2));

    if ( return_value == 0 )
    {
        /* no difference in the dates, sort by amount of transaction */
        amount_1 = gsb_data_transaction_get_amount ( transaction_number_1 );
        amount_2 = gsb_data_transaction_get_amount ( transaction_number_2 );
        return_value = gsb_transactions_list_sort_by_party ( transaction_number_1,
                        transaction_number_2 );
    }

    return return_value;
}
예제 #12
0
/**
 * compared by date and by party
 *
 * \param none but the local variables transaction_number_1 and transaction_number_2 MUST be set
 *
 * \return -1 if amount_2 is above amount_number_1
 * */
gint gsb_transactions_list_sort_by_date_and_party ( gint transaction_number_1,
                        gint transaction_number_2 )
{
    gint return_value;

    if ( !gsb_data_transaction_get_date (transaction_number_1) )
    {
        return 1;
    }
    if ( !gsb_data_transaction_get_date (transaction_number_2) )
    {
        return -1;
    }

    return_value = g_date_compare ( gsb_data_transaction_get_date (transaction_number_1),
                        gsb_data_transaction_get_date (transaction_number_2));

    if ( return_value == 0 )
    {
        /* no difference in the dates, sort by party */
        return_value = gsb_transactions_list_sort_by_party ( transaction_number_1,
                        transaction_number_2 );
    }

    return return_value;
}
예제 #13
0
/**
 * compared by date and by amount
 *
 * \param none but the local variables transaction_number_1 and transaction_number_2 MUST be set
 *
 * \return -1 if amount_2 is above amount_number_1
 * */
gint gsb_transactions_list_sort_by_date_and_amount ( gint transaction_number_1,
                        gint transaction_number_2 )
{
    gint return_value;
    GsbReal amount_1;
    GsbReal amount_2;

    if ( !gsb_data_transaction_get_date (transaction_number_1) )
    {
        return 1;
    }
    if ( !gsb_data_transaction_get_date (transaction_number_2) )
    {
        return -1;
    }

    return_value = g_date_compare ( gsb_data_transaction_get_date (transaction_number_1),
                        gsb_data_transaction_get_date (transaction_number_2));

    if ( return_value == 0 )
    {
        /* no difference in the dates, sort by amount of transaction */
        amount_1 = gsb_data_transaction_get_amount ( transaction_number_1 );
        amount_2 = gsb_data_transaction_get_amount ( transaction_number_2 );
        return_value = (gint)(amount_2.mantissa - amount_1.mantissa);
        if ( return_value == 0 )
            return_value = transaction_number_1 - transaction_number_2;
    }

    return return_value;
}
예제 #14
0
GST_END_TEST
GST_START_TEST (test_date_tags)
{
  GstTagList *tag_list, *tag_list2;
  GDate *date, *date2;
  gchar *str;

  date = g_date_new_dmy (14, 10, 2005);
  tag_list = gst_tag_list_new_empty ();
  gst_tag_list_add (tag_list, GST_TAG_MERGE_APPEND, GST_TAG_DATE, date, NULL);

  str = gst_tag_list_to_string (tag_list);
  fail_if (str == NULL);
  fail_if (strstr (str, "2005-10-14") == NULL);

  tag_list2 = gst_tag_list_new_from_string (str);
  fail_if (tag_list2 == NULL);
  fail_if (!gst_tag_list_get_date (tag_list2, GST_TAG_DATE, &date2));
  fail_unless (gst_tag_list_is_equal (tag_list2, tag_list));
  gst_tag_list_unref (tag_list2);
  g_free (str);

  fail_if (g_date_compare (date, date2) != 0);
  fail_if (g_date_get_day (date) != 14);
  fail_if (g_date_get_month (date) != 10);
  fail_if (g_date_get_year (date) != 2005);
  fail_if (g_date_get_day (date2) != 14);
  fail_if (g_date_get_month (date2) != 10);
  fail_if (g_date_get_year (date2) != 2005);
  g_date_free (date2);

  gst_tag_list_unref (tag_list);
  g_date_free (date);
}
예제 #15
0
gint
kvp_value_compare(const KvpValue * kva, const KvpValue * kvb)
{
    if (kva == kvb) return 0;
    /* nothing is always less than something */
    if (!kva && kvb) return -1;
    if (kva && !kvb) return 1;

    if (kva->type < kvb->type) return -1;
    if (kva->type > kvb->type) return 1;

    switch (kva->type)
    {
    case KVP_TYPE_GINT64:
        if (kva->value.int64 < kvb->value.int64) return -1;
        if (kva->value.int64 > kvb->value.int64) return 1;
        return 0;
        break;
    case KVP_TYPE_DOUBLE:
        return double_compare(kva->value.dbl, kvb->value.dbl);
        break;
    case KVP_TYPE_NUMERIC:
        return gnc_numeric_compare (kva->value.numeric, kvb->value.numeric);
        break;
    case KVP_TYPE_STRING:
        return strcmp(kva->value.str, kvb->value.str);
        break;
    case KVP_TYPE_GUID:
        return guid_compare(kva->value.guid, kvb->value.guid);
        break;
    case KVP_TYPE_TIMESPEC:
        return timespec_cmp(&(kva->value.timespec), &(kvb->value.timespec));
        break;
    case KVP_TYPE_GDATE:
        return g_date_compare(&(kva->value.gdate), &(kvb->value.gdate));
        break;
    case KVP_TYPE_BINARY:
        /* I don't know that this is a good compare. Ab is bigger than Acef.
           But I'm not sure that actually matters here. */
        if (kva->value.binary.datasize < kvb->value.binary.datasize) return -1;
        if (kva->value.binary.datasize > kvb->value.binary.datasize) return 1;
        return memcmp(kva->value.binary.data,
                      kvb->value.binary.data,
                      kva->value.binary.datasize);
        break;
    case KVP_TYPE_GLIST:
        return kvp_glist_compare(kva->value.list, kvb->value.list);
        break;
    case KVP_TYPE_FRAME:
        return kvp_frame_compare(kva->value.frame, kvb->value.frame);
        break;
    default:
	break;
    }
    PERR ("reached unreachable code.");
    return FALSE;
}
예제 #16
0
void
xaccSchedXactionSetLastOccurDate(SchedXaction *sx, const GDate* new_last_occur)
{
    g_return_if_fail (new_last_occur != NULL);
    if (g_date_valid(&sx->last_date)
            && g_date_compare(&sx->last_date, new_last_occur) == 0)
        return;
    gnc_sx_begin_edit(sx);
    sx->last_date = *new_last_occur;
    qof_instance_set_dirty(&sx->inst);
    gnc_sx_commit_edit(sx);
}
예제 #17
0
static void date_changed_cb (AnnumShellWindow *self,
			     GnomeCalendarViewType view,
			     AnnumShellView *shell_view)
{
	const char *view_id;
	ECalendar *date_navigator;
	GDate *today;
	GDate start;
	GDate end;

	if (view != GNOME_CAL_DAY_VIEW)
		return;

	/* Week_View also uses GNOME_CAL_DAY_VIEW, so make sure */
	view_id = e_shell_view_get_view_id (E_SHELL_VIEW (shell_view));
	if (!g_strcmp0 (view_id, "Week_View"))
		return;

	/* DAY_VIEW is treated specially, because we only want to have
	 * the button toggled if we are showing today, not any other
	 * day
	 */

	date_navigator = annum_shell_sidebar_get_date_navigator (ANNUM_SHELL_SIDEBAR (self->priv->sidebar));

	today = g_date_new ();
	g_date_set_time_t (today, time (NULL));

	e_calendar_item_get_selection (date_navigator->calitem,
				       &start, &end);

	if (g_date_compare (today, &start) || g_date_compare (&start, &end)) {
		GtkAction *action = gtk_action_group_get_action (self->priv->action_group,
								 "ShowDay");
		gtk_radio_action_set_current_value (GTK_RADIO_ACTION (action),
						    ANNUM_VIEW_DAY);
	}

	g_date_free (today);
}
예제 #18
0
파일: gdate.c 프로젝트: thewb/mokoiax
void
g_date_clamp (GDate       *date,
	      const GDate *min_date,
	      const GDate *max_date)
{
  g_return_if_fail (g_date_valid (date));

  if (min_date != NULL)
    g_return_if_fail (g_date_valid (min_date));

  if (max_date != NULL)
    g_return_if_fail (g_date_valid (max_date));

  if (min_date != NULL && max_date != NULL)
    g_return_if_fail (g_date_compare (min_date, max_date) <= 0);

  if (min_date && g_date_compare (date, min_date) < 0)
    *date = *min_date;

  if (max_date && g_date_compare (max_date, date) < 0)
    *date = *max_date;
}
예제 #19
0
void
gnc_tree_util_split_reg_parse_date (GDate *parsed, const char *datestr)
{
    int day, month, year;
    gboolean use_autoreadonly = qof_book_uses_autoreadonly (gnc_get_current_book ());

    if (!parsed) return;
    if (!datestr) return;

    if (!qof_scan_date (datestr, &day, &month, &year))
    {
        // Couldn't parse date, use today
        struct tm tm_today;
        gnc_tm_get_today_start (&tm_today);
        day = tm_today.tm_mday;
        month = tm_today.tm_mon + 1;
        year = tm_today.tm_year + 1900;
    }

    // If we have an auto-read-only threshold, do not accept a date that is
    // older than the threshold.
    if (use_autoreadonly)
    {
        GDate *d = g_date_new_dmy (day, month, year);
        GDate *readonly_threshold = qof_book_get_autoreadonly_gdate (gnc_get_current_book());
        if (g_date_compare (d, readonly_threshold) < 0)
        {
            g_warning("Entered date %s is before the \"auto-read-only threshold\"; resetting to the threshold.", datestr);
#if 0
            GtkWidget *dialog = gtk_message_dialog_new (NULL,
                                                       0,
                                                       GTK_MESSAGE_ERROR,
                                                       GTK_BUTTONS_OK,
                                                       "%s", _("Cannot store a transaction at this date"));
            gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
                                                     "%s", _("The entered date of the new transaction is older than the \"Read-Only Threshold\" set for this book. "
                                                             "This setting can be changed in File -> Properties -> Accounts."));
            gtk_dialog_run (GTK_DIALOG (dialog));
            gtk_widget_destroy (dialog);
#endif

            // Reset the date to the threshold date
            day = g_date_get_day (readonly_threshold);
            month = g_date_get_month (readonly_threshold);
            year = g_date_get_year (readonly_threshold);
        }
        g_date_free (d);
        g_date_free (readonly_threshold);
    }
    g_date_set_dmy (parsed, day, month, year);
}
예제 #20
0
/**
 * vu_check_latest_version:
 * @window: Somewhere where we may need use the display to inform the user about the version status
 *
 * Periodically checks the released latest VERSION file on the website to compare with the running version
 *
 */
void vu_check_latest_version ( GtkWindow *window )
{
	if ( ! a_vik_get_check_version () )
		return;

	gboolean do_check = FALSE;

	gint check_period;
	if ( ! a_settings_get_integer ( VIK_SETTINGS_VERSION_CHECK_PERIOD, &check_period ) ) {
		check_period = 14;
	}

	// Get last checked date...
	GDate *gdate_last = g_date_new();
	GDate *gdate_now = g_date_new();
	GTimeVal time_last;
	gchar *last_checked_date = NULL;

	// When no previous date available - set to do the version check
	if ( a_settings_get_string ( VIK_SETTINGS_VERSION_CHECKED_DATE, &last_checked_date) ) {
		if ( g_time_val_from_iso8601 ( last_checked_date, &time_last ) ) {
			g_date_set_time_val ( gdate_last, &time_last );
		}
		else
			do_check = TRUE;
	}
	else
		do_check = TRUE;

	GTimeVal time_now;
	g_get_current_time ( &time_now );
	g_date_set_time_val ( gdate_now, &time_now );

	if ( ! do_check ) {
		// Dates available so do the comparison
		g_date_add_days ( gdate_last, check_period );
		if ( g_date_compare ( gdate_last, gdate_now ) < 0 )
			do_check = TRUE;
	}

	g_date_free ( gdate_last );
	g_date_free ( gdate_now );

	if ( do_check ) {
#if GLIB_CHECK_VERSION (2, 32, 0)
		g_thread_try_new ( "latest_version_thread", (GThreadFunc)latest_version_thread, window, NULL );
#else
		g_thread_create ( (GThreadFunc)latest_version_thread, window, FALSE, NULL );
#endif
	}
}
예제 #21
0
static gboolean test_equal(GDate *d1, GDate *d2)
{
    if (!do_test(g_date_compare(d1, d2) == 0, "dates don't match"))
    {
        gchar s1[21];
        gchar s2[21];
        g_date_strftime(s1, 20, "%x", d1);
        g_date_strftime(s2, 20, "%x", d2);

        printf("%s != %s\n", s1, s2);
        return FALSE;
    }
    return TRUE;
}
예제 #22
0
파일: gdate.c 프로젝트: thewb/mokoiax
void
g_date_order (GDate *date1,
              GDate *date2)
{
  g_return_if_fail (g_date_valid (date1));
  g_return_if_fail (g_date_valid (date2));

  if (g_date_compare (date1, date2) > 0)
    {
      GDate tmp = *date1;
      *date1 = *date2;
      *date2 = tmp;
    }
}
예제 #23
0
파일: utils_date.c 프로젝트: rosedu/osmo
gboolean
utl_date_order (GDate *date1, GDate *date2)
{
	g_return_val_if_fail (g_date_valid (date1), FALSE);
	g_return_val_if_fail (g_date_valid (date2), FALSE);

	if (g_date_compare (date1, date2) > 0)
	{
		GDate tmp = *date1;
		*date1 = *date2;
		*date2 = tmp;
		return TRUE;
	} else
		return FALSE;
}
예제 #24
0
static gint
_safe_invalidable_date_compare(const GDate *a, const GDate *b)
{
    if (!g_date_valid(a) && !g_date_valid(b))
    {
        return 0;
    }
    if (!g_date_valid(a))
    {
        return 1;
    }
    if (!g_date_valid(b))
    {
        return -1;
    }
    return g_date_compare(a, b);
}
예제 #25
0
/**
 * compare deux rapprochements par date
 *
 * \param reconcile_1, reconcile_2
 *
 * \return 0 -1 1 comme strcmp
 * */
gint gsb_data_reconcile_cmp_int (struct_reconcile *reconcile_1,
                        struct_reconcile *reconcile_2)
{
    gint result;

    if ( ! reconcile_1 -> reconcile_final_date )
        return -1;
    else if ( ! reconcile_2 -> reconcile_final_date )
        return 1;
    else
        result = g_date_compare ( reconcile_1 -> reconcile_final_date,
                           reconcile_2 -> reconcile_final_date );
    if (result == 0 )
        return reconcile_1 -> reconcile_number - reconcile_2 -> reconcile_number;
    else
        return result;
}
예제 #26
0
static gint
_temporal_state_data_cmp( gconstpointer a, gconstpointer b )
{
    const SXTmpStateData *tsd_a = (SXTmpStateData*)a;
    const SXTmpStateData *tsd_b = (SXTmpStateData*)b;

    if ( !tsd_a && !tsd_b )
        return 0;
    if (tsd_a == tsd_b)
        return 0;
    if ( !tsd_a )
        return 1;
    if ( !tsd_b )
        return -1;
    return g_date_compare( &tsd_a->last_date,
                           &tsd_b->last_date );
}
예제 #27
0
static void
increment_sx_state(GncSxInstance *inst, GDate **last_occur_date, int *instance_count, int *remain_occur_count)
{
    if (!g_date_valid(*last_occur_date)
            || (g_date_valid(*last_occur_date)
                && g_date_compare(*last_occur_date, &inst->date) <= 0))
    {
        *last_occur_date = &inst->date;
    }

    *instance_count = gnc_sx_get_instance_count(inst->parent->sx, inst->temporal_state) + 1;

    if (*remain_occur_count > 0)
    {
        *remain_occur_count -= 1;
    }
}
예제 #28
0
static void
prepare_remarks (AcctPeriodInfo *info)
{
    int nperiods;
    GDate period_begin, period_end, date_now;
    const char *remarks_text;
    char * str;
    ENTER ("info=%p", info);

    /* Pull info from widget, push into freq spec */
    //gnc_frequency_save_state (info->period_menu, info->period, &info->closing_date);
    recurrenceListFree(&info->period);
    gnc_frequency_save_to_recurrence(info->period_menu, &info->period, &info->closing_date);

    /* Count the number of periods that would be generated. */
    g_date_clear (&period_begin, 1);
    g_date_clear (&period_end, 1);
    g_date_clear (&date_now, 1);
    nperiods = 0;
    period_end = info->closing_date;
    g_date_set_time_t (&date_now, time(NULL));

    while (0 > g_date_compare(&period_end, &date_now ))
    {
        nperiods ++;
        PINFO ("period=%d end date=%d/%d/%d", nperiods,
               g_date_get_month(&period_end),
               g_date_get_day(&period_end),
               g_date_get_year(&period_end));
        period_begin = period_end;
        recurrenceListNextInstance(info->period, &period_begin, &period_end);
    }

    /* Display the results */
    remarks_text =
        _("The earliest transaction date found in this book is %s. "
          "Based on the selection made above, this book will be split "
          "into %d books.  Click on 'Forward' to start closing the "
          "earliest book.");
    str = g_strdup_printf (remarks_text, info->earliest_str, nperiods);
    gtk_label_set_text (info->period_remarks, str);
    g_free (str);
}
예제 #29
0
static gboolean
check_conversion (const char * str, Timespec expected_ts)
{
    Timespec ts;
    int day, month, year;
    GDate d1, d2;

    ts = gnc_iso8601_to_timespec_gmt (str);

    // We test the conversion to GDate against the timespec2dmy
    // conversion, and also the conversion back to timespec and again
    // to GDate so that it is still the original GDate
    gnc_timespec2dmy(ts, &day, &month, &year);
    d1 = timespec_to_gdate(ts);
    d2 = timespec_to_gdate(gdate_to_timespec(d1));
    if ((g_date_compare(&d1, &d2) != 0)
            || (g_date_get_day(&d1) != day)
            || (g_date_get_month(&d1) != month)
            || (g_date_get_year(&d1) != year))
    {
        fprintf (stderr,
                 "\nmis-converted \"%s\" to GDate. "
                 "Got d1(Y-M-D) = %i-%i-%i, d2(Y-M-D) = %i-%i-%i\n",
                 str, year, month, day,
                 g_date_get_year(&d2), g_date_get_month(&d2), g_date_get_day(&d2));
        failure ("misconverted timespec");
        return FALSE;
    }

    if ((expected_ts.tv_sec != ts.tv_sec) || (expected_ts.tv_nsec != ts.tv_nsec))
    {
        fprintf (stderr,
                 "\nmis-converted \"%s\" to %" G_GUINT64_FORMAT ".%09ld seconds\n"
                 "\twas expecting %" G_GUINT64_FORMAT ".%09ld seconds\n",
                 str, ts.tv_sec, ts.tv_nsec,
                 expected_ts.tv_sec, expected_ts.tv_nsec);
        failure ("misconverted timespec");
        return FALSE;
    }
    success ("good conversion");
    return TRUE;
}
예제 #30
0
GDate
xaccSchedXactionGetNextInstance (const SchedXaction *sx, SXTmpStateData *tsd)
{
    GDate prev_occur, next_occur;

    g_date_clear( &prev_occur, 1 );
    if ( tsd != NULL )
        prev_occur = tsd->last_date;

    /* If prev_occur is in the "cleared" state and sx->start_date isn't, then
     * we're at the beginning. We want to pretend prev_occur is the day before
     * the start_date in case the start_date is today so that the SX will fire
     * today. If start_date isn't valid either then the SX will fire anyway, no
     * harm done.
     */
    if (! g_date_valid( &prev_occur ) && g_date_valid(&sx->start_date))
    {
        /* We must be at the beginning. */
        prev_occur = sx->start_date;
        g_date_subtract_days( &prev_occur, 1 );
    }

    recurrenceListNextInstance(sx->schedule, &prev_occur, &next_occur);

    if ( xaccSchedXactionHasEndDate( sx ) )
    {
        const GDate *end_date = xaccSchedXactionGetEndDate( sx );
        if ( g_date_compare( &next_occur, end_date ) > 0 )
        {
            g_date_clear( &next_occur, 1 );
        }
    }
    else if ( xaccSchedXactionHasOccurDef( sx ) )
    {
        if ((tsd && tsd->num_occur_rem == 0) ||
            (!tsd && sx->num_occurances_remain == 0 ))
        {
            g_date_clear( &next_occur, 1 );
        }
    }
    return next_occur;
}