aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Layt <[email protected]>2014-12-28 00:42:37 +0000
committerJohn Layt <[email protected]>2015-09-02 18:53:30 +0100
commitb47ddff602359476409d0db9807a35db2d200333 (patch)
treee2fa2ce255347fef0456e62622ddaae0758973da
parentfe5b5d1ca46e39f5ed1d13e050e97089e1b405ee (diff)
KF5: Remove use of KCalendarSystem
Switch from KCalendarSystem to QCalendarSystem to remove the dependency on kdelibs4support.
-rw-r--r--autotests/testholidayregion.cpp2
-rw-r--r--src/holidayregion.cpp4
-rw-r--r--src/holidayregion.h4
-rw-r--r--src/parsers/holidayparserdriver.cpp66
-rw-r--r--src/parsers/holidayparserdriver_p.h16
-rw-r--r--src/parsers/plan2/holidayparserdriverplan.cpp154
-rw-r--r--src/parsers/plan2/holidayparserdriverplan_p.h17
7 files changed, 137 insertions, 126 deletions
diff --git a/autotests/testholidayregion.cpp b/autotests/testholidayregion.cpp
index 27df7eb..1401b38 100644
--- a/autotests/testholidayregion.cpp
+++ b/autotests/testholidayregion.cpp
@@ -60,7 +60,7 @@ void HolidayRegionTest::parseRegionCalendarYear( const KHolidays::HolidayRegion
const QString &calendarType )
{
qDebug() << "Parsing region = " << region.regionCode() << " year = " << year << " calendar = " << calendarType;
- printHolidays( region.holidays( year, calendarType ) );
+ printHolidays( region.holidays( year ) );
qDebug() << "";
}
diff --git a/src/holidayregion.cpp b/src/holidayregion.cpp
index c98bb43..1cae595 100644
--- a/src/holidayregion.cpp
+++ b/src/holidayregion.cpp
@@ -356,10 +356,10 @@ Holiday::List HolidayRegion::holidays( const QDate &date ) const
}
}
-Holiday::List HolidayRegion::holidays( int calendarYear, const QString &calendarType ) const
+Holiday::List HolidayRegion::holidays( int calendarYear ) const
{
if ( isValid() ) {
- return d->mDriver->parseHolidays( calendarYear, calendarType );
+ return d->mDriver->parseHolidays( calendarYear );
} else {
return Holiday::List();
}
diff --git a/src/holidayregion.h b/src/holidayregion.h
index ba0c64b..12caa08 100644
--- a/src/holidayregion.h
+++ b/src/holidayregion.h
@@ -212,9 +212,9 @@ class KHOLIDAYS_EXPORT HolidayRegion
/**
* @since 4.6
*
- * Returns the list of holidays that occur in a calendar year @p calendarYear.
+ * Returns the list of holidays that occur in a Gregorian calendar year @p calendarYear.
*/
- Holiday::List holidays( int calendarYear, const QString &calendarType ) const;
+ Holiday::List holidays( int calendarYear ) const;
/**
* Checks whether there is any holiday defined for a @p date.
diff --git a/src/parsers/holidayparserdriver.cpp b/src/parsers/holidayparserdriver.cpp
index a94b15a..383d79c 100644
--- a/src/parsers/holidayparserdriver.cpp
+++ b/src/parsers/holidayparserdriver.cpp
@@ -21,7 +21,6 @@
#include "holidayparserdriver_p.h"
-#include <KCalendarSystem>
#include <QDebug>
using namespace KHolidays;
@@ -29,12 +28,10 @@ using namespace KHolidays;
HolidayParserDriver::HolidayParserDriver( const QString &filePath )
{
m_filePath = filePath;
- m_parseCalendar = 0;
}
HolidayParserDriver::~HolidayParserDriver()
{
- delete m_parseCalendar;
}
QString HolidayParserDriver::fileCountryCode() const
@@ -75,19 +72,16 @@ Holiday::List HolidayParserDriver::parseHolidays( const QDate &requestDate )
return parseHolidays( requestDate, requestDate );
}
-Holiday::List HolidayParserDriver::parseHolidays( int calendarYear, const QString &calendarType )
+Holiday::List HolidayParserDriver::parseHolidays( int calendarYear, QCalendarSystem::CalendarSystem calendar )
{
m_resultList.clear();
- setParseCalendar( calendarType );
- if ( !m_parseCalendar->isValid( calendarYear, 1, 1 ) ) {
+ setParseCalendar( calendar );
+ if ( !m_parseCalendar.isValid( calendarYear, 1, 1 ) ) {
return m_resultList;
}
- QDate startDate, endDate;
- m_parseCalendar->setDate( startDate, calendarYear, 1, 1 );
- endDate = startDate.addDays( m_parseCalendar->daysInYear( startDate ) - 1 );
-
- return parseHolidays( startDate, endDate );
+ return parseHolidays( m_parseCalendar.firstDayOfYear( calendarYear ),
+ m_parseCalendar.lastDayOfYear( calendarYear ) );
}
void HolidayParserDriver::error( const QString &errorMessage )
@@ -103,39 +97,9 @@ void HolidayParserDriver::parseMetadata()
{
}
-void HolidayParserDriver::setParseCalendar( const QString &calendarType )
+void HolidayParserDriver::setParseCalendar( QCalendarSystem::CalendarSystem calendar )
{
- delete m_parseCalendar;
-
- // this was removed from KCalendarSystem in KF5 for some reason, so copy it here until we have a QCalendarSystem
- KLocale::CalendarSystem cal = KLocale::QDateCalendar;
- if (calendarType == QLatin1String("coptic")) {
- cal = KLocale::CopticCalendar;
- } else if (calendarType == QLatin1String("ethiopian")) {
- cal = KLocale::EthiopianCalendar;
- } else if (calendarType == QLatin1String("gregorian")) {
- cal = KLocale::QDateCalendar;
- } else if (calendarType == QLatin1String("gregorian-proleptic")) {
- cal = KLocale::GregorianCalendar;
- } else if (calendarType == QLatin1String("hebrew")) {
- cal = KLocale::HebrewCalendar;
- } else if (calendarType == QLatin1String("hijri")) {
- cal = KLocale::IslamicCivilCalendar;
- } else if (calendarType == QLatin1String("indian-national")) {
- cal = KLocale::IndianNationalCalendar;
- } else if (calendarType == QLatin1String("jalali")) {
- cal = KLocale::JalaliCalendar;
- } else if (calendarType == QLatin1String("japanese")) {
- cal = KLocale::JapaneseCalendar;
- } else if (calendarType == QLatin1String("julian")) {
- cal = KLocale::JulianCalendar;
- } else if (calendarType == QLatin1String("minguo")) {
- cal = KLocale::MinguoCalendar;
- } else if (calendarType == QLatin1String("thai")) {
- cal = KLocale::ThaiCalendar;
- }
-
- m_parseCalendar = KCalendarSystem::create( cal );
+ m_parseCalendar = QCalendarSystem( calendar );
}
void HolidayParserDriver::setParseStartEnd()
@@ -143,22 +107,22 @@ void HolidayParserDriver::setParseStartEnd()
// Set start year and end year to generate holidays for
// TODO Maybe make +/- 1 more year to allow spanned holidays from previous/following years
// Make sure requested date range falls within valid date range for current calendar system
- if ( m_requestStart > m_parseCalendar->latestValidDate() ||
- m_requestEnd < m_parseCalendar->earliestValidDate() ) {
+ if ( m_requestStart > m_parseCalendar.latestValidDate() ||
+ m_requestEnd < m_parseCalendar.earliestValidDate() ) {
// Completely out of range, don't parse
m_parseStartYear = 0;
m_parseEndYear = m_parseStartYear - 1;
} else {
- if ( m_requestStart < m_parseCalendar->earliestValidDate() ) {
- m_parseStartYear = m_parseCalendar->year( m_parseCalendar->earliestValidDate() );
+ if ( m_requestStart < m_parseCalendar.earliestValidDate() ) {
+ m_parseStartYear = m_parseCalendar.year( m_parseCalendar.earliestValidDate() );
} else {
- m_parseStartYear = m_parseCalendar->year( m_requestStart );
+ m_parseStartYear = m_parseCalendar.year( m_requestStart );
}
- if ( m_requestEnd > m_parseCalendar->latestValidDate() ) {
- m_parseEndYear = m_parseCalendar->year( m_parseCalendar->latestValidDate() );
+ if ( m_requestEnd > m_parseCalendar.latestValidDate() ) {
+ m_parseEndYear = m_parseCalendar.year( m_parseCalendar.latestValidDate() );
} else {
- m_parseEndYear = m_parseCalendar->year( m_requestEnd );
+ m_parseEndYear = m_parseCalendar.year( m_requestEnd );
}
}
}
diff --git a/src/parsers/holidayparserdriver_p.h b/src/parsers/holidayparserdriver_p.h
index f0017d2..9b364ae 100644
--- a/src/parsers/holidayparserdriver_p.h
+++ b/src/parsers/holidayparserdriver_p.h
@@ -22,13 +22,13 @@
#ifndef KHOLIDAYS_HOLIDAYPARSERDRIVER_P_H
#define KHOLIDAYS_HOLIDAYPARSERDRIVER_P_H
+#include "qcalendarsystem_p.h"
+
#include <QDate>
#include <QString>
#include "holiday.h"
-class KCalendarSystem;
-
namespace KHolidays {
/**
@@ -117,12 +117,12 @@ class HolidayParserDriver
* Return a list of holidays falling in a given calendar year
*
* @param calendarYear year to return holidays for
- * @param calendarType calendar system of year, standard KDE calendar type,
- * see KCalendarSystem
+ * @param calendar calendar system of year
*
* @return a list of holidays
*/
- virtual Holiday::List parseHolidays( int calendarYear, const QString &calendarType );
+ virtual Holiday::List parseHolidays( int calendarYear,
+ QCalendarSystem::CalendarSystem calendar = QCalendarSystem::GregorianCalendar );
/**
* Standard error message handling
@@ -145,9 +145,9 @@ class HolidayParserDriver
/**
* Set the calendar system to use
*
- * @param calendarType standard KDE calendar type, see KCalendarSystem
+ * @param calendar The QCalendarSystem calendar system to use
*/
- virtual void setParseCalendar( const QString &calendarType );
+ virtual void setParseCalendar( QCalendarSystem::CalendarSystem calendar );
/**
* Initialise parse year variables for calendar system
@@ -166,7 +166,7 @@ class HolidayParserDriver
Holiday::List m_resultList; // List of requested holidays
- KCalendarSystem *m_parseCalendar; // Calendar system being parsed
+ QCalendarSystem m_parseCalendar; // Calendar system being parsed
int m_parseYear; // Year currently being parsed
int m_parseStartYear; // First year to parse in parse calendar
int m_parseEndYear; // Last year to parse in parse calendar
diff --git a/src/parsers/plan2/holidayparserdriverplan.cpp b/src/parsers/plan2/holidayparserdriverplan.cpp
index 54249bd..01e153a 100644
--- a/src/parsers/plan2/holidayparserdriverplan.cpp
+++ b/src/parsers/plan2/holidayparserdriverplan.cpp
@@ -39,7 +39,6 @@
#include <QFileInfo>
#include <qdebug.h>
-#include <KCalendarSystem>
#include "holiday_p.h"
@@ -94,17 +93,17 @@ void HolidayParserDriverPlan::error( const QString &errorMessage )
void HolidayParserDriverPlan::parse()
{
// Parse the file using every calendar system in the file
- foreach ( const QString &calendar, m_fileCalendarTypes ) {
+ foreach ( const QString &calendarType, m_fileCalendarTypes ) {
// Cater for events defined in other Calendar Systems where request year could cover 2 or 3 event years
// Perhaps also parse year before and year after to allow events to span years or shift to other year?
- setParseCalendar( calendar );
+ setParseCalendar( calendarType );
setParseStartEnd();
// Generate all events for this calendar in the required year(s)
for ( m_parseYear = m_parseStartYear; m_parseYear <= m_parseEndYear; ++m_parseYear ) {
- m_parseCalendar->setDate( m_parseYearStart, m_parseYear, 1, 1 );
+ m_parseYearStart = m_parseCalendar.firstDayOfYear( m_parseYear );
m_parseYearEaster = easter( m_parseYear );
m_parseYearPascha = pascha( m_parseYear );
@@ -163,6 +162,12 @@ void HolidayParserDriverPlan::parseMetadata()
m_parseMetadataOnly = false;
}
+void HolidayParserDriverPlan::setParseCalendar( QCalendarSystem::CalendarSystem calendar )
+{
+ m_parseCalendarType = systemToType( calendar );
+ HolidayParserDriver::setParseCalendar( calendar );
+}
+
QString HolidayParserDriverPlan::filePath()
{
return m_filePath;
@@ -181,8 +186,8 @@ std::string *HolidayParserDriverPlan::fileToParse() const
int HolidayParserDriverPlan::adjustedMonthNumber( int month )
{
if ( m_eventCalendarType != QLatin1String("hebrew") || // Only adjust Hebrew months
- m_parseCalendar->calendarType() != QLatin1String("hebrew") ||
- !m_parseCalendar->isLeapYear( m_parseYear ) || // Only adjust in leap year
+ m_parseCalendarType != QLatin1String("hebrew") ||
+ !m_parseCalendar.isLeapYear( m_parseYear ) || // Only adjust in leap year
month < 6 ) { // Only adjust from Adar onwards
return month;
}
@@ -200,7 +205,7 @@ int HolidayParserDriverPlan::adjustedMonthNumber( int month )
bool HolidayParserDriverPlan::isLeapYear( int year )
{
- return m_parseCalendar->isLeapYear( year );
+ return m_parseCalendar.isLeapYear( year );
}
int HolidayParserDriverPlan::parseYear()
@@ -208,25 +213,9 @@ int HolidayParserDriverPlan::parseYear()
return m_parseYear;
}
-int HolidayParserDriverPlan::monthsInYear( int year )
-{
- QDate tempDate;
- m_parseCalendar->setDate( tempDate, year, 1, 1 );
- return m_parseCalendar->monthsInYear( tempDate );
-}
-
-int HolidayParserDriverPlan::daysInMonth( int year, int month )
-{
- QDate tempDate;
- m_parseCalendar->setDate( tempDate, year, month, 1 );
- return m_parseCalendar->daysInMonth( tempDate );
-}
-
int HolidayParserDriverPlan::julianDay( int year, int month, int day )
{
- QDate tempDate;
- m_parseCalendar->setDate( tempDate, year, month, day );
- return tempDate.toJulianDay();
+ return m_parseCalendar.date( year, month, day ).toJulianDay();
}
void HolidayParserDriverPlan::julianDayToDate( int jd, int *year, int *month, int *day )
@@ -234,19 +223,19 @@ void HolidayParserDriverPlan::julianDayToDate( int jd, int *year, int *month, in
QDate tempDate = QDate::fromJulianDay( jd );
if ( year ) {
- *year = m_parseCalendar->year( tempDate );
+ *year = m_parseCalendar.year( tempDate );
}
if ( month ) {
- *month = m_parseCalendar->month( tempDate );
+ *month = m_parseCalendar.month( tempDate );
}
if ( day ) {
- *day = m_parseCalendar->day( tempDate );
+ *day = m_parseCalendar.day( tempDate );
}
}
QDate HolidayParserDriverPlan::easter( int year )
{
- if ( m_parseCalendar->calendarType() != QLatin1String("gregorian") ) {
+ if ( m_parseCalendar.calendarSystem() != QCalendarSystem::GregorianCalendar ) {
return QDate();
}
@@ -267,8 +256,8 @@ QDate HolidayParserDriverPlan::easter( int year )
QDate HolidayParserDriverPlan::pascha( int year )
{
- if ( m_parseCalendar->calendarType() == QLatin1String("gregorian") ||
- m_parseCalendar->calendarType() == QLatin1String("julian") ) {
+ if ( m_parseCalendar.calendarSystem() != QCalendarSystem::GregorianCalendar ||
+ m_parseCalendar.calendarSystem() != QCalendarSystem::JulianCalendar ) {
// Algorithm taken from Tondering
// http://www.tondering.dk/claus/cal/node3.html#SECTION003137000000000000000
// Gives Orthodox Easter in the Julian Calendar, need to convert afterwards to Gregorian if needed
@@ -279,11 +268,11 @@ QDate HolidayParserDriverPlan::pascha( int year )
int month = 3 + ( ( l + 40 ) / 44 );
int day = l + 28 - ( 31 * ( month / 4 ) );
- if ( m_parseCalendar->calendarType() == QLatin1String("julian") ) {
+ if ( m_parseCalendar.calendarSystem() != QCalendarSystem::JulianCalendar ) {
return QDate::fromJulianDay( julianDay( year, month, day ) );
}
- if ( m_parseCalendar->calendarType() == QLatin1String("gregorian") ) {
+ if ( m_parseCalendar.calendarSystem() != QCalendarSystem::GregorianCalendar ) {
setParseCalendar( QStringLiteral("julian") );
int paschaJd = julianDay( year, month, day );
setParseCalendar( QStringLiteral("gregorian") );
@@ -294,6 +283,51 @@ QDate HolidayParserDriverPlan::pascha( int year )
return QDate();
}
+QCalendarSystem::CalendarSystem HolidayParserDriverPlan::typeToSystem( const QString &calendarType )
+{
+ if ( calendarType == QStringLiteral( "gregorian" ) ) {
+ return QCalendarSystem::GregorianCalendar;
+ } else if ( calendarType == QStringLiteral( "hebrew" ) ) {
+ return QCalendarSystem::HebrewCalendar;
+ } else if ( calendarType == QStringLiteral( "hijri" ) ) {
+ return QCalendarSystem::IslamicCivilCalendar;
+ } else if ( calendarType == QStringLiteral( "jalali" ) ) {
+ return QCalendarSystem::PersianCalendar;
+ } else if ( calendarType == QStringLiteral( "julian" ) ) {
+ return QCalendarSystem::JulianCalendar;
+ } else if ( calendarType == QStringLiteral( "coptic" ) ) {
+ return QCalendarSystem::CopticCalendar;
+ } else if ( calendarType == QStringLiteral( "ethiopian" ) ) {
+ return QCalendarSystem::EthiopicCalendar;
+ } else if ( calendarType == QStringLiteral( "indiannational" ) ) {
+ return QCalendarSystem::IndianNationalCalendar;
+ }
+ return QCalendarSystem::GregorianCalendar;
+}
+
+QString HolidayParserDriverPlan::systemToType( QCalendarSystem::CalendarSystem calendar )
+{
+ switch (calendar) {
+ case QCalendarSystem::GregorianCalendar:
+ return QStringLiteral( "gregorian" );
+ case QCalendarSystem::HebrewCalendar:
+ return QStringLiteral( "hebrew" );
+ case QCalendarSystem::IslamicCivilCalendar:
+ return QStringLiteral( "hijri" );
+ case QCalendarSystem::PersianCalendar:
+ return QStringLiteral( "jalali" );
+ case QCalendarSystem::JulianCalendar:
+ return QStringLiteral( "julian" );
+ case QCalendarSystem::CopticCalendar:
+ return QStringLiteral( "coptic" );
+ case QCalendarSystem::EthiopicCalendar:
+ return QStringLiteral( "ethiopian" );
+ case QCalendarSystem::IndianNationalCalendar:
+ return QStringLiteral( "indiannational" );
+ default:
+ return QStringLiteral( "gregorian" );
+ }
+}
/*************************
* Calculate jd routines *
@@ -344,7 +378,7 @@ int HolidayParserDriverPlan::julianDayFromRelativeWeekday( int occurrence, int w
occurrence = AFTER;
}
- int thisWeekday = m_parseCalendar->dayOfWeek( QDate::fromJulianDay( jd ) );
+ int thisWeekday = m_parseCalendar.dayOfWeek( QDate::fromJulianDay( jd ) );
/* AFTER actually means on or after */
/* BEFORE actually means on or before */
@@ -365,7 +399,7 @@ int HolidayParserDriverPlan::julianDayFromRelativeWeekday( int occurrence, int w
int HolidayParserDriverPlan::julianDayFromWeekdayInMonth( int occurrence, int weekday, int month )
{
if ( occurrence == LAST ) { // Is weekday on or before last day of month
- return julianDayFromRelativeWeekday( BEFORE, weekday, julianDay( m_parseYear, month, daysInMonth( m_parseYear, month ) ) );
+ return julianDayFromRelativeWeekday( BEFORE, weekday, julianDay( m_parseYear, month, m_parseCalendar.daysInMonth( m_parseYear, month ) ) );
} else { // Is nth weekday on or after first day of month
return julianDayFromRelativeWeekday( occurrence, weekday, julianDay( m_parseYear, month, 1 ) );
}
@@ -376,6 +410,12 @@ int HolidayParserDriverPlan::julianDayFromWeekdayInMonth( int occurrence, int we
* Set parsed event variables convenience functions *
****************************************************/
+void HolidayParserDriverPlan::setParseCalendar( const QString &calendarType )
+{
+ m_parseCalendarType = calendarType;
+ setParseCalendar( typeToSystem( calendarType ) );
+}
+
void HolidayParserDriverPlan::setFileCountryCode( const QString &countryCode )
{
m_fileCountryCode = countryCode;
@@ -441,17 +481,17 @@ void HolidayParserDriverPlan::setEventDate( int jd )
void HolidayParserDriverPlan::setFromWeekdayInMonth( int occurrence, int weekday, int month, int offset, int duration )
{
// Don't set if only parsing metadata or calendar for event rule is not the current parse calendar
- if ( m_parseMetadataOnly || m_eventCalendarType != m_parseCalendar->calendarType() ) {
+ if ( m_parseMetadataOnly || m_eventCalendarType != m_parseCalendarType ) {
return;
}
int startMonth, endMonth;
if ( month == LAST ) {
- startMonth = monthsInYear( m_parseYear );
+ startMonth = m_parseCalendar.monthsInYear( m_parseYear );
endMonth = startMonth;
} else if ( month == ANY ) {
startMonth = 1;
- endMonth = monthsInYear( m_parseYear );
+ endMonth = m_parseCalendar.monthsInYear( m_parseYear );
} else {
startMonth = month;
endMonth = month;
@@ -460,7 +500,7 @@ void HolidayParserDriverPlan::setFromWeekdayInMonth( int occurrence, int weekday
// Generate all events in the required event month(s)
for ( int thisMonth = startMonth; thisMonth <= endMonth; ++thisMonth ) {
- if ( m_parseCalendar->isValid( m_parseYear, thisMonth, 1 ) ) {
+ if ( m_parseCalendar.isValid( m_parseYear, thisMonth, 1 ) ) {
int startOccurrence, endOccurrence;
if ( occurrence == ANY ) { // Generate 1st through 5th weekdays, assumes no month with > 35 days
startOccurrence = 1;
@@ -471,7 +511,7 @@ void HolidayParserDriverPlan::setFromWeekdayInMonth( int occurrence, int weekday
}
int jdMonthStart = julianDay( m_parseYear, thisMonth, 1 );
- int jdMonthEnd = julianDay( m_parseYear, thisMonth, daysInMonth( m_parseYear, thisMonth ) );
+ int jdMonthEnd = julianDay( m_parseYear, thisMonth, m_parseCalendar.daysInMonth( m_parseYear, thisMonth ) );
// Generate each required occurrence of weekday in month, check occurrence actually falls in month
for ( int thisOccurrence = startOccurrence; thisOccurrence <= endOccurrence; ++thisOccurrence ) {
@@ -494,7 +534,7 @@ void HolidayParserDriverPlan::setFromWeekdayInMonth( int occurrence, int weekday
void HolidayParserDriverPlan::setFromRelativeWeekday( int occurrence, int weekday, int offset, int duration )
{
// Don't set if only parsing metadata or calendar for event rule is not the current parse calendar
- if ( m_parseMetadataOnly || m_eventCalendarType != m_parseCalendar->calendarType() ) {
+ if ( m_parseMetadataOnly || m_eventCalendarType != m_parseCalendarType ) {
return;
}
@@ -507,11 +547,11 @@ void HolidayParserDriverPlan::setFromRelativeWeekday( int occurrence, int weekda
int startMonth, endMonth;
if ( m_eventMonth == LAST ) { // Generate just the last month
- startMonth = monthsInYear( thisYear );
+ startMonth = m_parseCalendar.monthsInYear( thisYear );
endMonth = startMonth;
} else if ( m_eventMonth == ANY ) { // Generate every month
startMonth = 1;
- endMonth = monthsInYear( thisYear );
+ endMonth = m_parseCalendar.monthsInYear( thisYear );
} else { // Generate just the specific event month
startMonth = m_eventMonth;
endMonth = m_eventMonth;
@@ -523,11 +563,11 @@ void HolidayParserDriverPlan::setFromRelativeWeekday( int occurrence, int weekda
int startDay, endDay;
if ( m_eventDay == LAST ) { // Generate just the last day in the month
- startDay = daysInMonth( thisYear, thisMonth );
+ startDay = m_parseCalendar.daysInMonth( thisYear, thisMonth );
endDay = startDay;
} else if ( m_eventDay == ANY ) { // Generate every day in the month
startDay = 1;
- endDay = daysInMonth( thisYear, thisMonth );
+ endDay = m_parseCalendar.daysInMonth( thisYear, thisMonth );
} else { // Generate just the specific event day
startDay = m_eventDay;
endDay = m_eventDay;
@@ -535,7 +575,7 @@ void HolidayParserDriverPlan::setFromRelativeWeekday( int occurrence, int weekda
// Generate all events on the required day(s)
for ( int thisDay = startDay; thisDay <= endDay; ++thisDay ) {
- if ( m_parseCalendar->isValid( thisYear, thisMonth, thisDay ) ) {
+ if ( m_parseCalendar.isValid( thisYear, thisMonth, thisDay ) ) {
int relativeJd = julianDayFromRelativeWeekday( occurrence, weekday, julianDay( thisYear, thisMonth, thisDay ) );
setEvent( relativeJd + offset, 0, duration );
}
@@ -554,9 +594,7 @@ int HolidayParserDriverPlan::conditionalOffset( int year, int month, int day, in
int offset = 0;
- QDate tempDate;
- m_parseCalendar->setDate( tempDate, year, month, day );
- int weekday = m_parseCalendar->dayOfWeek( tempDate );
+ int weekday = m_parseCalendar.dayOfWeek( year, month, day );
if ( condition & ( 1 << weekday ) ) {
/* condition matches -> higher 8 bits contain the possible days to shift to */
@@ -582,7 +620,7 @@ int HolidayParserDriverPlan::conditionalOffset( int year, int month, int day, in
void HolidayParserDriverPlan::setFromDate( int offset, int condition, int duration )
{
// Don't set if only parsing metadata or calendar for event rule is not the current parse calendar
- if ( m_parseMetadataOnly || m_eventCalendarType != m_parseCalendar->calendarType() ) {
+ if ( m_parseMetadataOnly || m_eventCalendarType != m_parseCalendarType ) {
return;
}
@@ -595,11 +633,11 @@ void HolidayParserDriverPlan::setFromDate( int offset, int condition, int durati
int startMonth, endMonth;
if ( m_eventMonth == LAST ) { // Generate just the last month
- startMonth = monthsInYear( thisYear );
+ startMonth = m_parseCalendar.monthsInYear( thisYear );
endMonth = startMonth;
} else if ( m_eventMonth == ANY ) { // Generate every month
startMonth = 1;
- endMonth = monthsInYear( thisYear );
+ endMonth = m_parseCalendar.monthsInYear( thisYear );
} else { // Generate just the specific event month
startMonth = m_eventMonth;
endMonth = m_eventMonth;
@@ -610,11 +648,11 @@ void HolidayParserDriverPlan::setFromDate( int offset, int condition, int durati
int startDay, endDay;
if ( m_eventDay == LAST ) { // Generate just the last day in the month
- startDay = daysInMonth( thisYear, thisMonth );
+ startDay = m_parseCalendar.daysInMonth( thisYear, thisMonth );
endDay = startDay;
} else if ( m_eventDay == ANY ) { // Generate every day in the month
startDay = 1;
- endDay = daysInMonth( thisYear, thisMonth );
+ endDay = m_parseCalendar.daysInMonth( thisYear, thisMonth );
} else { // Generate just the specific event day
startDay = m_eventDay;
endDay = m_eventDay;
@@ -623,7 +661,7 @@ void HolidayParserDriverPlan::setFromDate( int offset, int condition, int durati
// Generate all events on the required day(s)
for ( int thisDay = startDay; thisDay <= endDay; ++thisDay ) {
- if ( m_parseCalendar->isValid( thisYear, thisMonth, thisDay ) ) {
+ if ( m_parseCalendar.isValid( thisYear, thisMonth, thisDay ) ) {
setEvent( julianDay( thisYear, thisMonth, thisDay ) + offset,
conditionalOffset( thisYear, thisMonth, thisDay, condition ), duration );
}
@@ -642,7 +680,7 @@ void HolidayParserDriverPlan::setFromDate( int offset, int condition, int durati
void HolidayParserDriverPlan::setFromEaster( int offset, int duration )
{
// Don't set if only parsing metadata or calendar for event rule is not the current parse calendar
- if ( m_parseMetadataOnly || m_eventCalendarType != m_parseCalendar->calendarType() ) {
+ if ( m_parseMetadataOnly || m_eventCalendarType != m_parseCalendarType ) {
return;
}
@@ -662,7 +700,7 @@ void HolidayParserDriverPlan::setFromEaster( int offset, int duration )
void HolidayParserDriverPlan::setFromPascha( int offset, int duration )
{
// Don't set if only parsing metadata or calendar for event rule is not the current parse calendar
- if ( m_parseMetadataOnly || m_eventCalendarType != m_parseCalendar->calendarType() ) {
+ if ( m_parseMetadataOnly || m_eventCalendarType != m_parseCalendarType ) {
return;
}
@@ -677,7 +715,7 @@ void HolidayParserDriverPlan::setFromPascha( int offset, int duration )
void HolidayParserDriverPlan::setEvent( int jd, int observeOffset, int duration )
{
// Don't set if only parsing metadata or calendar for event rule is not the current parse calendar
- if ( m_parseMetadataOnly || m_eventCalendarType != m_parseCalendar->calendarType() ) {
+ if ( m_parseMetadataOnly || m_eventCalendarType != m_parseCalendarType ) {
return;
}
@@ -690,7 +728,7 @@ void HolidayParserDriverPlan::setEvent( int jd, int observeOffset, int duration
void HolidayParserDriverPlan::addHoliday( const QDate &observedDate, int duration )
{
// Only set if event falls in requested date range, i.e. either starts or ends during range
- if ( m_parseCalendar->isValid( observedDate ) &&
+ if ( m_parseCalendar.isValid( observedDate ) &&
observedDate <= m_requestEnd &&
observedDate.addDays( duration - 1 ) >= m_requestStart ) {
KHolidays::Holiday holiday;
diff --git a/src/parsers/plan2/holidayparserdriverplan_p.h b/src/parsers/plan2/holidayparserdriverplan_p.h
index 797f7c6..a44f56b 100644
--- a/src/parsers/plan2/holidayparserdriverplan_p.h
+++ b/src/parsers/plan2/holidayparserdriverplan_p.h
@@ -91,6 +91,13 @@ protected:
*/
void parseMetadata() Q_DECL_OVERRIDE;
+ /**
+ * Set the calendar system to use
+ *
+ * @param calendar The QCalendarSystem calendar system to use
+ */
+ void setParseCalendar( QCalendarSystem::CalendarSystem calendar );
+
// Bison C++ skeleton required friend for Bison parser class implementation
friend class HolidayParserPlan;
@@ -112,6 +119,7 @@ protected:
int julianDayFromWeekdayInMonth( int occurrence, int weekday, int month );
// Utilities for parser to set variables during parsing
+ void setParseCalendar( const QString &calendarType );
void setFileCountryCode( const QString &countryCode );
void setFileLanguageCode( const QString &languageCode );
void setFileName( const QString &ame );
@@ -132,12 +140,12 @@ protected:
private:
// Calendar and date calculation utilities
- int monthsInYear( int year );
- int daysInMonth( int year, int month );
int julianDay( int year, int month, int day );
void julianDayToDate( int jd, int *year, int *month, int *day );
QDate easter( int year );
QDate pascha( int year );
+ QCalendarSystem::CalendarSystem typeToSystem( const QString &calendarType );
+ QString systemToType( QCalendarSystem::CalendarSystem calendar );
int conditionalOffset( int year, int month, int day, int condition );
@@ -145,7 +153,8 @@ private:
QByteArray m_scanData; // Holiday file stored as a string
- QStringList m_fileCalendarTypes; // List of all Calendar Systems used in file
+ QStringList m_fileCalendarTypes; // List of all Calendar Types used in file
+ QString m_parseCalendarType; // Calendar Type being parsed
bool m_traceParsing; // Bison C++ skeleton enable tracing in Bison parser class
HolidayParserPlan *m_parser; // Bison C++ skeleton Bison parser class implementation
@@ -159,7 +168,7 @@ private:
QDate m_parseYearPascha; // Orthodox Easter in the parse year, Gregorian only
QStringList m_eventCategories; // Event categories
- QString m_eventCalendarType; // Calendar System for event rule
+ QString m_eventCalendarType; // Calendar Type for event rule
QString m_eventName; // Event name text
int m_eventYear; // Event date fields
int m_eventMonth; // Event date fields