Commit 58c51df6 authored by Alois Spitzbart's avatar Alois Spitzbart Committed by Allen Winter
Browse files

New function for plasma to generate holidays without astro seasons

This function creates just holidays from the holiday files. Astro seasons are not included, which are calculated. In Plasma can the astro seasons displayed two times. When this function is used, this can prevented.

I did get a better name. Maybe someone has a better idea. Would be Plasma as suffix better than Only?

This a follow up to !34

BUG: 445324
parent 014f3b3a
Pipeline #162339 passed with stage
in 2 minutes and 34 seconds
......@@ -21,8 +21,10 @@ include(ECMQtDeclareLoggingCategory)
include(ECMAddQch)
include(ECMGeneratePriFile)
include(KDEGitCommitHooks)
include(ECMGenerateExportHeader)
set(KHOLIDAYS_LIB_VERSION ${KF_VERSION})
set(EXCLUDE_DEPRECATED_BEFORE_AND_AT 0 CACHE STRING "Control the range of deprecated API excluded from the build [default=0].")
ecm_setup_version(PROJECT VARIABLE_PREFIX KHOLIDAYS
VERSION_HEADER "${CMAKE_CURRENT_BINARY_DIR}/kholidays_version.h"
......
......@@ -36,5 +36,11 @@ add_executable(testholidayregion testholidayregion.cpp)
add_test(NAME testholidayregion COMMAND testholidayregion)
set_target_properties(testholidayregion PROPERTIES COMPILE_FLAGS -DKDESRCDIR="\\"${CMAKE_CURRENT_SOURCE_DIR}/\\"")
# if(NOT EXCLUDE_DEPRECATED_BEFORE_AND_AT STREQUAL "CURRENT" AND
# EXCLUDE_DEPRECATED_BEFORE_AND_AT VERSION_LESS 5.93.0)
# add_test(NAME testholidayregion COMMAND testholidayregion)
# set_target_properties(testholidayregion PROPERTIES COMPILE_FLAGS -DKDESRCDIR="\\"${CMAKE_CURRENT_SOURCE_DIR}/\\"")
# endif()
ecm_mark_as_test(testholidayregion)
target_link_libraries(testholidayregion KF5Holidays Qt${QT_MAJOR_VERSION}::Test)
......@@ -46,7 +46,11 @@ void HolidayRegionTest::printHolidays(const KHolidays::Holiday::List &holidays)
void HolidayRegionTest::parseRegionCalendarYear(const KHolidays::HolidayRegion &region, int year, const QString &calendarType)
{
qDebug() << "Parsing region = " << region.regionCode() << " year = " << year << " calendar = " << calendarType;
#if KHOLIDAYS_BUILD_DEPRECATED_SINCE(5, 95)
printHolidays(region.holidays(year));
#else
printHolidays(region.rawHolidaysWithAstroSeasons(year));
#endif
qDebug() << "";
}
......@@ -54,14 +58,30 @@ void HolidayRegionTest::parseRegionDateRange(const KHolidays::HolidayRegion &reg
{
qDebug() << "Parsing regionCode = " << region.regionCode() << " start date = " << startDate.toString(Qt::ISODate)
<< " end date = " << endDate.toString(Qt::ISODate);
#if KHOLIDAYS_BUILD_DEPRECATED_SINCE(5, 95)
printHolidays(region.holidays(startDate, endDate));
#else
printHolidays(region.rawHolidaysWithAstroSeasons(startDate, endDate));
#endif
qDebug() << "";
}
void HolidayRegionTest::parseRawRegionDateRange(const KHolidays::HolidayRegion &region, const QDate &startDate, const QDate &endDate)
{
qDebug() << "Parsing regionCode = " << region.regionCode() << " start date = " << startDate.toString(Qt::ISODate)
<< " end date = " << endDate.toString(Qt::ISODate);
printHolidays(region.rawHolidays(startDate, endDate));
qDebug() << "";
}
void HolidayRegionTest::parseRegionDate(const KHolidays::HolidayRegion &region, const QDate &date)
{
qDebug() << "Parsing regionCode = " << region.regionCode() << " date = " << date.toString(Qt::ISODate);
#if KHOLIDAYS_BUILD_DEPRECATED_SINCE(5, 95)
printHolidays(region.holidays(date));
#else
printHolidays(region.rawHolidaysWithAstroSeasons(date));
#endif
qDebug() << "";
}
......@@ -178,3 +198,14 @@ void HolidayRegionTest::testSolistaleInHolidays()
parseRegionDateRange(region, QDate(2020, 12, 25), QDate(2021, 7, 2));
parseRegionDateRange(region, QDate(2020, 12, 25), QDate(2022, 1, 2));
}
void HolidayRegionTest::testLoadFileCalendarSystemsForPlasma()
{
KHolidays::HolidayRegion region(QFileInfo(KDESRCDIR "/holiday_calendar_systems"));
printMetadata(region);
parseRawRegionDateRange(region, QDate(2020, 7, 1), QDate(2021, 6, 30));
parseRawRegionDateRange(region, QDate(2020, 1, 1), QDate(2020, 12, 31));
parseRawRegionDateRange(region, QDate(2020, 11, 1), QDate(2021, 1, 2));
parseRawRegionDateRange(region, QDate(2020, 12, 25), QDate(2021, 7, 2));
parseRawRegionDateRange(region, QDate(2020, 12, 25), QDate(2022, 1, 2));
}
......@@ -28,12 +28,14 @@ private Q_SLOTS:
void testRegions();
void testDefaultRegions();
void testSolistaleInHolidays();
void testLoadFileCalendarSystemsForPlasma();
private:
void printMetadata(const KHolidays::HolidayRegion &region);
void printHolidays(const KHolidays::Holiday::List &holidays);
void parseRegionCalendarYear(const KHolidays::HolidayRegion &region, int year, const QString &calendarType = "gregorian");
void parseRegionDateRange(const KHolidays::HolidayRegion &region, const QDate &startDate, const QDate &endDate);
void parseRawRegionDateRange(const KHolidays::HolidayRegion &region, const QDate &startDate, const QDate &endDate);
void parseRegionDate(const KHolidays::HolidayRegion &region, const QDate &date);
};
......
EXCLUDE_PATTERNS += */parsers/*
# define so that deprecated API is not skipped
PREDEFINED += \
"KHOLIDAYS_DEPRECATED_VERSION(x, y, t)=" \
......@@ -54,7 +54,14 @@ ecm_qt_declare_logging_category(KF5Holidays
EXPORT KHOLIDAYS
)
generate_export_header(KF5Holidays BASE_NAME KHolidays)
ecm_generate_export_header(KF5Holidays
VERSION ${KF_VERSION}
BASE_NAME KHolidays
GROUP_BASE_NAME KF
DEPRECATED_BASE_VERSION 0
DEPRECATION_VERSIONS 5.95
EXCLUDE_DEPRECATED_BEFORE_AND_AT ${EXCLUDE_DEPRECATED_BEFORE_AND_AT}
)
target_include_directories(KF5Holidays INTERFACE "$<INSTALL_INTERFACE:${KDE_INSTALL_INCLUDEDIR_KF}/KHolidays>")
target_include_directories(KF5Holidays PUBLIC "$<BUILD_INTERFACE:${KHolidays_SOURCE_DIR}/src;${KHolidays_BINARY_DIR}/src>")
......
......@@ -1076,6 +1076,15 @@ Holiday::List HolidayRegion::holidays(const QDate &startDate, const QDate &endDa
}
}
Holiday::List HolidayRegion::rawHolidays(const QDate &startDate, const QDate &endDate) const
{
if (isValid()) {
return d->mDriver->parseRawHolidays(startDate, endDate);
} else {
return Holiday::List();
}
}
Holiday::List HolidayRegion::holidays(const QDate &date) const
{
if (isValid()) {
......
......@@ -207,26 +207,70 @@ public:
*/
static QString description(const QString &regionCode);
#if KHOLIDAYS_ENABLE_DEPRECATED_SINCE(5, 95)
/**
* @since 4.6
*
* Returns the list of holidays that occur between @p startDate and @p endDate.
*
* @deprecated Since 5.95, use rawHolidaysWithAstroSeasons() instead.
*/
KHOLIDAYS_DEPRECATED_VERSION(5, 95, "use rawHolidaysWithAstroSeasons() instead")
Holiday::List holidays(const QDate &startDate, const QDate &endDate) const;
#endif
/**
* @since 5.95
*
* Returns the list of holidays that occur between @p startDate and @p endDate.
*
*/
Holiday::List rawHolidaysWithAstroSeasons(const QDate &startDate, const QDate &endDate) const;
/**
* @since 5.95
*
* Returns the list of holidays that occur between @p startDate and @p endDate.
*/
Holiday::List rawHolidays(const QDate &startDate, const QDate &endDate) const;
#if KHOLIDAYS_ENABLE_DEPRECATED_SINCE(5, 95)
/**
* @since 4.6
*
* Returns the list of holidays that occur on a @p date.
*
* @deprecated Since 5.95, use rawHolidaysWithAstroSeasons() instead.
*/
KHOLIDAYS_DEPRECATED_VERSION(5, 95, "use rawHolidaysWithAstroSeasons() instead")
Holiday::List holidays(const QDate &date) const;
#endif
/**
* @since 5.95
*
* Returns the list of holidays that occur on a @p date.
*/
Holiday::List rawHolidaysWithAstroSeasons(const QDate &date) const;
#if KHOLIDAYS_ENABLE_DEPRECATED_SINCE(5, 95)
/**
* @since 4.6
*
* Returns the list of holidays that occur in a Gregorian calendar year @p calendarYear.
*
* @deprecated Since 5.95, use rawHolidaysWithAstroSeasons() instead.
*/
KHOLIDAYS_DEPRECATED_VERSION(5, 95, "use rawHolidaysWithAstroSeasons() instead")
Holiday::List holidays(int calendarYear) const;
#endif
/**
* @since 5.95
*
* Returns the list of holidays that occur in a Gregorian calendar year @p calendarYear.
*/
Holiday::List rawHolidaysWithAstroSeasons(int calendarYear) const;
/**
* Checks whether there is any holiday defined for a @p date.
......
......@@ -46,7 +46,7 @@ QString HolidayParserDriver::fileDescription() const
return m_fileDescription;
}
Holiday::List HolidayParserDriver::parseHolidays(const QDate &startDate, const QDate &endDate)
Holiday::List HolidayParserDriver::parseRawHolidays(const QDate &startDate, const QDate &endDate)
{
m_resultList.clear();
if (startDate.isNull() || endDate.isNull()) {
......@@ -55,6 +55,12 @@ Holiday::List HolidayParserDriver::parseHolidays(const QDate &startDate, const Q
m_requestStart = startDate;
m_requestEnd = endDate;
parse();
return m_resultList;
}
Holiday::List HolidayParserDriver::parseHolidays(const QDate &startDate, const QDate &endDate)
{
parseRawHolidays(startDate, endDate);
for (int year = startDate.year(); year <= endDate.year(); ++year) {
for (auto s : {AstroSeasons::JuneSolstice, AstroSeasons::DecemberSolstice, AstroSeasons::MarchEquinox, AstroSeasons::SeptemberEquinox}) {
......
......@@ -98,6 +98,16 @@ public:
*/
virtual Holiday::List parseHolidays(const QDate &date);
/**
* Return a list of holidays falling between any two dates without astro seasons
*
* @param startDate start date of the holiday parse range
* @param endDate end date of the holiday parse range
*
* @return a list of holidays
*/
virtual Holiday::List parseRawHolidays(const QDate &startDate, const QDate &endDate);
/**
* Convenience function
* Return a list of holidays falling in a given calendar year
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment