Skip to content

Commit

Permalink
[bug-69583] DateUtil needs to handle time only dates (issue with 1900…
Browse files Browse the repository at this point in the history
… format dates)

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1923785 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
pjfanning committed Feb 13, 2025
1 parent 8ad10c0 commit 6947653
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 68 deletions.
8 changes: 6 additions & 2 deletions poi/src/main/java/org/apache/poi/ss/usermodel/DateUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,12 @@ public static double getExcelDate(Calendar date, boolean use1904windowing) {
return internalGetExcelDate(year, dayOfYear, hour, minute, second, milliSecond, use1904windowing);
}

private static boolean isLastDay1899(final int year, final int dayOfYear) {
return year == 1899 && dayOfYear == 365;
}

private static double internalGetExcelDate(int year, int dayOfYear, int hour, int minute, int second, int milliSecond, boolean use1904windowing) {
if ((!use1904windowing && year < 1900) ||
if ((!use1904windowing && (year < 1900 && !isLastDay1899(year, dayOfYear))) ||
(use1904windowing && year < 1904))
{
return BAD_DATE;
Expand Down Expand Up @@ -866,7 +870,7 @@ private static int absoluteDay(int year, int dayOfYear, boolean use1904windowing

static int daysInPriorYears(int yr, boolean use1904windowing)
{
if ((!use1904windowing && yr < 1900) || (use1904windowing && yr < 1904)) {
if ((!use1904windowing && yr < 1899) || (use1904windowing && yr < 1904)) {
throw new IllegalArgumentException("'year' must be 1900 or greater");
}

Expand Down
Loading

0 comments on commit 6947653

Please sign in to comment.