Commit c3b5abaf authored by Jody Goldberg's avatar Jody Goldberg Committed by Jody Goldberg

add to round things out.

2003-06-27  Jody Goldberg <jody@gnome.org>

	* functions.c (gnumeric_yearfrac) : add to round things out.

2003-06-27  Jody Goldberg <jody@gnome.org>

	* src/datetime.c (days_between_basis) : tidy up a bit.
	(annual_year_basis) : move this here from the date plugin and use the
	  enum to improve clarity.
parent 2f3c340d
......@@ -524,7 +524,6 @@ Function Breakage
- Function range_min_k uses an O(n*log n) algorithm. It should use O(n)
algorithm, see Knuth.
- WORKDAY Add holiday support
- YEARFRAC Move to fn-finance and use the available routines.
* Convert the code from sc to use our more accurate date routines
- ODDFPRICE (test fails)
......
2003-06-27 Jody Goldberg <jody@gnome.org>
* src/datetime.c (days_between_basis) : tidy up a bit.
(annual_year_basis) : move this here from the date plugin and use the
enum to improve clarity.
2003-06-27 Andreas J. Guelzow <aguelzow@taliesin.ca>
http://bugzilla.gnome.org/show_bug.cgi?id=115503
......
......@@ -31,6 +31,7 @@ Jody:
* Fix jumping to internal links in a different sheet
* Add XML persistence for charts
* Misc Charting improvements & fixes
* Add YEARFRAC to put us at 100% coverage
Jon Kåre:
* Improve color combo.
......
2003-06-27 Jody Goldberg <jody@gnome.org>
* src/datetime.c (days_between_basis) : tidy up a bit.
(annual_year_basis) : move this here from the date plugin and use the
enum to improve clarity.
2003-06-27 Andreas J. Guelzow <aguelzow@taliesin.ca>
http://bugzilla.gnome.org/show_bug.cgi?id=115503
......
2003-06-27 Jody Goldberg <jody@gnome.org>
* src/datetime.c (days_between_basis) : tidy up a bit.
(annual_year_basis) : move this here from the date plugin and use the
enum to improve clarity.
2003-06-27 Andreas J. Guelzow <aguelzow@taliesin.ca>
http://bugzilla.gnome.org/show_bug.cgi?id=115503
......
2003-06-27 Jody Goldberg <jody@gnome.org>
* functions.c (gnumeric_yearfrac) : add to round things out.
2003-06-12 Jody Goldberg <jody@gnome.org>
* functions.c : Some docs cleanups as per
......
......@@ -1237,7 +1237,21 @@ static char const *help_yearfrac = {
static Value *
gnumeric_yearfrac (FunctionEvalInfo *ei, Value **argv)
{
return value_new_error_VALUE (ei->pos);
GnmDateConventions const *conv = DATE_CONV (ei->pos);
GDate start_date, end_date;
int basis = (argv[2] != NULL)
? value_get_as_int (argv[2])
: BASIS_MSRB_30_360;
if (basis < 0 || basis > 4 ||
!datetime_value_to_g (&start_date, argv[0], conv) ||
!datetime_value_to_g (&end_date, argv[1], conv) ||
!g_date_valid (&start_date) || !g_date_valid (&end_date))
return value_new_error_NUM (ei->pos);
return value_new_float (
(double) days_between_basis (&start_date, &end_date, basis) /
(double) annual_year_basis (argv[0], basis, conv));
}
/***************************************************************************/
......
......@@ -128,47 +128,6 @@ calculate_pmt (gnm_float rate, gnm_float nper, gnm_float pv, gnm_float fv,
/***************************************************************************/
/*
* Returns the number of days in the year for the given date accoring to
* the day counting system specified by 'basis' argument. Basis may have
* one of the following values:
*
* 0 for US 30/360 (days in a month/days in a year)
* 1 for actual days/actual days
* 2 for actual days/360
* 3 for actual days/365
* 4 for European 30/360
*
* This function returns 360 for basis 0, 2, and 4, it returns value
* 365 for basis 3, and value 365 or 366 for basis 1 accoring to the
* year of the given date (366 is returned if the date is in a leap
* year).
*/
static int
annual_year_basis (Value *value_date, int basis,
GnmDateConventions const *date_conv)
{
GDate date;
switch (basis) {
case 0:
return 360;
case 1:
if (!datetime_value_to_g (&date, value_date, date_conv))
return -1;
return g_date_is_leap_year (g_date_get_year (&date))
? 366 : 365;
case 2:
return 360;
case 3:
return 365;
case 4:
return 360;
default:
return -1;
}
}
/* Returns the number of days between issue date and maturity date
* accoring to the day counting system specified by the 'basis'
* argument. Basis may have one of the following values:
......
2003-06-27 Jody Goldberg <jody@gnome.org>
* graph/gog-plot-impl.h : Add GogPlotClass::supports_vary_by_element
2003-06-26 Morten Welinder <terra@gnome.org>
* graph/gog-renderer-pixbuf.c (gog_renderer_pixbuf_draw_polygon):
......
......@@ -77,9 +77,14 @@ typedef enum {
GOG_AXIS_X,
GOG_AXIS_Y,
GOG_AXIS_Z,
GOG_AXIS_RADIAL,
GOG_AXIS_TYPES
} GogAxisType;
typedef enum {
GOG_AXES_XY,
GOG_AXES_XY_pseduo_3d,
GOG_AXES_XYZ,
GOG_AXES_TYPES
} GogAxesType;
typedef enum {
GOG_DIM_INVALID = -1,
......
......@@ -61,6 +61,8 @@ typedef struct {
GogPlotDesc desc;
GType series_type;
unsigned supports_vary_by_element : 1;
/* Virtuals */
GOData *(*axis_bounds) (GogPlot *plot, unsigned axis,
double *min, double *max);
......
......@@ -267,6 +267,7 @@ gog_barcol_plot_class_init (GogPlotClass *plot_klass)
plot_klass->desc.num_series_min = 1;
plot_klass->desc.num_series_max = G_MAXINT;
plot_klass->series_type = gog_barcol_series_get_type ();
plot_klass->supports_vary_by_element = TRUE;
}
static void
......
......@@ -201,6 +201,7 @@ gog_pie_plot_class_init (GogPlotClass *plot_klass)
plot_klass->desc.num_series_min = plot_klass->desc.num_series_max = 1;
plot_klass->series_type = gog_pie_series_get_type ();
plot_klass->foreach_elem = gog_pie_plot_foreach_elem;
plot_klass->supports_vary_by_element = TRUE;
}
static void
......
......@@ -406,31 +406,29 @@ days_between_BASIS_30Ep_360 (GDate const *from, GDate const *to)
*/
gint32
days_between_basis (GDate const *from, GDate const *to, int basis)
days_between_basis (GDate const *from, GDate const *to, basis_t basis)
{
switch (g_date_compare (from, to)) {
case 1:
return (- days_between_basis (to, from, basis));
default:
break;
int sign = 1;
if (g_date_compare (from, to) == 1) {
GDate const *tmp = from;
from = to;
to = tmp;
sign = -1;
}
switch (basis) {
case BASIS_ACT_ACT:
case BASIS_ACT_360:
case BASIS_ACT_365:
return (g_date_get_julian (to) - g_date_get_julian (from));
break;
return sign * (g_date_get_julian (to) - g_date_get_julian (from));
case BASIS_30E_360:
return days_between_BASIS_30E_360 (from, to);
break;
return sign * days_between_BASIS_30E_360 (from, to);
case BASIS_30Ep_360:
return days_between_BASIS_30Ep_360 (from, to);
break;
return sign * days_between_BASIS_30Ep_360 (from, to);
case BASIS_MSRB_30_360:
default:
return days_between_BASIS_MSRB_30_360 (from, to);
break;
return sign * days_between_BASIS_MSRB_30_360 (from, to);
}
}
......@@ -563,3 +561,45 @@ gnm_date_convention_base (GnmDateConventions const *conv)
g_return_val_if_fail (conv != NULL, 1900);
return conv->use_1904 ? 1904 : 1900;
}
/*
* Returns the number of days in the year for the given date accoring to
* the day counting system specified by 'basis' argument. Basis may have
* one of the following values:
*
* 0 for US 30/360 (days in a month/days in a year)
* 1 for actual days/actual days
* 2 for actual days/360
* 3 for actual days/365
* 4 for European 30/360
*
* This function returns 360 for basis 0, 2, and 4, it returns value
* 365 for basis 3, and value 365 or 366 for basis 1 accoring to the
* year of the given date (366 is returned if the date is in a leap
* year).
*/
int
annual_year_basis (Value const *value_date, basis_t basis,
GnmDateConventions const *date_conv)
{
GDate date;
switch (basis) {
case BASIS_MSRB_30_360:
return 360;
case BASIS_ACT_ACT:
if (!datetime_value_to_g (&date, value_date, date_conv))
return -1;
return g_date_is_leap_year (g_date_get_year (&date))
? 366 : 365;
case BASIS_ACT_360:
return 360;
case BASIS_ACT_365:
return 365;
case BASIS_30E_360:
return 360;
default:
return -1;
}
}
......@@ -72,8 +72,9 @@ typedef enum { /* see doc/fn-financial-basis.txt for details */
BASIS_LAST = 6
} basis_t;
void adjust_dates_basis (GDate const *from, GDate const *to, int basis);
gint32 days_between_basis (GDate const *from, GDate const *to, int basis);
gint32 days_between_basis (GDate const *from, GDate const *to, basis_t basis);
int annual_year_basis (Value const *value_date, basis_t basis,
GnmDateConventions const *date_conv);
typedef struct {
int freq;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment