From 2350866d460c883fbd0b3a403a62b943a5f6aca5 Mon Sep 17 00:00:00 2001 From: xuri Date: Sun, 14 Mar 2021 22:29:18 +0800 Subject: #65 fn: NOW and TODAY, and update dependencies --- calc.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'calc.go') diff --git a/calc.go b/calc.go index 8b78e28..ef8d88c 100644 --- a/calc.go +++ b/calc.go @@ -320,6 +320,7 @@ var tokenPriority = map[string]int{ // MUNIT // NA // NOT +// NOW // OCT2BIN // OCT2DEC // OCT2HEX @@ -362,6 +363,7 @@ var tokenPriority = map[string]int{ // SUMSQ // TAN // TANH +// TODAY // TRIM // TRUE // TRUNC @@ -4647,6 +4649,33 @@ func (fn *formulaFuncs) DATE(argsList *list.List) formulaArg { return newStringFormulaArg(timeFromExcelTime(daysBetween(excelMinTime1900.Unix(), d)+1, false).String()) } +// NOW function returns the current date and time. The function receives no arguments and therefore. The syntax of the function is: +// +// NOW() +// +func (fn *formulaFuncs) NOW(argsList *list.List) formulaArg { + if argsList.Len() != 0 { + return newErrorFormulaArg(formulaErrorVALUE, "NOW accepts no arguments") + } + now := time.Now() + _, offset := now.Zone() + return newNumberFormulaArg(25569.0 + float64(now.Unix()+int64(offset))/86400) +} + +// TODAY function returns the current date. The function has no arguments and +// therefore. The syntax of the function is: +// +// TODAY() +// +func (fn *formulaFuncs) TODAY(argsList *list.List) formulaArg { + if argsList.Len() != 0 { + return newErrorFormulaArg(formulaErrorVALUE, "TODAY accepts no arguments") + } + now := time.Now() + _, offset := now.Zone() + return newNumberFormulaArg(daysBetween(excelMinTime1900.Unix(), now.Unix()+int64(offset)) + 1) +} + // makeDate return date as a Unix time, the number of seconds elapsed since // January 1, 1970 UTC. func makeDate(y int, m time.Month, d int) int64 { -- cgit v1.2.1