mirror of
https://github.com/unidoc/unioffice.git
synced 2025-04-25 13:48:53 +08:00
Merge branch 'master' into license-update-fix
This commit is contained in:
commit
2ca5dd2076
@ -8,6 +8,8 @@
|
||||
package formula
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
@ -205,7 +207,7 @@ const nsPerDay = 86400000000000
|
||||
|
||||
func dateFromDays(days float64) time.Time {
|
||||
unix := int64((days - daysTo1970) * nsPerDay)
|
||||
return time.Unix(0, unix)
|
||||
return time.Unix(0, unix).UTC()
|
||||
}
|
||||
|
||||
func daysFromDate(y, m, d int) float64 {
|
||||
@ -786,17 +788,26 @@ func YearFrac(args []Result) Result {
|
||||
if args[1].Type != ResultTypeNumber {
|
||||
return MakeErrorResult("YEARFRAC requires end date to be number argument")
|
||||
}
|
||||
spew.Dump(args)
|
||||
spew.Dump(startDate)
|
||||
endDate := args[1].ValueNumber
|
||||
spew.Dump(endDate)
|
||||
spew.Dump(basis)
|
||||
yf, errResult := yearFrac(startDate, endDate, basis)
|
||||
if errResult.Type == ResultTypeError {
|
||||
return errResult
|
||||
}
|
||||
spew.Dump(yf)
|
||||
return MakeNumberResult(yf)
|
||||
}
|
||||
|
||||
// yearFrac returns float64 fraction of the year and Result value which can be of ResultTypeError type if an error occurs or ResultTypeEmpty if doesn't.
|
||||
// yearFrac returns float64 fraction of the year and Result value which can be of
|
||||
// ResultTypeError type if an error occurs or ResultTypeEmpty if doesn't.
|
||||
func yearFrac(startDateF, endDateF float64, basis int) (float64, Result) {
|
||||
startDate, endDate := dateFromDays(startDateF), dateFromDays(endDateF)
|
||||
fmt.Printf("yearFRac\n")
|
||||
spew.Dump(startDate)
|
||||
spew.Dump(endDate)
|
||||
startDateS := startDate.Unix()
|
||||
endDateS := endDate.Unix()
|
||||
if startDateS == endDateS {
|
||||
|
@ -1136,14 +1136,14 @@ func TestYearFrac(t *testing.T) {
|
||||
ss := spreadsheet.New()
|
||||
sheet := ss.AddSheet()
|
||||
|
||||
sheet.Cell("A1").SetTime(time.Date(1900, time.January, 1, 0, 0, 0, 0, time.UTC))
|
||||
sheet.Cell("A2").SetTime(time.Date(1900, time.January, 2, 0, 0, 0, 0, time.UTC))
|
||||
sheet.Cell("A3").SetTime(time.Date(1900, time.January, 31, 0, 0, 0, 0, time.UTC))
|
||||
sheet.Cell("A4").SetTime(time.Date(1900, time.March, 31, 0, 0, 0, 0, time.UTC))
|
||||
sheet.Cell("A5").SetTime(time.Date(1900, time.February, 1, 0, 0, 0, 0, time.UTC))
|
||||
sheet.Cell("A6").SetTime(time.Date(1904, time.January, 1, 0, 0, 0, 0, time.UTC))
|
||||
sheet.Cell("A7").SetTime(time.Date(1904, time.January, 2, 0, 0, 0, 0, time.UTC))
|
||||
sheet.Cell("A8").SetTime(time.Date(1905, time.January, 1, 0, 0, 0, 0, time.UTC))
|
||||
sheet.Cell("A1").SetTime(time.Date(1900, time.January, 1, 0, 0, 0, 0, time.Local))
|
||||
sheet.Cell("A2").SetTime(time.Date(1900, time.January, 2, 0, 0, 0, 0, time.Local))
|
||||
sheet.Cell("A3").SetTime(time.Date(1900, time.January, 31, 0, 0, 0, 0, time.Local))
|
||||
sheet.Cell("A4").SetTime(time.Date(1900, time.March, 31, 0, 0, 0, 0, time.Local))
|
||||
sheet.Cell("A5").SetTime(time.Date(1900, time.February, 1, 0, 0, 0, 0, time.Local))
|
||||
sheet.Cell("A6").SetTime(time.Date(1904, time.January, 1, 0, 0, 0, 0, time.Local))
|
||||
sheet.Cell("A7").SetTime(time.Date(1904, time.January, 2, 0, 0, 0, 0, time.Local))
|
||||
sheet.Cell("A8").SetTime(time.Date(1905, time.January, 1, 0, 0, 0, 0, time.Local))
|
||||
sheet.Cell("A9").SetString("Hello")
|
||||
sheet.Cell("A10").SetString("World")
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user