From 2add938798cdd1456616869298319528b0c76913 Mon Sep 17 00:00:00 2001 From: xuri Date: Fri, 17 Sep 2021 00:15:51 +0800 Subject: - new formula functions: DATEVALUE, ref #65 - fix ineffectual variable assignments - timeout in go test --- calc.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'calc.go') diff --git a/calc.go b/calc.go index 9cbc8ec..3e402e6 100644 --- a/calc.go +++ b/calc.go @@ -321,6 +321,7 @@ type formulaFuncs struct { // CUMPRINC // DATE // DATEDIF +// DATEVALUE // DAY // DB // DDB @@ -6515,6 +6516,30 @@ func strToDate(str string) (int, int, int, bool, formulaArg) { return year, month, day, timeIsEmpty, newEmptyFormulaArg() } +// DATEVALUE function converts a text representation of a date into an Excel +// date. For example, the function converts a text string representing a +// date, into the serial number that represents the date in Excel's date-time +// code. The syntax of the function is: +// +// DATEVALUE(date_text) +// +func (fn *formulaFuncs) DATEVALUE(argsList *list.List) formulaArg { + if argsList.Len() != 1 { + return newErrorFormulaArg(formulaErrorVALUE, "DATEVALUE requires 1 argument") + } + dateText := argsList.Front().Value.(formulaArg).Value() + if !isDateOnlyFmt(dateText) { + if _, _, _, _, _, err := strToTime(dateText); err.Type == ArgError { + return err + } + } + y, m, d, _, err := strToDate(dateText) + if err.Type == ArgError { + return err + } + return newNumberFormulaArg(daysBetween(excelMinTime1900.Unix(), makeDate(y, time.Month(m), d)) + 1) +} + // DAY function returns the day of a date, represented by a serial number. The // day is given as an integer ranging from 1 to 31. The syntax of the // function is: -- cgit v1.2.1