Commit 24529699 authored by Morten Welinder's avatar Morten Welinder Committed by Morten Welinder
Browse files

Improve Excel compatibility.

2006-01-24  Morten Welinder  <terra@gnome.org>

	* functions.c (gnumeric_second, gnumeric_minute, gnumeric_hour):
	Improve Excel compatibility.

2006-01-24  Morten Welinder  <terra@gnome.org>

	* src/gnm-datetime.c (datetime_value_to_seconds): Kill.
parent 3380383e
2006-01-24 Morten Welinder <terra@gnome.org>
* src/gnm-datetime.c (datetime_value_to_seconds): Kill.
2006-01-24 Ivan, Wong Yat Cheung <ivanwong@gnome.org>
* src/Makefile.am: Build as non-console Win32 application by default.
......
......@@ -38,6 +38,7 @@ Morten:
* Fix loading of boolean constants from ods files.
* Fix MID for out-of-bounds values.
* Fix constructed-range parsing for OO.
* Fix SECOND, MINUTE, HOUR compatibility problems.
Jon Kåre:
* Hand clipboard off to clipboard manager when exiting.
......
2006-01-24 Morten Welinder <terra@gnome.org>
* src/gnm-datetime.c (datetime_value_to_seconds): Kill.
2006-01-24 Ivan, Wong Yat Cheung <ivanwong@gnome.org>
* src/Makefile.am: Build as non-console Win32 application by default.
......
2006-01-24 Morten Welinder <terra@gnome.org>
* functions.c (gnumeric_second, gnumeric_minute, gnumeric_hour):
Improve Excel compatibility.
2005-11-14 Jody Goldberg <jody@gnome.org>
* Release 1.6.1
......
......@@ -55,6 +55,29 @@ make_date (GnmValue *res)
return res;
}
static int
float_to_secs (gnm_float d)
{
int secs;
/* Ok, we have a positive number. Add epsilon before we scale
and translate because otherwise it will not be enough. */
d = gnm_add_epsilon (d);
/* Get the number down between 0 and 1 before we scale. */
d -= gnm_floor (d);
/* Scale and round. */
secs = (int)(gnm_add_epsilon (d) * DAY_SECONDS + 0.5);
/* We rounded, so we might have gone too far. */
if (secs >= DAY_SECONDS)
secs -= DAY_SECONDS;
return secs;
}
/***************************************************************************/
static GnmFuncHelp const help_date[] = {
......@@ -579,9 +602,14 @@ static GnmFuncHelp const help_hour[] = {
static GnmValue *
gnumeric_hour (FunctionEvalInfo *ei, GnmValue const * const *argv)
{
int secs;
secs = datetime_value_to_seconds (argv[0]);
return value_new_int (secs / 3600);
gnm_float d = value_get_as_float (argv[0]);
if (d < 0)
return value_new_error_VALUE (ei->pos);
else {
int secs = float_to_secs (d);
return value_new_int (secs / 3600);
}
}
/***************************************************************************/
......@@ -611,10 +639,14 @@ static GnmFuncHelp const help_minute[] = {
static GnmValue *
gnumeric_minute (FunctionEvalInfo *ei, GnmValue const * const *argv)
{
int secs;
gnm_float d = value_get_as_float (argv[0]);
secs = datetime_value_to_seconds (argv[0]);
return value_new_int ((secs / 60) % 60);
if (d < 0)
return value_new_error_VALUE (ei->pos);
else {
int secs = float_to_secs (d);
return value_new_int (secs / 60 % 60);
}
}
/***************************************************************************/
......@@ -644,10 +676,14 @@ static GnmFuncHelp const help_second[] = {
static GnmValue *
gnumeric_second (FunctionEvalInfo *ei, GnmValue const * const *argv)
{
int secs;
gnm_float d = value_get_as_float (argv[0]);
secs = datetime_value_to_seconds (argv[0]);
return value_new_int (secs % 60);
if (d < 0)
return value_new_error_VALUE (ei->pos);
else {
int secs = float_to_secs (d);
return value_new_int (secs % 60);
}
}
/***************************************************************************/
......
......@@ -74,16 +74,6 @@ datetime_value_to_g (GDate *res, GnmValue const *v, GODateConventions const *con
/* ------------------------------------------------------------------------- */
int
datetime_value_to_seconds (GnmValue const *v)
{
/* we just want the seconds, actual date does not matter. So we can ignore
* the date convention (1900 vs 1904) */
return datetime_serial_raw_to_seconds (datetime_value_to_serial_raw (v, NULL));
}
/* ------------------------------------------------------------------------- */
/*
* 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
......
......@@ -14,10 +14,6 @@ gnm_float datetime_value_to_serial_raw (GnmValue const *v, GODateConventions con
gboolean datetime_value_to_g (GDate *res, GnmValue const *v, GODateConventions const *conv);
int datetime_value_to_serial (GnmValue const *v, GODateConventions const *conv);
/* These are time-only assuming a 24h day. It probably loses completely on */
/* days with summer time ("daylight savings") changes. */
int datetime_value_to_seconds (GnmValue const *v);
int annual_year_basis (GnmValue const *value_date, basis_t basis,
GODateConventions const *date_conv);
gnm_float yearfrac (GDate const *from, GDate const *to, basis_t basis);
......
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