diff options
| author | xuri <xuri.me@gmail.com> | 2021-09-17 00:15:51 +0800 |
|---|---|---|
| committer | xuri <xuri.me@gmail.com> | 2021-09-17 00:15:51 +0800 |
| commit | 2add938798cdd1456616869298319528b0c76913 (patch) | |
| tree | 6df02447bf25779e5bd6099ade16438568c9640e /calc.go | |
| parent | 1ba3690764e90aa6f7bcb3cb1e095475d40e3d91 (diff) | |
- new formula functions: DATEVALUE, ref #65
- fix ineffectual variable assignments
- timeout in go test
Diffstat (limited to 'calc.go')
| -rw-r--r-- | calc.go | 25 |
1 files changed, 25 insertions, 0 deletions
@@ -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: |
