/* -*- 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/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
OUString SAL_CALL ScaDateAddIn::getProgrammaticFuntionName( const OUString& )
{ // not used by calc // (but should be implemented for other uses of the AddIn service) return OUString();
}
/** * Convert a date to a count of days starting from 01/01/0001 * * The internal representation of a Date used in this Addin * is the number of days between 01/01/0001 and the date * this function converts a Day , Month, Year representation * to this internal Date value.
*/
for( sal_uInt16 i = 1; i < nMonth; i++ )
nDays += DaysInMonth(i,nYear);
nDays += nDay;
return nDays;
}
/** * Convert a count of days starting from 01/01/0001 to a date * * The internal representation of a Date used in this Addin * is the number of days between 01/01/0001 and the date * this function converts this internal Date value * to a Day , Month, Year representation of a Date. * * @throws lang::IllegalArgumentException
*/
/** * Get the null date used by the spreadsheet document * * The internal representation of a Date used in this Addin * is the number of days between 01/01/0001 and the date * this function returns this internal Date value for the document null date * * @throws uno::RuntimeException
*/
sal_Int32 GetNullDate( const uno::Reference< beans::XPropertySet >& xOptions )
{ if (xOptions.is())
{ try
{
uno::Any aAny = xOptions->getPropertyValue( u"NullDate"_ustr );
util::Date aDate; if ( aAny >>= aDate ) return DateToDays( aDate.Day, aDate.Month, aDate.Year );
} catch (uno::Exception&)
{
}
}
// no null date available -> no calculations possible throw uno::RuntimeException();
}
} // XDateFunctions
/** * Get week difference between 2 dates * * new Weeks(date1,date2,mode) function for StarCalc * * Two modes of operation are provided. * mode 0 is just a simple division by 7 calculation. * * mode 1 calculates the difference by week adhering to ISO8601. * * The International Standard IS-8601 states that Monday is the first * day of the week. The Gregorian Calendar is used for all dates, * proleptic in case of dates before 1582-10-15. * * The (consecutive) week number of a date is * std::floor( (date + NullDate - 1), 7.0 ), * with weeks starting on Monday, and week 0 * starting on Monday, 0001-01-01 Gregorian. * * Weeks(d2,d1,m) is defined as -Weeks(d1,d2,m). *
*/
/** * Get month difference between 2 dates * =Month(start, end, mode) Function for StarCalc * * two modes are provided * * mode 0 is the interval between the dates in month * * mode 1 is the difference in calendar month
*/
sal_Int32 SAL_CALL ScaDateAddIn::getDiffMonths( const uno::Reference< beans::XPropertySet >& xOptions,
sal_Int32 nStartDate, sal_Int32 nEndDate,
sal_Int32 nMode )
{ if (nMode != 0 && nMode != 1) throw lang::IllegalArgumentException();
/** * Get Year difference between 2 dates * * two modes are provided * * mode 0 is the interval between the dates in years * * mode 1 is the difference in calendar years
*/
sal_Int32 SAL_CALL ScaDateAddIn::getDiffYears( const uno::Reference< beans::XPropertySet >& xOptions,
sal_Int32 nStartDate, sal_Int32 nEndDate,
sal_Int32 nMode )
{ if (nMode != 0 && nMode != 1) throw lang::IllegalArgumentException();
/** * Check if a Date is in a leap year in the Gregorian calendar
*/
sal_Int32 SAL_CALL ScaDateAddIn::getIsLeapYear( const uno::Reference< beans::XPropertySet >& xOptions,
sal_Int32 nDate )
{
sal_Int32 nNullDate = GetNullDate( xOptions );
sal_Int32 nDays = nDate + nNullDate;
/** * Get the Number of Days in the month for a date
*/
sal_Int32 SAL_CALL ScaDateAddIn::getDaysInMonth( const uno::Reference<beans::XPropertySet>& xOptions,
sal_Int32 nDate )
{
sal_Int32 nNullDate = GetNullDate( xOptions );
sal_Int32 nDays = nDate + nNullDate;
/** * Get number of days in the year of a date specified
*/
sal_Int32 SAL_CALL ScaDateAddIn::getDaysInYear( const uno::Reference< beans::XPropertySet >& xOptions,
sal_Int32 nDate )
{
sal_Int32 nNullDate = GetNullDate( xOptions );
sal_Int32 nDays = nDate + nNullDate;
/** * Get number of weeks in the year for a date * * Most years have 52 weeks, but years that start on a Thursday * and leap years that start on a Wednesday have 53 weeks * * The International Standard IS-8601 has decreed that Monday * shall be the first day of the week. * * A WeekDay can be calculated by subtracting 1 and calculating the rest of * a division by 7 from the internal date representation * which gives a 0 - 6 value for Monday - Sunday * * @see #IsLeapYear #WeekNumber
*/
sal_Int32 SAL_CALL ScaDateAddIn::getWeeksInYear( const uno::Reference< beans::XPropertySet >& xOptions,
sal_Int32 nDate )
{
sal_Int32 nNullDate = GetNullDate( xOptions );
sal_Int32 nDays = nDate + nNullDate;
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.