--- a/svl/source/numbers/zformat.cxx +++ b/svl/source/numbers/zformat.cxx @@ -18,6 +18,7 @@ */ #include +#include #include #include @@ -3727,6 +3728,29 @@ rCal.getUniqueID() == GREGORIAN && !lcl_hasEra( rNumFor ); } +// Tabmorph: a disposable worker processes exactly one top-level source file. +// The trusted wrapper enables this only for a preflight-verified XLSX package. +// Values/formulas stay numeric; the Excel fictitious leap day is display data. +struct TabmorphExcelDateDisplay +{ + int dayShift = 0; + int dayOverride = -1; +}; + +static TabmorphExcelDateDisplay lcl_tabmorphExcelDateDisplay(double serial, const Date& nullDate) +{ + const char* mode = std::getenv("TABMORPH_EXCEL_1900"); + if (!mode || mode[0] != '1' || mode[1] != '\0' || nullDate != Date(30, 12, 1899) + || !(serial >= 0.0 && serial < 61.0)) + return {}; + const auto day = static_cast(std::floor(serial)); + if (day == 0) + return {2, 0}; // Excel January 0, with January/year fields from January 1. + if (day == 60) + return {0, 29}; // Keep February/year/weekday; override the fictitious day. + return {1, -1}; +} + /* XXX: if needed this could be stripped from rEpochStart and diff adding and * moved to tools' DateTime to be reused elsewhere. */ static bool lcl_getValidDate( const DateTime& rNullDate, const DateTime& rEpochStart, double& fNumber ) @@ -3755,6 +3779,8 @@ using namespace ::com::sun::star::i18n; bool bRes = false; + const auto excelDate = lcl_tabmorphExcelDateDisplay(fNumber, rScan.GetNullDate()); + fNumber += excelDate.dayShift; CalendarWrapper& rCal = *rCurrentLang.GetCalendar(); if (!lcl_getValidDate( DateTime( rScan.GetNullDate() ), rCal.getEpochStart(), fNumber)) { @@ -3762,6 +3788,25 @@ return false; } rCal.setLocalDateTime( fNumber ); + + // Excel's weekday convention before March 1900 remains one day behind the + // real Gregorian date. Use its original serial for names, not the shifted day. + const auto getDateDisplay = [&](sal_Int32 code, sal_Int16 mode) -> OUString { + if (excelDate.dayOverride >= 0 && + (code == CalendarDisplayCode::SHORT_DAY || code == CalendarDisplayCode::LONG_DAY)) + return ImpIntToString(rNatNum, nIx, excelDate.dayOverride, + code == CalendarDisplayCode::LONG_DAY ? 2 : 1); + if (excelDate.dayShift && + (code == CalendarDisplayCode::SHORT_DAY_NAME || code == CalendarDisplayCode::LONG_DAY_NAME)) + { + rCal.setLocalDateTime(fNumber - excelDate.dayShift); + OUString value = rCal.getDisplayString(code, mode); + rCal.setLocalDateTime(fNumber); + return value; + } + return rCal.getDisplayString(code, mode); + }; + int nUseMonthCase = 0; // Not decided yet OUString aOrgCalendar; // empty => not changed yet @@ -3830,7 +3875,7 @@ sBuff.append(rInfo.sStrArray[i]); break; case NF_KEY_M: // M - aStr = rCal.getDisplayString( CalendarDisplayCode::SHORT_MONTH, nNatNum ); + aStr = getDateDisplay( CalendarDisplayCode::SHORT_MONTH, nNatNum ); // NatNum12: support variants of preposition, suffixation or article // for example, Catalan "de març", but "d'abril" etc. if ( bUseSpellout ) @@ -3840,7 +3885,7 @@ sBuff.append(aStr); break; case NF_KEY_MM: // MM - sBuff.append(rCal.getDisplayString( CalendarDisplayCode::LONG_MONTH, nNatNum )); + sBuff.append(getDateDisplay( CalendarDisplayCode::LONG_MONTH, nNatNum )); break; case NF_KEY_MMM: // MMM case NF_KEY_MMMM: // MMMM @@ -3851,7 +3896,7 @@ // PartitiveMonths or GenitiveMonths defined in the locale data, // see description of ImpUseMonthCase(), and locale data in // i18npool/source/localedata/data/ and libnumbertext - aStr = rCal.getDisplayString( ImpUseMonthCase( nUseMonthCase, NumFor[nIx], + aStr = getDateDisplay( ImpUseMonthCase( nUseMonthCase, NumFor[nIx], static_cast(rInfo.nTypeArray[i])), nNatNum); if ( bUseSpellout ) @@ -3861,13 +3906,13 @@ sBuff.append(aStr); break; case NF_KEY_Q: // Q - sBuff.append(rCal.getDisplayString( CalendarDisplayCode::SHORT_QUARTER, nNatNum )); + sBuff.append(getDateDisplay( CalendarDisplayCode::SHORT_QUARTER, nNatNum )); break; case NF_KEY_QQ: // QQ - sBuff.append(rCal.getDisplayString( CalendarDisplayCode::LONG_QUARTER, nNatNum )); + sBuff.append(getDateDisplay( CalendarDisplayCode::LONG_QUARTER, nNatNum )); break; case NF_KEY_D: // D - aStr = rCal.getDisplayString( CalendarDisplayCode::SHORT_DAY, nNatNum ); + aStr = getDateDisplay( CalendarDisplayCode::SHORT_DAY, nNatNum ); // NatNum12: support variants of preposition, suffixation or article if ( bUseSpellout ) { @@ -3876,14 +3921,14 @@ sBuff.append(aStr); break; case NF_KEY_DD: // DD - sBuff.append(rCal.getDisplayString( CalendarDisplayCode::LONG_DAY, nNatNum )); + sBuff.append(getDateDisplay( CalendarDisplayCode::LONG_DAY, nNatNum )); break; case NF_KEY_DDD: // DDD if ( bOtherCalendar ) { SwitchToGregorianCalendar( aOrgCalendar, fOrgDateTime, *rCurrentLang.GetCalendar() ); } - aStr = rCal.getDisplayString( CalendarDisplayCode::SHORT_DAY_NAME, nNatNum ); + aStr = getDateDisplay( CalendarDisplayCode::SHORT_DAY_NAME, nNatNum ); // NatNum12: support at least capitalize, upper, lower, title if ( bUseSpellout ) { @@ -3900,7 +3945,7 @@ { SwitchToGregorianCalendar( aOrgCalendar, fOrgDateTime, *rCurrentLang.GetCalendar() ); } - aStr = rCal.getDisplayString( CalendarDisplayCode::LONG_DAY_NAME, nNatNum ); + aStr = getDateDisplay( CalendarDisplayCode::LONG_DAY_NAME, nNatNum ); // NatNum12: support variants of preposition, suffixation or article if ( bUseSpellout ) { @@ -3922,7 +3967,7 @@ { sBuff.append('-'); } - sBuff.append(rCal.getDisplayString( CalendarDisplayCode::SHORT_YEAR, nNatNum )); + sBuff.append(getDateDisplay( CalendarDisplayCode::SHORT_YEAR, nNatNum )); if ( bOtherCalendar ) { SwitchToOtherCalendar( aOrgCalendar, fOrgDateTime, *rCurrentLang.GetCalendar() ); @@ -3938,7 +3983,7 @@ { sBuff.append('-'); } - aStr = rCal.getDisplayString( CalendarDisplayCode::LONG_YEAR, nNatNum ); + aStr = getDateDisplay( CalendarDisplayCode::LONG_YEAR, nNatNum ); if (aStr.getLength() < 4 && !lcl_hasEra(NumFor[nIx])) { using namespace comphelper::string; @@ -3963,15 +4008,15 @@ } break; case NF_KEY_EC: // E - sBuff.append(rCal.getDisplayString( CalendarDisplayCode::SHORT_YEAR, nNatNum )); + sBuff.append(getDateDisplay( CalendarDisplayCode::SHORT_YEAR, nNatNum )); break; case NF_KEY_EEC: // EE case NF_KEY_R: // R - sBuff.append(rCal.getDisplayString( CalendarDisplayCode::LONG_YEAR, nNatNum )); + sBuff.append(getDateDisplay( CalendarDisplayCode::LONG_YEAR, nNatNum )); break; case NF_KEY_NN: // NN case NF_KEY_AAA: // AAA - aStr = rCal.getDisplayString( CalendarDisplayCode::SHORT_DAY_NAME, nNatNum ); + aStr = getDateDisplay( CalendarDisplayCode::SHORT_DAY_NAME, nNatNum ); // NatNum12: support at least capitalize, upper, lower, title if ( bUseSpellout ) { @@ -3981,7 +4026,7 @@ break; case NF_KEY_NNN: // NNN case NF_KEY_AAAA: // AAAA - aStr = rCal.getDisplayString( CalendarDisplayCode::LONG_DAY_NAME, nNatNum ); + aStr = getDateDisplay( CalendarDisplayCode::LONG_DAY_NAME, nNatNum ); // NatNum12: support variants of preposition, suffixation or article if ( bUseSpellout ) { @@ -3990,7 +4035,7 @@ sBuff.append(aStr); break; case NF_KEY_NNNN: // NNNN - sBuff.append(rCal.getDisplayString( CalendarDisplayCode::LONG_DAY_NAME, nNatNum )); + sBuff.append(getDateDisplay( CalendarDisplayCode::LONG_DAY_NAME, nNatNum )); sBuff.append(rLoc().getLongDateDayOfWeekSep()); break; case NF_KEY_WW : // WW @@ -4001,13 +4046,13 @@ ImpAppendEraG(sBuff, rCal, nNatNum ); break; case NF_KEY_GG: // GG - sBuff.append(rCal.getDisplayString( CalendarDisplayCode::SHORT_ERA, nNatNum )); + sBuff.append(getDateDisplay( CalendarDisplayCode::SHORT_ERA, nNatNum )); break; case NF_KEY_GGG: // GGG - sBuff.append(rCal.getDisplayString( CalendarDisplayCode::LONG_ERA, nNatNum )); + sBuff.append(getDateDisplay( CalendarDisplayCode::LONG_ERA, nNatNum )); break; case NF_KEY_RR: // RR => GGGEE - sBuff.append(rCal.getDisplayString( CalendarDisplayCode::LONG_YEAR_AND_ERA, nNatNum )); + sBuff.append(getDateDisplay( CalendarDisplayCode::LONG_YEAR_AND_ERA, nNatNum )); break; } } @@ -4059,7 +4104,28 @@ fTime -= 86400.0; fNumber = floor( fNumber + 0.5) + fTime; } + const auto excelDate = lcl_tabmorphExcelDateDisplay(fNumber - DateTime::Sub(DateTime(rScan.GetNullDate()), rCal.getEpochStart()), rScan.GetNullDate()); + fNumber += excelDate.dayShift; rCal.setLocalDateTime( fNumber ); + + // Excel's weekday convention before March 1900 remains one day behind the + // real Gregorian date. Use its original serial for names, not the shifted day. + const auto getDateDisplay = [&](sal_Int32 code, sal_Int16 mode) -> OUString { + if (excelDate.dayOverride >= 0 && + (code == CalendarDisplayCode::SHORT_DAY || code == CalendarDisplayCode::LONG_DAY)) + return ImpIntToString(rNatNum, nIx, excelDate.dayOverride, + code == CalendarDisplayCode::LONG_DAY ? 2 : 1); + if (excelDate.dayShift && + (code == CalendarDisplayCode::SHORT_DAY_NAME || code == CalendarDisplayCode::LONG_DAY_NAME)) + { + rCal.setLocalDateTime(fNumber - excelDate.dayShift); + OUString value = rCal.getDisplayString(code, mode); + rCal.setLocalDateTime(fNumber); + return value; + } + return rCal.getDisplayString(code, mode); + }; + int nUseMonthCase = 0; // Not decided yet OUString aOrgCalendar; // empty => not changed yet @@ -4228,46 +4294,46 @@ sBuff.append(ImpIntToString(rNatNum, nIx, nSec, 2 )); break; case NF_KEY_M: // M - sBuff.append(rCal.getDisplayString( + sBuff.append(getDateDisplay( CalendarDisplayCode::SHORT_MONTH, nNatNum )); break; case NF_KEY_MM: // MM - sBuff.append(rCal.getDisplayString( + sBuff.append(getDateDisplay( CalendarDisplayCode::LONG_MONTH, nNatNum )); break; case NF_KEY_MMM: // MMM - sBuff.append(rCal.getDisplayString( ImpUseMonthCase( nUseMonthCase, NumFor[nIx], + sBuff.append(getDateDisplay( ImpUseMonthCase( nUseMonthCase, NumFor[nIx], static_cast(rInfo.nTypeArray[i])), nNatNum)); break; case NF_KEY_MMMM: // MMMM - sBuff.append(rCal.getDisplayString( ImpUseMonthCase( nUseMonthCase, NumFor[nIx], + sBuff.append(getDateDisplay( ImpUseMonthCase( nUseMonthCase, NumFor[nIx], static_cast(rInfo.nTypeArray[i])), nNatNum)); break; case NF_KEY_MMMMM: // MMMMM - sBuff.append(rCal.getDisplayString( ImpUseMonthCase( nUseMonthCase, NumFor[nIx], + sBuff.append(getDateDisplay( ImpUseMonthCase( nUseMonthCase, NumFor[nIx], static_cast(rInfo.nTypeArray[i])), nNatNum)); break; case NF_KEY_Q: // Q - sBuff.append(rCal.getDisplayString( CalendarDisplayCode::SHORT_QUARTER, nNatNum )); + sBuff.append(getDateDisplay( CalendarDisplayCode::SHORT_QUARTER, nNatNum )); break; case NF_KEY_QQ: // QQ - sBuff.append(rCal.getDisplayString( CalendarDisplayCode::LONG_QUARTER, nNatNum )); + sBuff.append(getDateDisplay( CalendarDisplayCode::LONG_QUARTER, nNatNum )); break; case NF_KEY_D: // D - sBuff.append(rCal.getDisplayString( CalendarDisplayCode::SHORT_DAY, nNatNum )); + sBuff.append(getDateDisplay( CalendarDisplayCode::SHORT_DAY, nNatNum )); break; case NF_KEY_DD: // DD - sBuff.append(rCal.getDisplayString( CalendarDisplayCode::LONG_DAY, nNatNum )); + sBuff.append(getDateDisplay( CalendarDisplayCode::LONG_DAY, nNatNum )); break; case NF_KEY_DDD: // DDD if ( bOtherCalendar ) { SwitchToGregorianCalendar( aOrgCalendar, fOrgDateTime, *rCurrentLang.GetCalendar() ); } - sBuff.append(rCal.getDisplayString( CalendarDisplayCode::SHORT_DAY_NAME, nNatNum )); + sBuff.append(getDateDisplay( CalendarDisplayCode::SHORT_DAY_NAME, nNatNum )); if ( bOtherCalendar ) { SwitchToOtherCalendar( aOrgCalendar, fOrgDateTime, *rCurrentLang.GetCalendar() ); @@ -4278,7 +4344,7 @@ { SwitchToGregorianCalendar( aOrgCalendar, fOrgDateTime, *rCurrentLang.GetCalendar() ); } - sBuff.append(rCal.getDisplayString( CalendarDisplayCode::LONG_DAY_NAME, nNatNum )); + sBuff.append(getDateDisplay( CalendarDisplayCode::LONG_DAY_NAME, nNatNum )); if ( bOtherCalendar ) { SwitchToOtherCalendar( aOrgCalendar, fOrgDateTime, *rCurrentLang.GetCalendar() ); @@ -4294,7 +4360,7 @@ { sBuff.append('-'); } - sBuff.append(rCal.getDisplayString( CalendarDisplayCode::SHORT_YEAR, nNatNum )); + sBuff.append(getDateDisplay( CalendarDisplayCode::SHORT_YEAR, nNatNum )); if ( bOtherCalendar ) { SwitchToOtherCalendar( aOrgCalendar, fOrgDateTime, *rCurrentLang.GetCalendar() ); @@ -4310,7 +4376,7 @@ { sBuff.append('-'); } - aYear = rCal.getDisplayString( CalendarDisplayCode::LONG_YEAR, nNatNum ); + aYear = getDateDisplay( CalendarDisplayCode::LONG_YEAR, nNatNum ); if (aYear.getLength() < 4 && !lcl_hasEra(NumFor[nIx])) { using namespace comphelper::string; @@ -4333,22 +4399,22 @@ } break; case NF_KEY_EC: // E - sBuff.append(rCal.getDisplayString( CalendarDisplayCode::SHORT_YEAR, nNatNum )); + sBuff.append(getDateDisplay( CalendarDisplayCode::SHORT_YEAR, nNatNum )); break; case NF_KEY_EEC: // EE case NF_KEY_R: // R - sBuff.append(rCal.getDisplayString( CalendarDisplayCode::LONG_YEAR, nNatNum )); + sBuff.append(getDateDisplay( CalendarDisplayCode::LONG_YEAR, nNatNum )); break; case NF_KEY_NN: // NN case NF_KEY_AAA: // AAA - sBuff.append(rCal.getDisplayString( CalendarDisplayCode::SHORT_DAY_NAME, nNatNum )); + sBuff.append(getDateDisplay( CalendarDisplayCode::SHORT_DAY_NAME, nNatNum )); break; case NF_KEY_NNN: // NNN case NF_KEY_AAAA: // AAAA - sBuff.append(rCal.getDisplayString( CalendarDisplayCode::LONG_DAY_NAME, nNatNum )); + sBuff.append(getDateDisplay( CalendarDisplayCode::LONG_DAY_NAME, nNatNum )); break; case NF_KEY_NNNN: // NNNN - sBuff.append(rCal.getDisplayString( CalendarDisplayCode::LONG_DAY_NAME, nNatNum )); + sBuff.append(getDateDisplay( CalendarDisplayCode::LONG_DAY_NAME, nNatNum )); sBuff.append(rLoc().getLongDateDayOfWeekSep()); break; case NF_KEY_WW : // WW @@ -4358,13 +4424,13 @@ ImpAppendEraG( sBuff, rCal, nNatNum ); break; case NF_KEY_GG: // GG - sBuff.append(rCal.getDisplayString( CalendarDisplayCode::SHORT_ERA, nNatNum )); + sBuff.append(getDateDisplay( CalendarDisplayCode::SHORT_ERA, nNatNum )); break; case NF_KEY_GGG: // GGG - sBuff.append(rCal.getDisplayString( CalendarDisplayCode::LONG_ERA, nNatNum )); + sBuff.append(getDateDisplay( CalendarDisplayCode::LONG_ERA, nNatNum )); break; case NF_KEY_RR: // RR => GGGEE - sBuff.append(rCal.getDisplayString( CalendarDisplayCode::LONG_YEAR_AND_ERA, nNatNum )); + sBuff.append(getDateDisplay( CalendarDisplayCode::LONG_YEAR_AND_ERA, nNatNum )); break; } } --- a/sc/source/core/tool/interpr2.cxx +++ b/sc/source/core/tool/interpr2.cxx @@ -18,6 +18,7 @@ */ #include +#include #include #include @@ -59,10 +60,33 @@ // Date and Time +static bool tabmorphExcelSource() +{ + const char* mode = std::getenv("TABMORPH_EXCEL_1900"); + return mode && mode[0] == '1' && mode[1] == '\0'; +} + +static bool tabmorphExcel1900(const Date& nullDate) +{ + return tabmorphExcelSource() && nullDate == Date(30, 12, 1899); +} + +static sal_Int32 tabmorphExcelDateOffset(sal_Int32 serial, const Date& nullDate) +{ + if (!tabmorphExcel1900(nullDate)) + return serial; + if (serial == 0) + return 2; + return serial > 0 && serial < 60 ? serial + 1 : serial; +} + + double ScInterpreter::GetDateSerial( sal_Int16 nYear, sal_Int16 nMonth, sal_Int16 nDay, bool bStrict ) { - if ( nYear < 100 && !bStrict ) + if (tabmorphExcelSource() && !bStrict && nYear >= 0 && nYear < 1900) + nYear += 1900; + else if ( nYear < 100 && !bStrict ) nYear = mrContext.NFExpandTwoDigitYear( nYear ); // Do not use a default Date ctor here because it asks system time with a // performance penalty. @@ -86,6 +110,21 @@ nM = 12 - (-nMonth) % 12; } nD = 1; + } + if (tabmorphExcel1900(mrContext.NFGetNullDate())) + { + if (bStrict && nY == 1900 && nM == 2 && nD == 29) + return 60.0; + // DATE normalizes the first of the month, then adds day-1 in Excel's + // serial space. This includes Feb29 and overflow across that boundary. + Date first(bStrict ? nD : 1, nM, nY); + if (first.IsValidAndGregorian()) + { + double serial = static_cast(first - Date(31, 12, 1899)); + if (first >= Date(1, 3, 1900)) + serial += 1.0; + return serial + (bStrict ? 0 : nDay - 1); + } } Date aDate( nD, nM, nY); if (!bStrict) @@ -122,21 +161,27 @@ void ScInterpreter::ScGetYear() { Date aDate = mrContext.NFGetNullDate(); - aDate.AddDays( GetFloor32()); + aDate.AddDays(tabmorphExcelDateOffset(GetFloor32(), mrContext.NFGetNullDate())); PushDouble( static_cast(aDate.GetYear()) ); } void ScInterpreter::ScGetMonth() { Date aDate = mrContext.NFGetNullDate(); - aDate.AddDays( GetFloor32()); + aDate.AddDays(tabmorphExcelDateOffset(GetFloor32(), mrContext.NFGetNullDate())); PushDouble( static_cast(aDate.GetMonth()) ); } void ScInterpreter::ScGetDay() { Date aDate = mrContext.NFGetNullDate(); - if (aDate.CheckedAddDays(GetFloor32())) + const sal_Int32 serial = GetFloor32(); + if (tabmorphExcel1900(mrContext.NFGetNullDate()) && (serial == 0 || serial == 60)) + { + PushDouble(serial == 0 ? 0.0 : 29.0); + return; + } + if (aDate.CheckedAddDays(tabmorphExcelDateOffset(serial, mrContext.NFGetNullDate()))) PushDouble(static_cast(aDate.GetDay())); else { @@ -183,6 +228,8 @@ if (eType == SvNumFormatType::DATE || eType == SvNumFormatType::DATETIME) { nFuncFmtType = SvNumFormatType::DATE; + if (tabmorphExcel1900(mrContext.NFGetNullDate()) && fVal >= 2.0 && fVal < 61.0) + fVal -= 1.0; PushDouble(::rtl::math::approxFloor(fVal)); } else --- a/sc/source/filter/oox/unitconverter.cxx +++ b/sc/source/filter/oox/unitconverter.cxx @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -157,6 +158,11 @@ double UnitConverter::calcSerialFromDateTime( const util::DateTime& rDateTime ) const { sal_Int32 nDays = lclGetDays( util::Date( rDateTime.Day, rDateTime.Month, rDateTime.Year ) ) - mnNullDate; + // Keep true OOXML t=d historical dates aligned with Excel numeric cells. + const char* mode = std::getenv("TABMORPH_EXCEL_1900"); + if (mode && mode[0] == '1' && mode[1] == '\0' + && mnNullDate == lclGetDays(util::Date(30, 12, 1899)) && nDays >= 2 && nDays < 61) + --nDays; OSL_ENSURE( nDays >= 0, "UnitConverter::calcDateTimeSerial - invalid date" ); OSL_ENSURE( (rDateTime.Hours <= 23) && (rDateTime.Minutes <= 59) && (rDateTime.Seconds <= 59), "UnitConverter::calcDateTimeSerial - invalid time" ); return nDays + rDateTime.Hours / 24.0 + rDateTime.Minutes / 1440.0 + rDateTime.Seconds / 86400.0; --- a/scaddins/source/analysis/analysis.cxx +++ b/scaddins/source/analysis/analysis.cxx @@ -30,6 +30,7 @@ #include #include #include +#include #include constexpr OUString ADDIN_SERVICE = u"com.sun.star.sheet.AddIn"_ustr; @@ -38,6 +39,35 @@ using namespace ::com::sun::star; using namespace sca::analysis; + +static bool tabmorphAnalysisExcel1900(sal_Int32 nullDate) +{ + const char* mode = std::getenv("TABMORPH_EXCEL_1900"); + return mode && mode[0] == '1' && mode[1] == '\0' + && nullDate == DateToDays(30, 12, 1899); +} + +static sal_Int32 tabmorphExcelMonth(sal_Int32 serial, sal_Int32 months, bool endOfMonth) +{ + const sal_Int32 epoch = DateToDays(31, 12, 1899); + if (serial < 0 || serial > DateToDays(31, 12, 9999) - epoch + 1) + throw lang::IllegalArgumentException(); + sal_uInt16 day, month, year; + if (serial == 0) { day = 0; month = 1; year = 1900; } + else if (serial == 60) { day = 29; month = 2; year = 1900; } + else DaysToDate(epoch + serial - (serial > 60 ? 1 : 0), day, month, year); + const sal_Int64 ym = static_cast(year) * 12 + month - 1 + months; + if (ym < 1900 * 12 || ym >= 10000 * 12) + throw lang::IllegalArgumentException(); + year = static_cast(ym / 12); + month = static_cast(ym % 12 + 1); + // Excel16.88 EDATE/EOMONTH use the real Gregorian last day of February, + // even though DATE/raw serial60 can represent the fictitious Feb29. + const sal_uInt16 lastDay = DaysInMonth(month, year); + day = endOfMonth ? lastDay : std::min(day, lastDay); + return DateToDays(1, month, year) - epoch + + ((year > 1900 || month >= 3) ? 1 : 0) + day - 1; +} OUString AnalysisAddIn::GetFuncDescrStr(const TranslateId* pResId, sal_uInt16 nStrIndex) { @@ -394,6 +424,8 @@ sal_Int32 SAL_CALL AnalysisAddIn::getEdate( const uno::Reference< beans::XPropertySet >& xOpt, sal_Int32 nStartDate, sal_Int32 nMonths ) { sal_Int32 nNullDate = GetNullDate( xOpt ); + if (tabmorphAnalysisExcel1900(nNullDate)) + return tabmorphExcelMonth(nStartDate, nMonths, false); ScaDate aDate( nNullDate, nStartDate, 5 ); aDate.addMonths( nMonths ); return aDate.getDate( nNullDate ); @@ -415,6 +447,8 @@ sal_Int32 SAL_CALL AnalysisAddIn::getEomonth( const uno::Reference< beans::XPropertySet >& xOpt, sal_Int32 nDate, sal_Int32 nMonths ) { sal_Int32 nNullDate = GetNullDate( xOpt ); + if (tabmorphAnalysisExcel1900(nNullDate)) + return tabmorphExcelMonth(nDate, nMonths, true); nDate += nNullDate; sal_uInt16 nDay, nMonth, nYear; DaysToDate( nDate, nDay, nMonth, nYear );