forked from p30928647/excelize
ref #65, new formula function: TIME
This commit is contained in:
parent
c64ce0f9ac
commit
cf8766df83
25
calc.go
25
calc.go
|
@ -489,6 +489,7 @@ type formulaFuncs struct {
|
|||
// T
|
||||
// TAN
|
||||
// TANH
|
||||
// TIME
|
||||
// TODAY
|
||||
// TRANSPOSE
|
||||
// TRIM
|
||||
|
@ -6848,6 +6849,30 @@ func (fn *formulaFuncs) NOW(argsList *list.List) formulaArg {
|
|||
return newNumberFormulaArg(25569.0 + float64(now.Unix()+int64(offset))/86400)
|
||||
}
|
||||
|
||||
// TIME function accepts three integer arguments representing hours, minutes
|
||||
// and seconds, and returns an Excel time. I.e. the function returns the
|
||||
// decimal value that represents the time in Excel. The syntax of the Time
|
||||
// function is:
|
||||
//
|
||||
// TIME(hour,minute,second)
|
||||
//
|
||||
func (fn *formulaFuncs) TIME(argsList *list.List) formulaArg {
|
||||
if argsList.Len() != 3 {
|
||||
return newErrorFormulaArg(formulaErrorVALUE, "TIME requires 3 number arguments")
|
||||
}
|
||||
h := argsList.Front().Value.(formulaArg).ToNumber()
|
||||
m := argsList.Front().Next().Value.(formulaArg).ToNumber()
|
||||
s := argsList.Back().Value.(formulaArg).ToNumber()
|
||||
if h.Type != ArgNumber || m.Type != ArgNumber || s.Type != ArgNumber {
|
||||
return newErrorFormulaArg(formulaErrorVALUE, "TIME requires 3 number arguments")
|
||||
}
|
||||
t := (h.Number*3600 + m.Number*60 + s.Number) / 86400
|
||||
if t < 0 {
|
||||
return newErrorFormulaArg(formulaErrorNUM, formulaErrorNUM)
|
||||
}
|
||||
return newNumberFormulaArg(t)
|
||||
}
|
||||
|
||||
// TODAY function returns the current date. The function has no arguments and
|
||||
// therefore. The syntax of the function is:
|
||||
//
|
||||
|
|
|
@ -1016,6 +1016,10 @@ func TestCalcCellValue(t *testing.T) {
|
|||
"=YEARFRAC(\"02/29/2000\", \"01/29/2001\",1)": "0.915300546448087",
|
||||
"=YEARFRAC(\"02/29/2000\", \"03/29/2000\",1)": "0.0792349726775956",
|
||||
"=YEARFRAC(\"01/31/2000\", \"03/29/2000\",4)": "0.163888888888889",
|
||||
// TIME
|
||||
"=TIME(5,44,32)": "0.239259259259259",
|
||||
"=TIME(\"5\",\"44\",\"32\")": "0.239259259259259",
|
||||
"=TIME(0,0,73)": "0.000844907407407407",
|
||||
// Text Functions
|
||||
// CHAR
|
||||
"=CHAR(65)": "A",
|
||||
|
@ -2093,6 +2097,10 @@ func TestCalcCellValue(t *testing.T) {
|
|||
"=YEARFRAC(42005,42094,\"\")": "strconv.ParseFloat: parsing \"\": invalid syntax",
|
||||
// NOW
|
||||
"=NOW(A1)": "NOW accepts no arguments",
|
||||
// TIME
|
||||
"=TIME()": "TIME requires 3 number arguments",
|
||||
"=TIME(\"\",0,0)": "TIME requires 3 number arguments",
|
||||
"=TIME(0,0,-1)": "#NUM!",
|
||||
// TODAY
|
||||
"=TODAY(A1)": "TODAY accepts no arguments",
|
||||
// Text Functions
|
||||
|
|
10
cell_test.go
10
cell_test.go
|
@ -268,11 +268,11 @@ func TestGetCellValue(t *testing.T) {
|
|||
<c r="T1"><v>68.900000000000006</v></c>
|
||||
<c r="U1"><v>8.8880000000000001E-2</v></c>
|
||||
<c r="V1"><v>4.0000000000000003E-5</v></c>
|
||||
<c r="W1"><v>2422.3000000000002</v></c>
|
||||
<c r="X1"><v>1101.5999999999999</v></c>
|
||||
<c r="Y1"><v>275.39999999999998</v></c>
|
||||
<c r="Z1"><v>68.900000000000006</v></c>
|
||||
<c r="AA1"><v>1.1000000000000001</v></c>
|
||||
<c r="W1"><v>2422.3000000000002</v></c>
|
||||
<c r="X1"><v>1101.5999999999999</v></c>
|
||||
<c r="Y1"><v>275.39999999999998</v></c>
|
||||
<c r="Z1"><v>68.900000000000006</v></c>
|
||||
<c r="AA1"><v>1.1000000000000001</v></c>
|
||||
</row>`)))
|
||||
f.checked = nil
|
||||
rows, err = f.GetRows("Sheet1")
|
||||
|
|
Loading…
Reference in New Issue