21#include <datefunc.hrc>
23#include <com/sun/star/util/Date.hpp>
27#include <rtl/ustrbuf.hxx>
37constexpr OUStringLiteral
MY_SERVICE =
u"com.sun.star.sheet.addin.DateFunctions";
38constexpr OUStringLiteral
MY_IMPLNAME =
u"com.sun.star.sheet.addin.DateFunctionsImpl";
45#define FUNCDATA( FuncName, ParamCount, Category, Double, IntPar ) \
46 { "get" #FuncName, DATE_FUNCNAME_##FuncName, DATE_FUNCDESC_##FuncName, DATE_DEFFUNCNAME_##FuncName, ParamCount, Category, Double, IntPar }
63 aIntName( OUString::createFromAscii( rBaseData.pIntName ) ),
64 pUINameID( rBaseData.pUINameID ),
65 pDescrID( rBaseData.pDescrID ),
66 nParamCount( rBaseData.nParamCount ),
67 eCat( rBaseData.eCat ),
68 bDouble( rBaseData.bDouble ),
69 bWithOpt( rBaseData.bWithOpt )
90extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
92 css::uno::XComponentContext* , css::uno::Sequence<css::uno::Any>
const&)
103static const char*
pLang[] = {
"de",
"en" };
104static const char*
pCoun[] = {
"DE",
"US" };
142 return ScaResId(pResId[nStrIndex - 1]);
195 aRet =
ScaResId(fDataIt->GetUINameID());
196 if( fDataIt->IsDouble() )
201 aRet =
"UNKNOWNFUNC_" + aProgrammaticName;
220 const OUString& aProgrammaticName, sal_Int32 nArgument )
226 if( fDataIt !=
pFuncDataList->end() && (nArgument <= 0xFFFF) )
228 sal_uInt16 nStr = fDataIt->GetStrIndex(
static_cast< sal_uInt16
>( nArgument ) );
239 const OUString& aProgrammaticName, sal_Int32 nArgument )
245 if( fDataIt !=
pFuncDataList->end() && (nArgument <= 0xFFFF) )
247 sal_uInt16 nStr = fDataIt->GetStrIndex(
static_cast< sal_uInt16
>( nArgument ) );
251 aRet =
"for internal use only";
258 const OUString& aProgrammaticName )
266 switch( fDataIt->GetCategory() )
283 const OUString& aProgrammaticName )
290 const OUString& aProgrammaticName )
295 return uno::Sequence< sheet::LocalizedName >( 0 );
297 const std::vector<OUString>& rStrList = fDataIt->GetCompNameList();
298 sal_uInt32
nCount = rStrList.size();
300 uno::Sequence< sheet::LocalizedName > aRet(
nCount );
301 sheet::LocalizedName* pArray = aRet.getArray();
314 return ((((nYear % 4) == 0) && ((nYear % 100) != 0)) || ((nYear % 400) == 0));
317sal_uInt16
DaysInMonth( sal_uInt16 nMonth, sal_uInt16 nYear )
319 static const sal_uInt16 aDaysInMonth[12] = { 31, 28, 31, 30, 31, 30,
320 31, 31, 30, 31, 30, 31 };
323 return aDaysInMonth[nMonth-1];
327 return aDaysInMonth[nMonth-1] + 1;
329 return aDaysInMonth[nMonth-1];
342sal_Int32
DateToDays( sal_uInt16 nDay, sal_uInt16 nMonth, sal_uInt16 nYear )
344 sal_Int32 nDays = (
static_cast<sal_Int32
>(nYear)-1) * 365;
345 nDays += ((nYear-1) / 4) - ((nYear-1) / 100) + ((nYear-1) / 400);
347 for( sal_uInt16 i = 1;
i < nMonth;
i++ )
366 sal_uInt16& rDay, sal_uInt16& rMonth, sal_uInt16& rYear )
369 throw lang::IllegalArgumentException();
378 rYear =
static_cast<sal_uInt16
>((nTempDays / 365) - i);
379 nTempDays -= (
static_cast<sal_Int32
>(rYear) -1) * 365;
380 nTempDays -= (( rYear -1) / 4) - (( rYear -1) / 100) + ((rYear -1) / 400);
389 if ( nTempDays > 365 )
391 if ( (nTempDays != 366) || !
IsLeapYear( rYear ) )
407 rDay =
static_cast<sal_uInt16
>(nTempDays);
419sal_Int32
GetNullDate(
const uno::Reference< beans::XPropertySet >& xOptions )
425 uno::Any aAny = xOptions->getPropertyValue(
"NullDate" );
427 if ( aAny >>= aDate )
428 return DateToDays( aDate.Day, aDate.Month, aDate.Year );
430 catch (uno::Exception&)
436 throw uno::RuntimeException();
466 const uno::Reference< beans::XPropertySet >& xOptions,
467 sal_Int32 nStartDate, sal_Int32 nEndDate,
472 return ( nEndDate - nStartDate ) / 7;
474 else if ( nMode == 1 )
477 sal_Int32 nDays1 = nStartDate + nNullDate - 1;
478 sal_Int32 nDays2 = nEndDate + nNullDate - 1;
480 return ( std::floor( nDays2 / 7.0 ) - std::floor( nDays1 / 7.0 ) );
483 throw lang::IllegalArgumentException();
497 const uno::Reference< beans::XPropertySet >& xOptions,
498 sal_Int32 nStartDate, sal_Int32 nEndDate,
501 if (nMode != 0 && nMode != 1)
502 throw lang::IllegalArgumentException();
506 sal_Int32 nDays1 = nStartDate + nNullDate;
507 sal_Int32 nDays2 = nEndDate + nNullDate;
509 sal_uInt16 nDay1,nMonth1,nYear1;
510 sal_uInt16 nDay2,nMonth2,nYear2;
514 sal_Int32 nRet = nMonth2 - nMonth1 + (nYear2 - nYear1) * 12;
515 if ( nMode == 1 || nDays1 == nDays2 )
return nRet;
517 if ( nDays1 < nDays2 )
545 const uno::Reference< beans::XPropertySet >& xOptions,
546 sal_Int32 nStartDate, sal_Int32 nEndDate,
549 if (nMode != 0 && nMode != 1)
550 throw lang::IllegalArgumentException();
553 return getDiffMonths( xOptions, nStartDate, nEndDate, nMode ) / 12;
557 sal_Int32 nDays1 = nStartDate + nNullDate;
558 sal_Int32 nDays2 = nEndDate + nNullDate;
560 sal_uInt16 nDay1,nMonth1,nYear1;
561 sal_uInt16 nDay2,nMonth2,nYear2;
565 return nYear2 - nYear1;
572 const uno::Reference< beans::XPropertySet >& xOptions,
576 sal_Int32 nDays = nDate + nNullDate;
578 sal_uInt16 nDay, nMonth, nYear;
581 return static_cast<sal_Int32
>(
IsLeapYear(nYear));
588 const uno::Reference<beans::XPropertySet>& xOptions,
592 sal_Int32 nDays = nDate + nNullDate;
594 sal_uInt16 nDay, nMonth, nYear;
604 const uno::Reference< beans::XPropertySet >& xOptions,
608 sal_Int32 nDays = nDate + nNullDate;
610 sal_uInt16 nDay, nMonth, nYear;
632 const uno::Reference< beans::XPropertySet >& xOptions,
636 sal_Int32 nDays = nDate + nNullDate;
638 sal_uInt16 nDay, nMonth, nYear;
641 sal_Int32 nJan1WeekDay = (
DateToDays(1,1,nYear) - 1) % 7;
644 if ( nJan1WeekDay == 3 )
646 else if ( nJan1WeekDay == 2 )
662 OUStringBuffer
aBuffer( aSrcString );
666 if( (cChar >=
'a') && (cChar <=
'z'))
672 else if( (cChar >=
'A') && (cChar <=
'Z') )
680 return aBuffer.makeStringAndClear();
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
virtual void SAL_CALL setLocale(const css::lang::Locale &eLocale) override
std::unique_ptr< ScaFuncDataList > pFuncDataList
OUString GetFuncDescrStr(const TranslateId *pResId, sal_uInt16 nStrIndex)
const css::lang::Locale & GetLocale(sal_uInt32 nIndex)
virtual sal_Int32 SAL_CALL getDaysInMonth(const css::uno::Reference< css::beans::XPropertySet > &xOptions, sal_Int32 nDate) override
Get the Number of Days in the month for a date.
virtual sal_Int32 SAL_CALL getDiffYears(const css::uno::Reference< css::beans::XPropertySet > &xOptions, sal_Int32 nEndDate, sal_Int32 nStartDate, sal_Int32 nMode) override
Get Year difference between 2 dates.
virtual sal_Int32 SAL_CALL getWeeksInYear(const css::uno::Reference< css::beans::XPropertySet > &xOptions, sal_Int32 nDate) override
Get number of weeks in the year for a date.
virtual OUString SAL_CALL getFunctionDescription(const OUString &aProgrammaticName) override
virtual css::uno::Sequence< css::sheet::LocalizedName > SAL_CALL getCompatibilityNames(const OUString &aProgrammaticName) override
virtual sal_Int32 SAL_CALL getDiffMonths(const css::uno::Reference< css::beans::XPropertySet > &xOptions, sal_Int32 nEndDate, sal_Int32 nStartDate, sal_Int32 nMode) override
Get month difference between 2 dates =Month(start, end, mode) Function for StarCalc.
virtual OUString SAL_CALL getProgrammaticFuntionName(const OUString &aDisplayName) override
css::lang::Locale aFuncLoc
virtual sal_Int32 SAL_CALL getIsLeapYear(const css::uno::Reference< css::beans::XPropertySet > &xOptions, sal_Int32 nDate) override
Check if a Date is in a leap year in the Gregorian calendar.
virtual sal_Int32 SAL_CALL getDiffWeeks(const css::uno::Reference< css::beans::XPropertySet > &xOptions, sal_Int32 nEndDate, sal_Int32 nStartDate, sal_Int32 nMode) override
Get week difference between 2 dates.
virtual OUString SAL_CALL getDisplayArgumentName(const OUString &aProgrammaticName, sal_Int32 nArgument) override
virtual OUString SAL_CALL getDisplayCategoryName(const OUString &aProgrammaticName) override
virtual OUString SAL_CALL getServiceName() override
virtual css::lang::Locale SAL_CALL getLocale() override
virtual OUString SAL_CALL getArgumentDescription(const OUString &aProgrammaticName, sal_Int32 nArgument) override
virtual OUString SAL_CALL getRot13(const OUString &aSrcText) override
Encrypt or decrypt a string using ROT13 algorithm.
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
std::unique_ptr< css::lang::Locale[] > pDefLocales
OUString ScaResId(TranslateId aId)
virtual OUString SAL_CALL getDisplayFunctionName(const OUString &aProgrammaticName) override
virtual OUString SAL_CALL getImplementationName() override
virtual OUString SAL_CALL getProgrammaticCategoryName(const OUString &aProgrammaticName) override
virtual sal_Int32 SAL_CALL getDaysInYear(const css::uno::Reference< css::beans::XPropertySet > &xOptions, sal_Int32 nDate) override
Get number of days in the year of a date specified.
ScaFuncData(const ScaFuncDataBase &rBaseData)
std::vector< OUString > aCompList
sal_uInt16 GetStrIndex(sal_uInt16 nParam) const
const ScaFuncDataBase pFuncDataArr[]
static void InitScaFuncDataList(ScaFuncDataList &rList)
static const char * pCoun[]
const sal_uInt32 nNumOfLoc
#define FUNCDATA(FuncName, ParamCount, Category, Double, IntPar)
constexpr OUStringLiteral MY_IMPLNAME
static const char * pLang[]
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * scaddins_ScaDateAddIn_get_implementation(css::uno::XComponentContext *, css::uno::Sequence< css::uno::Any > const &)
constexpr OUStringLiteral ADDIN_SERVICE
constexpr OUStringLiteral MY_SERVICE
std::vector< ScaFuncData > ScaFuncDataList
#define SAL_N_ELEMENTS(arr)
std::locale Create(std::string_view aPrefixName, const LanguageTag &rLocale)
OUString get(TranslateId sContextAndId, const std::locale &loc)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
const char ** pCompListID
std::unique_ptr< char[]> aBuffer