From 40ff5dc1a7d7aa42f5db9cf9dfe858cc3820b44e Mon Sep 17 00:00:00 2001 From: xuri Date: Sat, 23 Mar 2019 20:08:06 +0800 Subject: refactor: handler error instead of panic, Exported functions: SetCellStyle InsertCol RemoveCol RemoveRow InsertRow DuplicateRow DuplicateRowTo SetRowHeight GetRowHeight GetCellValue GetCellFormula GetCellHyperLink SetCellHyperLink SetCellInt SetCellBool SetCellFloat SetCellStr SetCellDefault GetCellStyle SetCellValue MergeCell SetSheetRow SetRowVisible GetRowVisible SetRowOutlineLevel GetRowOutlineLevel GetRows Columns SearchSheet AddTable GetPicture AutoFilter GetColVisible SetColVisible GetColOutlineLevel SetColOutlineLevel SetColWidth GetColWidth inner functions: adjustHelper adjustMergeCells adjustAutoFilter prepareCell setDefaultTimeStyle timeToExcelTime addDrawingChart addDrawingVML addDrawingPicture getTotalRowsCols checkRow addDrawingShape addTable --- date.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'date.go') diff --git a/date.go b/date.go index e550feb..b49a695 100644 --- a/date.go +++ b/date.go @@ -10,6 +10,7 @@ package excelize import ( + "errors" "math" "time" ) @@ -25,18 +26,18 @@ var ( ) // timeToExcelTime provides a function to convert time to Excel time. -func timeToExcelTime(t time.Time) float64 { +func timeToExcelTime(t time.Time) (float64, error) { // TODO in future this should probably also handle date1904 and like TimeFromExcelTime // Force user to explicit convet passed value to UTC time. // Because for example 1900-01-01 00:00:00 +0300 MSK converts to 1900-01-01 00:00:00 +0230 LMT // probably due to daylight saving. if t.Location() != time.UTC { - panic("only UTC time expected") + return 0.0, errors.New("only UTC time expected") } if t.Before(excelMinTime1900) { - return 0.0 + return 0.0, nil } tt := t @@ -60,7 +61,7 @@ func timeToExcelTime(t time.Time) float64 { if t.After(excelBuggyPeriodStart) { result += 1.0 } - return result + return result, nil } // shiftJulianToNoon provides a function to process julian date to noon. -- cgit v1.2.1