diff options
| author | Stani <spe.stani.be@gmail.com> | 2021-08-21 09:46:43 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-08-21 15:46:43 +0800 |
| commit | 4d716fa7edde76ed838aefcd8c5945bcfe3ba8f3 (patch) | |
| tree | 503abf127202c6c232ea80506cf3e24e3a5425f1 /calc.go | |
| parent | f280c03345dc2a207ac319182da182a0f0fbb963 (diff) | |
* This closes #1004, new fn: MONTH ref #65
Diffstat (limited to 'calc.go')
| -rw-r--r-- | calc.go | 32 |
1 files changed, 32 insertions, 0 deletions
@@ -420,6 +420,7 @@ type formulaFuncs struct { // MINA // MIRR // MOD +// MONTH // MROUND // MULTINOMIAL // MUNIT @@ -6413,6 +6414,37 @@ func (fn *formulaFuncs) DAY(argsList *list.List) formulaArg { return newNumberFormulaArg(float64(timeFromExcelTime(num.Number, false).Day())) } +// MONTH function returns the month of a date represented by a serial number. +// The month is given as an integer, ranging from 1 (January) to 12 +// (December). The syntax of the function is: +// +// MONTH(serial_number) +// +func (fn *formulaFuncs) MONTH(argsList *list.List) formulaArg { + if argsList.Len() != 1 { + return newErrorFormulaArg(formulaErrorVALUE, "MONTH requires exactly 1 argument") + } + arg := argsList.Front().Value.(formulaArg) + num := arg.ToNumber() + if num.Type != ArgNumber { + dateString := strings.ToLower(arg.Value()) + if !isDateOnlyFmt(dateString) { + if _, _, _, _, _, err := strToTime(dateString); err.Type == ArgError { + return err + } + } + _, month, _, _, err := strToDate(dateString) + if err.Type == ArgError { + return err + } + return newNumberFormulaArg(float64(month)) + } + if num.Number < 0 { + return newErrorFormulaArg(formulaErrorNUM, "MONTH only accepts positive argument") + } + return newNumberFormulaArg(float64(timeFromExcelTime(num.Number, false).Month())) +} + // NOW function returns the current date and time. The function receives no // arguments and therefore. The syntax of the function is: // |
