@ -40,7 +40,7 @@ var excelTimeInputList = []dateTest{
func TestTimeToExcelTime ( t * testing . T ) {
for i , test := range trueExpectedDateList {
t . Run ( fmt . Sprintf ( "TestData%d" , i + 1 ) , func ( t * testing . T ) {
excelTime , err := timeToExcelTime ( test . GoValue )
excelTime , err := timeToExcelTime ( test . GoValue , false )
assert . NoError ( t , err )
assert . Equalf ( t , test . ExcelValue , excelTime ,
"Time: %s" , test . GoValue . String ( ) )
@ -55,7 +55,7 @@ func TestTimeToExcelTime_Timezone(t *testing.T) {
}
for i , test := range trueExpectedDateList {
t . Run ( fmt . Sprintf ( "TestData%d" , i + 1 ) , func ( t * testing . T ) {
_ , err := timeToExcelTime ( test . GoValue . In ( location ) )
_ , err := timeToExcelTime ( test . GoValue . In ( location ) , false )
assert . NoError ( t , err )
} )
}
@ -71,21 +71,34 @@ func TestTimeFromExcelTime(t *testing.T) {
for min := 0 ; min < 60 ; min ++ {
for sec := 0 ; sec < 60 ; sec ++ {
date := time . Date ( 2021 , time . December , 30 , hour , min , sec , 0 , time . UTC )
excelTime , err := timeToExcelTime ( date )
// Test use 1900 date system
excel1900Time , err := timeToExcelTime ( date , false )
assert . NoError ( t , err )
dateOut := timeFromExcelTime ( excelTime , false )
assert . EqualValues ( t , hour , dateOut . Hour ( ) )
assert . EqualValues ( t , min , dateOut . Minute ( ) )
assert . EqualValues ( t , sec , dateOut . Second ( ) )
date1900Out := timeFromExcelTime ( excel1900Time , false )
assert . EqualValues ( t , hour , date1900Out . Hour ( ) )
assert . EqualValues ( t , min , date1900Out . Minute ( ) )
assert . EqualValues ( t , sec , date1900Out . Second ( ) )
// Test use 1904 date system
excel1904Time , err := timeToExcelTime ( date , true )
assert . NoError ( t , err )
date1904Out := timeFromExcelTime ( excel1904Time , true )
assert . EqualValues ( t , hour , date1904Out . Hour ( ) )
assert . EqualValues ( t , min , date1904Out . Minute ( ) )
assert . EqualValues ( t , sec , date1904Out . Second ( ) )
}
}
}
}
func TestTimeFromExcelTime_1904 ( t * testing . T ) {
_ , _ = shiftJulianToNoon ( 1 , - 0.6 )
timeFromExcelTime ( 61 , true )
timeFromExcelTime ( 62 , true )
julianDays , julianFraction := shiftJulianToNoon ( 1 , - 0.6 )
assert . Equal ( t , julianDays , 0.0 )
assert . Equal ( t , julianFraction , 0.9 )
julianDays , julianFraction = shiftJulianToNoon ( 1 , 0.1 )
assert . Equal ( t , julianDays , 1.0 )
assert . Equal ( t , julianFraction , 0.6 )
assert . Equal ( t , timeFromExcelTime ( 61 , true ) , time . Date ( 1904 , time . March , 2 , 0 , 0 , 0 , 0 , time . UTC ) )
assert . Equal ( t , timeFromExcelTime ( 62 , true ) , time . Date ( 1904 , time . March , 3 , 0 , 0 , 0 , 0 , time . UTC ) )
}
func TestExcelDateToTime ( t * testing . T ) {