Fix CalendarSystem:getDate and CalendarSystem::dateDifference
This commit is contained in:
parent
9cbc32a078
commit
6844da9ccb
@ -113,9 +113,21 @@ bool CalendarSystem::isValid(const QDate &date) const
|
||||
return m_calendarSystem->isValid(date);
|
||||
}
|
||||
|
||||
void CalendarSystem::getDate(const QDate date, int *year, int *month, int *day) const
|
||||
QVariantHash CalendarSystem::getDate(const QDate date) const
|
||||
{
|
||||
return m_calendarSystem->getDate(date, year, month, day);
|
||||
QVariantHash hash;
|
||||
|
||||
int year;
|
||||
int month;
|
||||
int day;
|
||||
|
||||
m_calendarSystem->getDate(date, &year, &month, &day);
|
||||
|
||||
hash["year"] = year;
|
||||
hash["month"] = month;
|
||||
hash["day"] = day;
|
||||
|
||||
return hash;
|
||||
}
|
||||
|
||||
int CalendarSystem::year(const QDate &date) const
|
||||
@ -164,10 +176,23 @@ QDate CalendarSystem::addDays(const QDate &date, int numDays) const
|
||||
return m_calendarSystem->addDays(date, numDays);
|
||||
}
|
||||
|
||||
void CalendarSystem::dateDifference(const QDate &fromDate, const QDate &toDate,
|
||||
int *yearsDiff, int *monthsDiff, int *daysDiff, int *direction) const
|
||||
QVariantHash CalendarSystem::dateDifference(const QDate &fromDate, const QDate &toDate) const
|
||||
{
|
||||
return m_calendarSystem->dateDifference(fromDate, toDate, yearsDiff, monthsDiff, daysDiff, direction);
|
||||
QVariantHash hash;
|
||||
|
||||
int yearsDiff;
|
||||
int monthsDiff;
|
||||
int daysDiff;
|
||||
int direction;
|
||||
|
||||
m_calendarSystem->dateDifference(fromDate, toDate, &yearsDiff, &monthsDiff, &daysDiff, &direction);
|
||||
|
||||
hash["years"] = yearsDiff;
|
||||
hash["months"] = monthsDiff;
|
||||
hash["days"] = daysDiff;
|
||||
hash["direction"] = direction;
|
||||
|
||||
return hash;
|
||||
}
|
||||
|
||||
int CalendarSystem::yearsDifference(const QDate &fromDate, const QDate &toDate) const
|
||||
|
@ -244,13 +244,13 @@ public:
|
||||
/**
|
||||
*
|
||||
* Returns the year, month and day portion of a given date in the current calendar system
|
||||
*
|
||||
* The values are returned in a hash, the available keys are,
|
||||
* ["year"] the year of the date
|
||||
* ["month"] the month of the date
|
||||
* ["day"] the day of the date
|
||||
* @param date date to get year, month and day for
|
||||
* @param year year number returned in this variable
|
||||
* @param month month number returned in this variable
|
||||
* @param day day of month returned in this variable
|
||||
*/
|
||||
Q_INVOKABLE void getDate(const QDate date, int *year, int *month, int *day) const;//TODO should it be part of the QML Wrapper?
|
||||
Q_INVOKABLE QVariantHash getDate(const QDate date) const;//TODO should it be part of the QML Wrapper?
|
||||
|
||||
/**
|
||||
* Returns the year portion of a given date in the current calendar system
|
||||
@ -340,7 +340,11 @@ public:
|
||||
|
||||
//KDE5 make virtual?
|
||||
/**
|
||||
* Returns the difference between two dates in years, months and days.
|
||||
* Returns the difference between two dates with a hash, the available keys are
|
||||
* ["years"] Returns number of years difference
|
||||
* ["months"] Returns number of months difference
|
||||
* ["days"] Returns number of days difference
|
||||
* ["direction"] Returns direction of difference, 1 if fromDate <= toDate, -1 otherwise
|
||||
* The difference is always caculated from the earlier date to the later
|
||||
* date in year, month and day order, with the @p direction parameter
|
||||
* indicating which direction the difference is applied from the @p toDate.
|
||||
@ -352,13 +356,8 @@ public:
|
||||
*
|
||||
* @param fromDate The date to start from
|
||||
* @param toDate The date to end at
|
||||
* @param yearsDiff Returns number of years difference
|
||||
* @param monthsDiff Returns number of months difference
|
||||
* @param daysDiff Returns number of days difference
|
||||
* @param direction Returns direction of difference, 1 if fromDate <= toDate, -1 otherwise
|
||||
*/
|
||||
Q_INVOKABLE void dateDifference(const QDate &fromDate, const QDate &toDate,
|
||||
int *yearsDiff, int *monthsDiff, int *daysDiff, int *direction) const;//TODO Does it work?
|
||||
Q_INVOKABLE QVariantHash dateDifference(const QDate &fromDate, const QDate &toDate)const;
|
||||
|
||||
//KDE5 make virtual?
|
||||
/**
|
||||
|
@ -213,6 +213,7 @@ Item {
|
||||
|
||||
PlasmaComponents.Button {
|
||||
id: bt2
|
||||
property variant hash
|
||||
anchors.horizontalCenter: column.horizontalCenter
|
||||
text: "click in order to test the CalendarSystem component"
|
||||
onClicked:{
|
||||
@ -242,7 +243,7 @@ Item {
|
||||
|
||||
console.log("isValid:" + calendar.isValid(2012, 33))
|
||||
|
||||
console.log("isValid:" + calendar.isValid(calendar.formatDate("2012-02-03"), 2010, 5, 5))//TODO
|
||||
console.log("isValid:" + calendar.isValid(calendar.formatDate("2012-02-03"), 2010, 5, 5))
|
||||
|
||||
console.log("isValidIsoWeekDate:" + calendar.isValidIsoWeekDate(2012, 2, 3))
|
||||
|
||||
@ -310,6 +311,18 @@ Item {
|
||||
|
||||
console.log("applyShortYearWindow:" + calendar.applyShortYearWindow(50))
|
||||
|
||||
console.log("getDate:")
|
||||
hash = calendar.getDate("2012-02-03")
|
||||
for (var i in hash) {
|
||||
console.log(" " + i, "=", hash[i])
|
||||
}
|
||||
|
||||
console.log("dateDifference:")
|
||||
hash = calendar.dateDifference("2012-01-01", "2014-03-03")
|
||||
for (var i in hash) {
|
||||
console.log(" " + i, "=", hash[i])
|
||||
}
|
||||
|
||||
console.log("===============end===============")
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user