fix some of the broken tests

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1923794 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
PJ Fanning 2025-02-13 21:40:26 +00:00
parent f61dddea12
commit 50dcbd390b
6 changed files with 15 additions and 22 deletions

View File

@ -856,31 +856,24 @@ public class DateUtil {
* @throws IllegalArgumentException if date is invalid * @throws IllegalArgumentException if date is invalid
*/ */
private static int absoluteDay(int year, int dayOfYear, boolean use1904windowing) { private static int absoluteDay(int year, int dayOfYear, boolean use1904windowing) {
return dayOfYear + daysInPriorYears(year, use1904windowing); return dayOfYear + daysInPriorYears(year, dayOfYear, use1904windowing);
} }
/** private static int daysInPriorYears(final int year, final int dayOfYear,
* Return the number of days in prior years since 1900 final boolean use1904windowing)
*
* @return days number of days in years prior to yr.
* @param yr a year (1900 < yr < 4000)
* @param use1904windowing Should 1900 or 1904 date windowing be used?
* @throws IllegalArgumentException if year is outside of range.
*/
static int daysInPriorYears(int yr, boolean use1904windowing)
{ {
if ((!use1904windowing && yr < 1899) || (use1904windowing && yr < 1904)) { if ((!use1904windowing && (year < 1900 && !isLastDay1899(year, dayOfYear)))
|| (use1904windowing && year < 1904)) {
throw new IllegalArgumentException("'year' must be 1900 or greater"); throw new IllegalArgumentException("'year' must be 1900 or greater");
} }
int yr1 = yr - 1; int yr1 = year - 1;
int leapDays = yr1 / 4 // plus julian leap days in prior years int leapDays = yr1 / 4 // plus julian leap days in prior years
- yr1 / 100 // minus prior century years - yr1 / 100 // minus prior century years
+ yr1 / 400 // plus years divisible by 400 + yr1 / 400 // plus years divisible by 400
- 460; // leap days in previous 1900 years - 460; // leap days in previous 1900 years
return 365 * (yr - (use1904windowing ? 1904 : 1900)) + leapDays; return 365 * (year - (use1904windowing ? 1904 : 1900)) + leapDays;
} }
// set HH:MM:SS fields of cal to 00:00:00:000 // set HH:MM:SS fields of cal to 00:00:00:000

View File

@ -41,7 +41,7 @@ class TestEDate {
checkValue(1, 0, 1d); checkValue(1, 0, 1d);
checkValue(0, 1, 31d); checkValue(0, 1, 31d);
checkValue(1, 1, 32d); checkValue(1, 1, 32d);
checkValue(0, 0, /* BAD_DATE! */ -1.0d); checkValue(0, 0, 0.0d);
checkValue(0, -2, /* BAD_DATE! */ -1.0d); checkValue(0, -2, /* BAD_DATE! */ -1.0d);
checkValue(0, -3, /* BAD_DATE! */ -1.0d); checkValue(0, -3, /* BAD_DATE! */ -1.0d);
checkValue(49104, 0, 49104d); checkValue(49104, 0, 49104d);
@ -112,14 +112,14 @@ class TestEDate {
@Test @Test
void testEDateBlankValueEval() { void testEDateBlankValueEval() {
NumberEval evaluate = (NumberEval) new EDate().evaluate(new ValueEval[]{BlankEval.instance, new NumberEval(0)}, null); NumberEval evaluate = (NumberEval) new EDate().evaluate(new ValueEval[]{BlankEval.instance, new NumberEval(0)}, null);
assertEquals(-1.0d, evaluate.getNumberValue(), 0); assertEquals(0.0d, evaluate.getNumberValue(), 0);
} }
@Test @Test
void testEDateBlankRefValueEval() { void testEDateBlankRefValueEval() {
EDate eDate = new EDate(); EDate eDate = new EDate();
NumberEval result = (NumberEval) eDate.evaluate(new ValueEval[]{new RefEvalImplementation(BlankEval.instance), new NumberEval(0)}, null); NumberEval result = (NumberEval) eDate.evaluate(new ValueEval[]{new RefEvalImplementation(BlankEval.instance), new NumberEval(0)}, null);
assertEquals(-1.0d, result.getNumberValue(), 0, "0 startDate triggers BAD_DATE currently, thus -1.0!"); assertEquals(0.0d, result.getNumberValue(), 0, "0 startDate triggers BAD_DATE currently, thus -1.0!");
result = (NumberEval) eDate.evaluate(new ValueEval[]{new NumberEval(1), new RefEvalImplementation(BlankEval.instance)}, null); result = (NumberEval) eDate.evaluate(new ValueEval[]{new NumberEval(1), new RefEvalImplementation(BlankEval.instance)}, null);
assertEquals(1.0d, result.getNumberValue(), 0, "Blank is handled as 0 otherwise"); assertEquals(1.0d, result.getNumberValue(), 0, "Blank is handled as 0 otherwise");

View File

@ -64,7 +64,7 @@ class TestEOMonth {
void testEOMonthBadDateValues() { void testEOMonthBadDateValues() {
checkValue(0.0, -2, BAD_DATE); checkValue(0.0, -2, BAD_DATE);
checkValue(0.0, -3, BAD_DATE); checkValue(0.0, -3, BAD_DATE);
checkValue(DATE_1900_01_31, -1, BAD_DATE); checkValue(DATE_1900_01_31, -2, BAD_DATE);
} }
private void checkValue(double startDate, int monthInc, double expectedResult) { private void checkValue(double startDate, int monthInc, double expectedResult) {

View File

@ -531,7 +531,7 @@ public abstract class BaseTestConditionalFormatting {
// Sanity check data // Sanity check data
assertEquals("Values", s.getRow(0).getCell(0).toString()); assertEquals("Values", s.getRow(0).getCell(0).toString());
assertEquals("10.0", s.getRow(2).getCell(0).toString()); assertEquals("10", s.getRow(2).getCell(0).toString());
// Check we found all the conditional formatting rules we should have // Check we found all the conditional formatting rules we should have
SheetConditionalFormatting sheetCF = s.getSheetConditionalFormatting(); SheetConditionalFormatting sheetCF = s.getSheetConditionalFormatting();

View File

@ -357,7 +357,7 @@ public abstract class BaseTestFormulaEvaluator {
eval.evaluateInCell(cell); eval.evaluateInCell(cell);
assertEquals("3.0", cell.toString()); assertEquals("3", cell.toString());
} }
} }
@ -621,7 +621,7 @@ public abstract class BaseTestFormulaEvaluator {
assertNotNull(eval.evaluateInCell(cell)); assertNotNull(eval.evaluateInCell(cell));
assertEquals("3.0", cell.toString()); assertEquals("3", cell.toString());
assertEquals(CellType.NUMERIC, cell.getCellType()); assertEquals(CellType.NUMERIC, cell.getCellType());
assertEquals(3.0, cell.getNumericCellValue(), 0.01); assertEquals(3.0, cell.getNumericCellValue(), 0.01);
} }

View File

@ -505,7 +505,7 @@ class TestDateUtil {
Date date32 = df.parse("1900-02-01"); Date date32 = df.parse("1900-02-01");
assertEquals(32.0, DateUtil.getExcelDate(date32), 0.00001); assertEquals(32.0, DateUtil.getExcelDate(date32), 0.00001);
assertEquals(32.0, DateUtil.getExcelDate(DateUtil.toLocalDateTime(date32)), 0.00001); assertEquals(32.0, DateUtil.getExcelDate(DateUtil.toLocalDateTime(date32)), 0.00001);
Date dateMinus1 = df.parse("1899-12-31"); Date dateMinus1 = df.parse("1899-12-30");
assertEquals(/* BAD_DATE! */ -1.0, DateUtil.getExcelDate(dateMinus1), 0.00001); assertEquals(/* BAD_DATE! */ -1.0, DateUtil.getExcelDate(dateMinus1), 0.00001);
assertEquals(/* BAD_DATE! */ -1.0, DateUtil.getExcelDate(DateUtil.toLocalDateTime(dateMinus1)), 0.00001); assertEquals(/* BAD_DATE! */ -1.0, DateUtil.getExcelDate(DateUtil.toLocalDateTime(dateMinus1)), 0.00001);
} }