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
|
||||
|
|
Loading…
Reference in New Issue