\r
import java.io.IOException;\r
import java.nio.charset.Charset;\r
+import java.util.Calendar;\r
import java.util.Date;\r
+import java.util.GregorianCalendar;\r
\r
import junit.framework.TestCase;\r
\r
import org.apache.poi.hssf.HSSFTestDataSamples;\r
import org.apache.poi.ss.usermodel.Cell;\r
import org.apache.poi.ss.usermodel.DataFormatter;\r
+import org.apache.poi.ss.usermodel.DateUtil;\r
import org.apache.poi.ss.usermodel.Row;\r
import org.apache.poi.ss.usermodel.Sheet;\r
import org.apache.poi.ss.usermodel.Workbook;\r
}\r
}\r
}\r
+ \r
+ public void test54071Simple() {\r
+ double value1 = 41224.999988425923;\r
+ double value2 = 41224.999988368058;\r
+ \r
+ int wholeDays1 = (int)Math.floor(value1);\r
+ int millisecondsInDay1 = (int)((value1 - wholeDays1) * DateUtil.DAY_MILLISECONDS + 0.5);\r
\r
+ int wholeDays2 = (int)Math.floor(value2);\r
+ int millisecondsInDay2 = (int)((value2 - wholeDays2) * DateUtil.DAY_MILLISECONDS + 0.5);\r
+ \r
+ assertEquals(wholeDays1, wholeDays2);\r
+ // here we see that the time-value is 5 milliseconds apart, one is 86399000 and the other is 86398995, \r
+ // thus one is one second higher than the other\r
+ assertEquals("The time-values are 5 milliseconds apart", \r
+ millisecondsInDay1, millisecondsInDay2);\r
+\r
+ // when we do the calendar-stuff, there is a boolean which determines if\r
+ // the milliseconds are rounded or not, having this at "false" causes the \r
+ // second to be different here!\r
+ int startYear = 1900;\r
+ int dayAdjust = -1; // Excel thinks 2/29/1900 is a valid date, which it isn't\r
+ Calendar calendar1 = new GregorianCalendar();\r
+ calendar1.set(startYear,0, wholeDays1 + dayAdjust, 0, 0, 0);\r
+ calendar1.set(Calendar.MILLISECOND, millisecondsInDay1);\r
+ // this is the rounding part:\r
+ calendar1.add(Calendar.MILLISECOND, 500);\r
+ calendar1.clear(Calendar.MILLISECOND);\r
+\r
+ Calendar calendar2 = new GregorianCalendar();\r
+ calendar2.set(startYear,0, wholeDays2 + dayAdjust, 0, 0, 0);\r
+ calendar2.set(Calendar.MILLISECOND, millisecondsInDay2);\r
+ // this is the rounding part:\r
+ calendar2.add(Calendar.MILLISECOND, 500);\r
+ calendar2.clear(Calendar.MILLISECOND);\r
+\r
+ // now the calendars are equal\r
+ assertEquals(calendar1, calendar2);\r
+ \r
+ assertEquals(DateUtil.getJavaDate(value1, false), DateUtil.getJavaDate(value2, false));\r
+ }\r
\r
public void test57236() {\r
// Having very small numbers leads to different formatting, Excel uses the scientific notation, but POI leads to "0"\r