functions.c (gnumeric-1.12.49.tar.xz) | : | functions.c (gnumeric-1.12.50.tar.xz) | ||
---|---|---|---|---|
skipping to change at line 818 | skipping to change at line 818 | |||
{ GNM_FUNC_HELP_NOTE, F_("@{days} may be negative.") }, | { GNM_FUNC_HELP_NOTE, F_("@{days} may be negative.") }, | |||
{ GNM_FUNC_HELP_NOTE, F_("If an entry of @{weekend} is non-zero, the corr esponding weekday is not a work day.")}, | { GNM_FUNC_HELP_NOTE, F_("If an entry of @{weekend} is non-zero, the corr esponding weekday is not a work day.")}, | |||
{ GNM_FUNC_HELP_EXCEL, F_("This function is Excel compatible if the last argument is omitted.") }, | { GNM_FUNC_HELP_EXCEL, F_("This function is Excel compatible if the last argument is omitted.") }, | |||
{ GNM_FUNC_HELP_ODF, F_("This function is OpenFormula compatible.") }, | { GNM_FUNC_HELP_ODF, F_("This function is OpenFormula compatible.") }, | |||
{ GNM_FUNC_HELP_EXAMPLES, "=WORKDAY(DATE(2001,12,14),2)" }, | { GNM_FUNC_HELP_EXAMPLES, "=WORKDAY(DATE(2001,12,14),2)" }, | |||
{ GNM_FUNC_HELP_EXAMPLES, "=WORKDAY(DATE(2001,12,14),2,,{0,0,0,0,0,1,1}) " }, | { GNM_FUNC_HELP_EXAMPLES, "=WORKDAY(DATE(2001,12,14),2,,{0,0,0,0,0,1,1}) " }, | |||
{ GNM_FUNC_HELP_SEEALSO, "NETWORKDAYS"}, | { GNM_FUNC_HELP_SEEALSO, "NETWORKDAYS"}, | |||
{ GNM_FUNC_HELP_END } | { GNM_FUNC_HELP_END } | |||
}; | }; | |||
static gint | ||||
float_compare (gnm_float const *a, gnm_float const *b) | ||||
{ | ||||
if (*a < *b) | ||||
return -1; | ||||
else if (*a == *b) | ||||
return 0; | ||||
else | ||||
return 1; | ||||
} | ||||
static GnmValue * | static GnmValue * | |||
gnumeric_workday (GnmFuncEvalInfo *ei, GnmValue const * const *argv) | gnumeric_workday (GnmFuncEvalInfo *ei, GnmValue const * const *argv) | |||
{ | { | |||
GDate date; | GDate date; | |||
GODateConventions const *conv = DATE_CONV (ei->pos); | GODateConventions const *conv = DATE_CONV (ei->pos); | |||
gnm_float days = value_get_as_float (argv[1]); | gnm_float days = value_get_as_float (argv[1]); | |||
int idays; | int idays; | |||
gnm_float *holidays = NULL; | gnm_float *holidays = NULL; | |||
gnm_float *weekends = NULL; | gnm_float *weekends = NULL; | |||
gnm_float const default_weekends[] = {1.,0.,0.,0.,0.,0.,1.}; | gnm_float const default_weekends[] = {1.,0.,0.,0.,0.,0.,1.}; | |||
int nholidays, nweekends, n_non_weekend = 0; | int nholidays, nweekends, n_non_weekend = 0; | |||
GDateWeekday weekday; | GDateWeekday weekday; | |||
int serial; | int serial = 0; | |||
int i; | int i; | |||
datetime_value_to_g (&date, argv[0], conv); | datetime_value_to_g (&date, argv[0], conv); | |||
if (!g_date_valid (&date)) | if (!g_date_valid (&date)) | |||
goto bad; | goto bad; | |||
if (days > INT_MAX / 2 || -days > INT_MAX / 2) | if (days > INT_MAX / 2 || -days > INT_MAX / 2) | |||
return value_new_error_NUM (ei->pos); | return value_new_error_NUM (ei->pos); | |||
idays = (int)days; | idays = (int)days; | |||
skipping to change at line 889 | skipping to change at line 878 | |||
} | } | |||
if (argv[2]) { | if (argv[2]) { | |||
int j; | int j; | |||
GDate hol; | GDate hol; | |||
GnmValue *result = NULL; | GnmValue *result = NULL; | |||
holidays = collect_floats_value (argv[2], ei->pos, | holidays = collect_floats_value (argv[2], ei->pos, | |||
COLLECT_COERCE_STRINGS | | COLLECT_COERCE_STRINGS | | |||
COLLECT_IGNORE_BOOLS | | COLLECT_IGNORE_BOOLS | | |||
COLLECT_IGNORE_BLANKS, | COLLECT_IGNORE_BLANKS | | |||
COLLECT_SORT, | ||||
&nholidays, &result); | &nholidays, &result); | |||
if (result) { | if (result) { | |||
if (weekends != default_weekends) | if (weekends != default_weekends) | |||
g_free (weekends); | g_free (weekends); | |||
return result; | return result; | |||
} | } | |||
qsort (holidays, nholidays, sizeof (holidays[0]), (void *) &float _compare); | ||||
for (i = j = 0; i < nholidays; i++) { | for (i = j = 0; i < nholidays; i++) { | |||
gnm_float s = holidays[i]; | gnm_float s = holidays[i]; | |||
int hserial; | int hserial; | |||
if (s < 0 || s > INT_MAX) | if (s < 0 || s > INT_MAX) | |||
goto bad; | goto bad; | |||
hserial = (int)s; | hserial = (int)s; | |||
if (j > 0 && hserial == holidays[j - 1]) | if (j > 0 && hserial == holidays[j - 1]) | |||
continue; /* Dupe */ | continue; /* Dupe */ | |||
go_date_serial_to_g (&hol, hserial, conv); | go_date_serial_to_g (&hol, hserial, conv); | |||
skipping to change at line 1189 | skipping to change at line 1178 | |||
/* Now get the holiday info */ | /* Now get the holiday info */ | |||
if (argv[2]) { | if (argv[2]) { | |||
int j; | int j; | |||
GDate hol; | GDate hol; | |||
GnmValue *result = NULL; | GnmValue *result = NULL; | |||
holidays = collect_floats_value (argv[2], ei->pos, | holidays = collect_floats_value (argv[2], ei->pos, | |||
COLLECT_COERCE_STRINGS | | COLLECT_COERCE_STRINGS | | |||
COLLECT_IGNORE_BOOLS | | COLLECT_IGNORE_BOOLS | | |||
COLLECT_IGNORE_BLANKS, | COLLECT_IGNORE_BLANKS | | |||
COLLECT_SORT, | ||||
&nholidays, &result); | &nholidays, &result); | |||
if (result) { | if (result) { | |||
if (weekends != default_weekends) | if (weekends != default_weekends) | |||
g_free (weekends); | g_free (weekends); | |||
return result; | return result; | |||
} | } | |||
qsort (holidays, nholidays, sizeof (holidays[0]), (void *) &float _compare); | ||||
for (i = j = 0; i < nholidays; i++) { | for (i = j = 0; i < nholidays; i++) { | |||
gnm_float s = holidays[i]; | gnm_float s = holidays[i]; | |||
int hserial; | int hserial; | |||
if (s < 0 || s > INT_MAX) | if (s < 0 || s > INT_MAX) | |||
goto bad; | goto bad; | |||
hserial = (int)s; | hserial = (int)s; | |||
if (j > 0 && hserial == holidays[j - 1]) | if (j > 0 && hserial == holidays[j - 1]) | |||
continue; /* Dupe */ | continue; /* Dupe */ | |||
go_date_serial_to_g (&hol, hserial, conv); | go_date_serial_to_g (&hol, hserial, conv); | |||
End of changes. 6 change blocks. | ||||
16 lines changed or deleted | 5 lines changed or added |