summaryrefslogtreecommitdiff
path: root/calc.go
diff options
context:
space:
mode:
authorxuri <xuri.me@gmail.com>2021-10-16 16:05:50 +0800
committerxuri <xuri.me@gmail.com>2021-10-16 16:05:50 +0800
commitcf8766df83f03152026c2301ff99eb7121d702ba (patch)
treecbd16659a5890b2a85120c8608f9fe98ea996022 /calc.go
parentc64ce0f9ac1ffa251d6645d527263e3a9a7f854b (diff)
ref #65, new formula function: TIME
Diffstat (limited to 'calc.go')
-rw-r--r--calc.go25
1 files changed, 25 insertions, 0 deletions
diff --git a/calc.go b/calc.go
index a4ecb66..b8cb645 100644
--- a/calc.go
+++ b/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:
//