QDateTime: change an instance of out parameters to return-by-value
Compilers don't like out parameters. Effects on Linux GCC 4.9 stripped release builds: text -528B data +-0B relocs +-0 Change-Id: I32ee1a6c4388900bacfc6eb20feb4b81d71cb1f2 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
c3e680c3b1
commit
62475eb8b0
@ -117,7 +117,12 @@ static inline qint64 julianDayFromDate(int year, int month, int day)
|
|||||||
return day + floordiv(153 * m + 2, 5) + 365 * y + floordiv(y, 4) - floordiv(y, 100) + floordiv(y, 400) - 32045;
|
return day + floordiv(153 * m + 2, 5) + 365 * y + floordiv(y, 4) - floordiv(y, 100) + floordiv(y, 400) - 32045;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void getDateFromJulianDay(qint64 julianDay, int *yearp, int *monthp, int *dayp)
|
struct ParsedDate
|
||||||
|
{
|
||||||
|
int year, month, day;
|
||||||
|
};
|
||||||
|
|
||||||
|
static ParsedDate getDateFromJulianDay(qint64 julianDay)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* Math from The Calendar FAQ at http://www.tondering.dk/claus/cal/julperiod.php
|
* Math from The Calendar FAQ at http://www.tondering.dk/claus/cal/julperiod.php
|
||||||
@ -140,12 +145,8 @@ static void getDateFromJulianDay(qint64 julianDay, int *yearp, int *monthp, int
|
|||||||
if (year <= 0)
|
if (year <= 0)
|
||||||
--year ;
|
--year ;
|
||||||
|
|
||||||
if (yearp)
|
const ParsedDate result = { year, month, day };
|
||||||
*yearp = year;
|
return result;
|
||||||
if (monthp)
|
|
||||||
*monthp = month;
|
|
||||||
if (dayp)
|
|
||||||
*dayp = day;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
@ -449,9 +450,7 @@ int QDate::year() const
|
|||||||
if (isNull())
|
if (isNull())
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
int y;
|
return getDateFromJulianDay(jd).year;
|
||||||
getDateFromJulianDay(jd, &y, 0, 0);
|
|
||||||
return y;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@ -483,9 +482,7 @@ int QDate::month() const
|
|||||||
if (isNull())
|
if (isNull())
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
int m;
|
return getDateFromJulianDay(jd).month;
|
||||||
getDateFromJulianDay(jd, 0, &m, 0);
|
|
||||||
return m;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@ -501,9 +498,7 @@ int QDate::day() const
|
|||||||
if (isNull())
|
if (isNull())
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
int d;
|
return getDateFromJulianDay(jd).day;
|
||||||
getDateFromJulianDay(jd, 0, 0, &d);
|
|
||||||
return d;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@ -555,12 +550,11 @@ int QDate::daysInMonth() const
|
|||||||
if (isNull())
|
if (isNull())
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
int y, m;
|
const ParsedDate pd = getDateFromJulianDay(jd);
|
||||||
getDateFromJulianDay(jd, &y, &m, 0);
|
if (pd.month == 2 && isLeapYear(pd.year))
|
||||||
if (m == 2 && isLeapYear(y))
|
|
||||||
return 29;
|
return 29;
|
||||||
else
|
else
|
||||||
return monthDays[m];
|
return monthDays[pd.month];
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@ -576,9 +570,7 @@ int QDate::daysInYear() const
|
|||||||
if (isNull())
|
if (isNull())
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
int y;
|
return isLeapYear(getDateFromJulianDay(jd).year) ? 366 : 365;
|
||||||
getDateFromJulianDay(jd, &y, 0, 0);
|
|
||||||
return isLeapYear(y) ? 366 : 365;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@ -895,7 +887,7 @@ QString QDate::toString(Qt::DateFormat format) const
|
|||||||
if (!isValid())
|
if (!isValid())
|
||||||
return QString();
|
return QString();
|
||||||
|
|
||||||
int y, m, d;
|
ParsedDate pd;
|
||||||
|
|
||||||
switch (format) {
|
switch (format) {
|
||||||
case Qt::SystemLocaleDate:
|
case Qt::SystemLocaleDate:
|
||||||
@ -913,19 +905,19 @@ QString QDate::toString(Qt::DateFormat format) const
|
|||||||
default:
|
default:
|
||||||
#ifndef QT_NO_TEXTDATE
|
#ifndef QT_NO_TEXTDATE
|
||||||
case Qt::TextDate:
|
case Qt::TextDate:
|
||||||
getDateFromJulianDay(jd, &y, &m, &d);
|
pd = getDateFromJulianDay(jd);
|
||||||
return QString::fromLatin1("%1 %2 %3 %4").arg(shortDayName(dayOfWeek()))
|
return QString::fromLatin1("%1 %2 %3 %4").arg(shortDayName(dayOfWeek()))
|
||||||
.arg(shortMonthName(m))
|
.arg(shortMonthName(pd.month))
|
||||||
.arg(d)
|
.arg(pd.day)
|
||||||
.arg(y);
|
.arg(pd.year);
|
||||||
#endif
|
#endif
|
||||||
case Qt::ISODate:
|
case Qt::ISODate:
|
||||||
getDateFromJulianDay(jd, &y, &m, &d);
|
pd = getDateFromJulianDay(jd);
|
||||||
if (y < 0 || y > 9999)
|
if (pd.year < 0 || pd.year > 9999)
|
||||||
return QString();
|
return QString();
|
||||||
return QString::fromLatin1("%1-%2-%3").arg(y, 4, 10, QLatin1Char('0'))
|
return QString::fromLatin1("%1-%2-%3").arg(pd.year, 4, 10, QLatin1Char('0'))
|
||||||
.arg(m, 2, 10, QLatin1Char('0'))
|
.arg(pd.month, 2, 10, QLatin1Char('0'))
|
||||||
.arg(d, 2, 10, QLatin1Char('0'));
|
.arg(pd.day, 2, 10, QLatin1Char('0'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1031,16 +1023,16 @@ bool QDate::setDate(int year, int month, int day)
|
|||||||
*/
|
*/
|
||||||
void QDate::getDate(int *year, int *month, int *day)
|
void QDate::getDate(int *year, int *month, int *day)
|
||||||
{
|
{
|
||||||
if (isValid()) {
|
ParsedDate pd = { 0, 0, 0 };
|
||||||
getDateFromJulianDay(jd, year, month, day);
|
if (isValid())
|
||||||
} else {
|
pd = getDateFromJulianDay(jd);
|
||||||
if (year)
|
|
||||||
*year = 0;
|
if (year)
|
||||||
if (month)
|
*year = pd.year;
|
||||||
*month = 0;
|
if (month)
|
||||||
if (day)
|
*month = pd.month;
|
||||||
*day = 0;
|
if (day)
|
||||||
}
|
*day = pd.day;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@ -1082,7 +1074,12 @@ QDate QDate::addMonths(int nmonths) const
|
|||||||
return *this;
|
return *this;
|
||||||
|
|
||||||
int old_y, y, m, d;
|
int old_y, y, m, d;
|
||||||
getDateFromJulianDay(jd, &y, &m, &d);
|
{
|
||||||
|
const ParsedDate pd = getDateFromJulianDay(jd);
|
||||||
|
y = pd.year;
|
||||||
|
m = pd.month;
|
||||||
|
d = pd.day;
|
||||||
|
}
|
||||||
old_y = y;
|
old_y = y;
|
||||||
|
|
||||||
bool increasing = nmonths > 0;
|
bool increasing = nmonths > 0;
|
||||||
@ -1140,19 +1137,18 @@ QDate QDate::addYears(int nyears) const
|
|||||||
if (!isValid())
|
if (!isValid())
|
||||||
return QDate();
|
return QDate();
|
||||||
|
|
||||||
int y, m, d;
|
ParsedDate pd = getDateFromJulianDay(jd);
|
||||||
getDateFromJulianDay(jd, &y, &m, &d);
|
|
||||||
|
|
||||||
int old_y = y;
|
int old_y = pd.year;
|
||||||
y += nyears;
|
pd.year += nyears;
|
||||||
|
|
||||||
// was there a sign change?
|
// was there a sign change?
|
||||||
if ((old_y > 0 && y <= 0) ||
|
if ((old_y > 0 && pd.year <= 0) ||
|
||||||
(old_y < 0 && y >= 0))
|
(old_y < 0 && pd.year >= 0))
|
||||||
// yes, adjust the date by +1 or -1 years
|
// yes, adjust the date by +1 or -1 years
|
||||||
y += nyears > 0 ? +1 : -1;
|
pd.year += nyears > 0 ? +1 : -1;
|
||||||
|
|
||||||
return fixedDate(y, m, d);
|
return fixedDate(pd.year, pd.month, pd.day);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
Loading…
Reference in New Issue
Block a user