Commit ab7ae6f1 authored by Havoc Pennington's avatar Havoc Pennington Committed by Havoc Pennington
Browse files

An old patch I forgot to commit.

1999-01-04  Havoc Pennington  <hp@pobox.com>

	* src/fn-date.c (gnumeric_date): Allocate the GDate on the stack,
		saves some small amount of time. Check user-provided
			month/day/year for validity before using it.
				(gnumeric_today): Allocate GDate on the stack.
					(gnumeric_now): Ditto.
parent 66bbc270
1999-01-04 Havoc Pennington <hp@pobox.com>
* src/fn-date.c (gnumeric_date): Allocate the GDate on the stack,
saves some small amount of time. Check user-provided
month/day/year for validity before using it.
(gnumeric_today): Allocate GDate on the stack.
(gnumeric_now): Ditto.
1999-01-04 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/sheet.c (sheet_rename): New routine.
......
1999-01-04 Havoc Pennington <hp@pobox.com>
* src/fn-date.c (gnumeric_date): Allocate the GDate on the stack,
saves some small amount of time. Check user-provided
month/day/year for validity before using it.
(gnumeric_today): Allocate GDate on the stack.
(gnumeric_now): Ditto.
1999-01-04 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/sheet.c (sheet_rename): New routine.
......
1999-01-04 Havoc Pennington <hp@pobox.com>
* src/fn-date.c (gnumeric_date): Allocate the GDate on the stack,
saves some small amount of time. Check user-provided
month/day/year for validity before using it.
(gnumeric_today): Allocate GDate on the stack.
(gnumeric_now): Ditto.
1999-01-04 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/sheet.c (sheet_rename): New routine.
......
1999-01-04 Havoc Pennington <hp@pobox.com>
* src/fn-date.c (gnumeric_date): Allocate the GDate on the stack,
saves some small amount of time. Check user-provided
month/day/year for validity before using it.
(gnumeric_today): Allocate GDate on the stack.
(gnumeric_now): Ditto.
1999-01-04 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/sheet.c (sheet_rename): New routine.
......
......@@ -35,22 +35,34 @@ gnumeric_date (struct FunctionDefinition *fd, Value *argv [], char **error_strin
{
Value *v;
int year, month, day;
GDate *date;
GDate date;
year = value_get_as_double (argv [0]);
month = value_get_as_double (argv [1]);
day = value_get_as_double (argv [2]);
date = g_date_new_dmy (1, month, year);
if (!g_date_valid_dmy(1, month, year))
{
*error_string = _("Invalid month or year");
return NULL;
}
g_date_clear(&date, 1);
g_date_set_dmy (&date, 1, month, year);
if (day > 0)
g_date_set_day (date, day);
else
g_date_subtract_days (date, -day + 1);
g_date_set_day (&date, day);
else
g_date_subtract_days (&date, -day + 1);
v = value_int (g_date_serial (date));
if (!g_date_valid(&date))
{
*error_string = _("Invalid day");
return NULL;
}
g_date_free (date);
v = value_int (g_date_serial (&date));
return v;
}
......@@ -72,13 +84,14 @@ static Value *
gnumeric_today (FunctionDefinition *fd, Value *argv [], char **error_string)
{
Value *v;
GDate *date = g_date_new ();
GDate date;
g_date_clear(&date, 1);
g_date_set_time (date, time (NULL));
g_date_set_time (&date, time (NULL));
v = value_int (g_date_serial (date));
g_date_free (date);
v = value_int (g_date_serial (&date));
return v;
}
......@@ -110,16 +123,16 @@ gnumeric_now (FunctionDefinition *fd, Value *argv [], char **error_string)
Value *v;
time_t t = time (NULL);
struct tm *tm = localtime (&t);
GDate *date = g_date_new ();
GDate date;
g_date_clear(&date, 1);
g_date_set_time (date, t);
g_date_set_time (&date, t);
v = value_float (g_date_serial (date) +
v = value_float (g_date_serial(&date) +
((tm->tm_hour * 3600 + tm->tm_min * 60
+ tm->tm_sec)/(double)DAY_SECONDS));
g_date_free (date);
return v;
}
......
......@@ -35,22 +35,34 @@ gnumeric_date (struct FunctionDefinition *fd, Value *argv [], char **error_strin
{
Value *v;
int year, month, day;
GDate *date;
GDate date;
year = value_get_as_double (argv [0]);
month = value_get_as_double (argv [1]);
day = value_get_as_double (argv [2]);
date = g_date_new_dmy (1, month, year);
if (!g_date_valid_dmy(1, month, year))
{
*error_string = _("Invalid month or year");
return NULL;
}
g_date_clear(&date, 1);
g_date_set_dmy (&date, 1, month, year);
if (day > 0)
g_date_set_day (date, day);
else
g_date_subtract_days (date, -day + 1);
g_date_set_day (&date, day);
else
g_date_subtract_days (&date, -day + 1);
v = value_int (g_date_serial (date));
if (!g_date_valid(&date))
{
*error_string = _("Invalid day");
return NULL;
}
g_date_free (date);
v = value_int (g_date_serial (&date));
return v;
}
......@@ -72,13 +84,14 @@ static Value *
gnumeric_today (FunctionDefinition *fd, Value *argv [], char **error_string)
{
Value *v;
GDate *date = g_date_new ();
GDate date;
g_date_clear(&date, 1);
g_date_set_time (date, time (NULL));
g_date_set_time (&date, time (NULL));
v = value_int (g_date_serial (date));
g_date_free (date);
v = value_int (g_date_serial (&date));
return v;
}
......@@ -110,16 +123,16 @@ gnumeric_now (FunctionDefinition *fd, Value *argv [], char **error_string)
Value *v;
time_t t = time (NULL);
struct tm *tm = localtime (&t);
GDate *date = g_date_new ();
GDate date;
g_date_clear(&date, 1);
g_date_set_time (date, t);
g_date_set_time (&date, t);
v = value_float (g_date_serial (date) +
v = value_float (g_date_serial(&date) +
((tm->tm_hour * 3600 + tm->tm_min * 60
+ tm->tm_sec)/(double)DAY_SECONDS));
g_date_free (date);
return v;
}
......
......@@ -35,22 +35,34 @@ gnumeric_date (struct FunctionDefinition *fd, Value *argv [], char **error_strin
{
Value *v;
int year, month, day;
GDate *date;
GDate date;
year = value_get_as_double (argv [0]);
month = value_get_as_double (argv [1]);
day = value_get_as_double (argv [2]);
date = g_date_new_dmy (1, month, year);
if (!g_date_valid_dmy(1, month, year))
{
*error_string = _("Invalid month or year");
return NULL;
}
g_date_clear(&date, 1);
g_date_set_dmy (&date, 1, month, year);
if (day > 0)
g_date_set_day (date, day);
else
g_date_subtract_days (date, -day + 1);
g_date_set_day (&date, day);
else
g_date_subtract_days (&date, -day + 1);
v = value_int (g_date_serial (date));
if (!g_date_valid(&date))
{
*error_string = _("Invalid day");
return NULL;
}
g_date_free (date);
v = value_int (g_date_serial (&date));
return v;
}
......@@ -72,13 +84,14 @@ static Value *
gnumeric_today (FunctionDefinition *fd, Value *argv [], char **error_string)
{
Value *v;
GDate *date = g_date_new ();
GDate date;
g_date_clear(&date, 1);
g_date_set_time (date, time (NULL));
g_date_set_time (&date, time (NULL));
v = value_int (g_date_serial (date));
g_date_free (date);
v = value_int (g_date_serial (&date));
return v;
}
......@@ -110,16 +123,16 @@ gnumeric_now (FunctionDefinition *fd, Value *argv [], char **error_string)
Value *v;
time_t t = time (NULL);
struct tm *tm = localtime (&t);
GDate *date = g_date_new ();
GDate date;
g_date_clear(&date, 1);
g_date_set_time (date, t);
g_date_set_time (&date, t);
v = value_float (g_date_serial (date) +
v = value_float (g_date_serial(&date) +
((tm->tm_hour * 3600 + tm->tm_min * 60
+ tm->tm_sec)/(double)DAY_SECONDS));
g_date_free (date);
return v;
}
......
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