/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
sal_uInt8 ScDPUtil::getDuplicateIndex(const OUString& rName)
{ // Count all trailing '*'s.
sal_Int32 n = rName.getLength(); if (!n) return 0;
sal_uInt8 nDupCount = 0; const sal_Unicode* p = rName.getStr(); const sal_Unicode* pStart = p;
p += n-1; // Set it to the last char. for (; p != pStart; --p, ++nDupCount)
{ if (*p != '*') break;
}
switch ( nDatePart )
{ case sheet::DataPilotFieldGroupBy::YEARS: return OUString::number(nValue); case sheet::DataPilotFieldGroupBy::QUARTERS: return ScGlobal::getLocaleData().getQuarterAbbreviation(sal_Int16(nValue-1)); // nValue is 1-based case css::sheet::DataPilotFieldGroupBy::MONTHS: return ScGlobal::GetCalendar().getDisplayName(
i18n::CalendarDisplayIndex::MONTH, sal_Int16(nValue-1), 0); // 0-based, get short name case sheet::DataPilotFieldGroupBy::DAYS:
{
Date aDate(1, 1, SC_DP_LEAPYEAR);
aDate.AddDays(nValue - 1); // nValue is 1-based
tools::Long nDays = aDate - pFormatter->GetNullDate();
if (rtl::math::approxEqual(fGroupStart, rInfo.mfEnd) &&
!rtl::math::approxEqual(fGroupStart, rInfo.mfStart))
{ if (!rInfo.mbDateValues)
{ // A group that would consist only of the end value is not // created, instead the value is included in the last group // before. So the previous group is used if the calculated group // start value is the selected end value.
double fStep = rInfo.mfStep; double fEndValue = fStartValue + fStep; if (rInfo.mbIntegerOnly && (rInfo.mbDateValues || !rtl::math::approxEqual(fEndValue, rInfo.mfEnd)))
{ // The second number of the group label is // (first number + size - 1) if there are only integer numbers, // (first number + size) if any non-integer numbers are involved. // Exception: The last group (containing the end value) is always // shown as including the end value (but not for dates).
fEndValue -= 1.0;
}
if ( fEndValue > rInfo.mfEnd && !rInfo.mbAutoEnd )
{ // limit the last group to the end value
if ( rtl::math::approxEqual( fGroupStart, rInfo.mfEnd ) &&
!rtl::math::approxEqual( fGroupStart, rInfo.mfStart ) )
{ if (rInfo.mbDateValues)
{ // For date values, the end value is instead treated as above the limit // if it would be a group of its own. return lcl_GetSpecialNumGroupName( rInfo.mfEnd, false, cDecSep, rInfo.mbDateValues, pFormatter );
}
}
sal_Int32 ScDPUtil::getDatePartValue( double fValue, const ScDPNumGroupInfo* pInfo, sal_Int32 nDatePart, const SvNumberFormatter* pFormatter)
{ // Start and end are inclusive // (End date without a time value is included, with a time value it's not)
if (pInfo)
{ if (fValue < pInfo->mfStart && !rtl::math::approxEqual(fValue, pInfo->mfStart)) return ScDPItemData::DateFirst; if (fValue > pInfo->mfEnd && !rtl::math::approxEqual(fValue, pInfo->mfEnd)) return ScDPItemData::DateLast;
}
sal_Int32 nResult = 0;
if (nDatePart == sheet::DataPilotFieldGroupBy::HOURS ||
nDatePart == sheet::DataPilotFieldGroupBy::MINUTES ||
nDatePart == sheet::DataPilotFieldGroupBy::SECONDS)
{ // handle time // (do as in the cell functions, ScInterpreter::ScGetHour() etc.)
switch (nDatePart)
{ case sheet::DataPilotFieldGroupBy::HOURS:
nResult = nHour; break; case sheet::DataPilotFieldGroupBy::MINUTES:
nResult = nMinute; break; case sheet::DataPilotFieldGroupBy::SECONDS:
nResult = nSecond; break;
}
} else
{
Date aDate = pFormatter->GetNullDate();
aDate.AddDays(::rtl::math::approxFloor(fValue));
switch ( nDatePart )
{ case css::sheet::DataPilotFieldGroupBy::YEARS:
nResult = aDate.GetYear(); break; case css::sheet::DataPilotFieldGroupBy::QUARTERS:
nResult = 1 + (aDate.GetMonth() - 1) / 3; // 1..4 break; case css::sheet::DataPilotFieldGroupBy::MONTHS:
nResult = aDate.GetMonth(); // 1..12 break; case css::sheet::DataPilotFieldGroupBy::DAYS:
{
Date aYearStart(1, 1, aDate.GetYear());
nResult = (aDate - aYearStart) + 1; // Jan 01 has value 1 if (nResult >= 60 && !aDate.IsLeapYear())
{ // days are counted from 1 to 366 - if not from a leap year, adjust
++nResult;
}
} break; default:
OSL_FAIL("invalid date part");
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.