diff options
author | xuri <xuri.me@gmail.com> | 2021-03-14 22:29:18 +0800 |
---|---|---|
committer | xuri <xuri.me@gmail.com> | 2021-03-14 22:29:18 +0800 |
commit | 2350866d460c883fbd0b3a403a62b943a5f6aca5 (patch) | |
tree | f05781d72781405145fb6e14a81dbce42d979574 /calc.go | |
parent | b83a36a8aead4b76c2c4025283590e1afd7e500a (diff) |
#65 fn: NOW and TODAY, and update dependencies
Diffstat (limited to 'calc.go')
-rw-r--r-- | calc.go | 29 |
1 files changed, 29 insertions, 0 deletions
@@ -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 { |