diff options
author | xuri <xuri.me@gmail.com> | 2021-10-16 16:05:50 +0800 |
---|---|---|
committer | xuri <xuri.me@gmail.com> | 2021-10-16 16:05:50 +0800 |
commit | cf8766df83f03152026c2301ff99eb7121d702ba (patch) | |
tree | cbd16659a5890b2a85120c8608f9fe98ea996022 /calc.go | |
parent | c64ce0f9ac1ffa251d6645d527263e3a9a7f854b (diff) |
ref #65, new formula function: TIME
Diffstat (limited to 'calc.go')
-rw-r--r-- | calc.go | 25 |
1 files changed, 25 insertions, 0 deletions
@@ -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: // |