* This closes #1004, new fn: MONTH ref #65

pull/2/head
Stani 3 years ago committed by GitHub
parent f280c03345
commit 4d716fa7ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -420,6 +420,7 @@ type formulaFuncs struct {
// MINA // MINA
// MIRR // MIRR
// MOD // MOD
// MONTH
// MROUND // MROUND
// MULTINOMIAL // MULTINOMIAL
// MUNIT // MUNIT
@ -6413,6 +6414,37 @@ func (fn *formulaFuncs) DAY(argsList *list.List) formulaArg {
return newNumberFormulaArg(float64(timeFromExcelTime(num.Number, false).Day())) 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 // NOW function returns the current date and time. The function receives no
// arguments and therefore. The syntax of the function is: // arguments and therefore. The syntax of the function is:
// //

@ -962,6 +962,9 @@ func TestCalcCellValue(t *testing.T) {
"=DAY(\"3-February-2008\")": "3", "=DAY(\"3-February-2008\")": "3",
"=DAY(\"01/25/20\")": "25", "=DAY(\"01/25/20\")": "25",
"=DAY(\"01/25/31\")": "25", "=DAY(\"01/25/31\")": "25",
// MONTH
"=MONTH(42171)": "6",
"=MONTH(\"31-May-2015\")": "5",
// Text Functions // Text Functions
// CHAR // CHAR
"=CHAR(65)": "A", "=CHAR(65)": "A",
@ -1981,6 +1984,12 @@ func TestCalcCellValue(t *testing.T) {
"=DAY(\"3-January-9223372036854775808\")": "#VALUE!", "=DAY(\"3-January-9223372036854775808\")": "#VALUE!",
"=DAY(\"9223372036854775808-January-1900\")": "#VALUE!", "=DAY(\"9223372036854775808-January-1900\")": "#VALUE!",
"=DAY(\"0-January-1900\")": "#VALUE!", "=DAY(\"0-January-1900\")": "#VALUE!",
// MONTH
"=MONTH()": "MONTH requires exactly 1 argument",
"=MONTH(43891,43101)": "MONTH requires exactly 1 argument",
"=MONTH(-1)": "MONTH only accepts positive argument",
"=MONTH(\"text\")": "#VALUE!",
"=MONTH(\"January 25, 100\")": "#VALUE!",
// NOW // NOW
"=NOW(A1)": "NOW accepts no arguments", "=NOW(A1)": "NOW accepts no arguments",
// TODAY // TODAY

Loading…
Cancel
Save