Merge integration refs/builds/qtci/dev/1618397939
This commit is contained in:
commit
fb0fcd7fe3
@ -361,6 +361,11 @@ static QByteArray parseTzPosixRule(QDataStream &ds)
|
|||||||
|
|
||||||
static QDate calculateDowDate(int year, int month, int dayOfWeek, int week)
|
static QDate calculateDowDate(int year, int month, int dayOfWeek, int week)
|
||||||
{
|
{
|
||||||
|
if (dayOfWeek == 0) // Sunday; we represent it as 7, POSIX uses 0
|
||||||
|
dayOfWeek = 7;
|
||||||
|
else if (dayOfWeek & ~7 || month < 1 || month > 12 || week < 1 || week > 5)
|
||||||
|
return QDate();
|
||||||
|
|
||||||
QDate date(year, month, 1);
|
QDate date(year, month, 1);
|
||||||
int startDow = date.dayOfWeek();
|
int startDow = date.dayOfWeek();
|
||||||
if (startDow <= dayOfWeek)
|
if (startDow <= dayOfWeek)
|
||||||
@ -375,28 +380,34 @@ static QDate calculateDowDate(int year, int month, int dayOfWeek, int week)
|
|||||||
|
|
||||||
static QDate calculatePosixDate(const QByteArray &dateRule, int year)
|
static QDate calculatePosixDate(const QByteArray &dateRule, int year)
|
||||||
{
|
{
|
||||||
|
bool ok;
|
||||||
// Can start with M, J, or a digit
|
// Can start with M, J, or a digit
|
||||||
if (dateRule.at(0) == 'M') {
|
if (dateRule.at(0) == 'M') {
|
||||||
// nth week in month format "Mmonth.week.dow"
|
// nth week in month format "Mmonth.week.dow"
|
||||||
QList<QByteArray> dateParts = dateRule.split('.');
|
QList<QByteArray> dateParts = dateRule.split('.');
|
||||||
int month = dateParts.at(0).mid(1).toInt();
|
if (dateParts.count() > 2) {
|
||||||
int week = dateParts.at(1).toInt();
|
int month = dateParts.at(0).mid(1).toInt(&ok);
|
||||||
int dow = dateParts.at(2).toInt();
|
int week = ok ? dateParts.at(1).toInt(&ok) : 0;
|
||||||
if (dow == 0) // Sunday; we represent it as 7
|
int dow = ok ? dateParts.at(2).toInt(&ok) : 0;
|
||||||
dow = 7;
|
if (ok)
|
||||||
return calculateDowDate(year, month, dow, week);
|
return calculateDowDate(year, month, dow, week);
|
||||||
|
}
|
||||||
} else if (dateRule.at(0) == 'J') {
|
} else if (dateRule.at(0) == 'J') {
|
||||||
// Day of Year ignores Feb 29
|
// Day of Year ignores Feb 29
|
||||||
int doy = dateRule.mid(1).toInt();
|
int doy = dateRule.mid(1).toInt(&ok);
|
||||||
QDate date = QDate(year, 1, 1).addDays(doy - 1);
|
if (ok && doy > 0 && doy < 366) {
|
||||||
if (QDate::isLeapYear(date.year()))
|
QDate date = QDate(year, 1, 1).addDays(doy - 1);
|
||||||
date = date.addDays(-1);
|
if (QDate::isLeapYear(date.year()) && date.month() > 2)
|
||||||
return date;
|
date = date.addDays(-1);
|
||||||
|
return date;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// Day of Year includes Feb 29
|
// Day of Year includes Feb 29
|
||||||
int doy = dateRule.toInt();
|
int doy = dateRule.toInt(&ok);
|
||||||
return QDate(year, 1, 1).addDays(doy - 1);
|
if (ok && doy > 0 && doy <= 366)
|
||||||
|
return QDate(year, 1, 1).addDays(doy - 1);
|
||||||
}
|
}
|
||||||
|
return QDate();
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns the time in seconds, INT_MIN if we failed to parse
|
// returns the time in seconds, INT_MIN if we failed to parse
|
||||||
@ -586,7 +597,8 @@ static QList<QTimeZonePrivate::Data> calculatePosixTransitions(const QByteArray
|
|||||||
result << data;
|
result << data;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
if (parts.count() < 3 || parts.at(1).isEmpty() || parts.at(2).isEmpty())
|
||||||
|
return result; // Malformed.
|
||||||
|
|
||||||
// Get the std to dst transtion details
|
// Get the std to dst transtion details
|
||||||
QList<QByteArray> dstParts = parts.at(1).split('/');
|
QList<QByteArray> dstParts = parts.at(1).split('/');
|
||||||
@ -606,6 +618,9 @@ static QList<QTimeZonePrivate::Data> calculatePosixTransitions(const QByteArray
|
|||||||
else
|
else
|
||||||
stdTime = QTime(2, 0, 0);
|
stdTime = QTime(2, 0, 0);
|
||||||
|
|
||||||
|
if (dstDateRule.isEmpty() || stdDateRule.isEmpty() || !dstTime.isValid() || !stdTime.isValid())
|
||||||
|
return result; // Malformed.
|
||||||
|
|
||||||
// Limit year to the range QDateTime can represent:
|
// Limit year to the range QDateTime can represent:
|
||||||
const int minYear = int(QDateTime::YearRange::First);
|
const int minYear = int(QDateTime::YearRange::First);
|
||||||
const int maxYear = int(QDateTime::YearRange::Last);
|
const int maxYear = int(QDateTime::YearRange::Last);
|
||||||
|
@ -67,6 +67,7 @@ private Q_SLOTS:
|
|||||||
void isValidId_data();
|
void isValidId_data();
|
||||||
void isValidId();
|
void isValidId();
|
||||||
void serialize();
|
void serialize();
|
||||||
|
void malformed();
|
||||||
// Backend tests
|
// Backend tests
|
||||||
void utcTest();
|
void utcTest();
|
||||||
void icuTest();
|
void icuTest();
|
||||||
@ -986,6 +987,21 @@ void tst_QTimeZone::serialize()
|
|||||||
QSKIP("No serialization enabled");
|
QSKIP("No serialization enabled");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tst_QTimeZone::malformed()
|
||||||
|
{
|
||||||
|
// Regression test for QTBUG-92808
|
||||||
|
// Strings that look enough like a POSIX zone specifier that the constructor
|
||||||
|
// accepts them, but the specifier is invalid.
|
||||||
|
// Must not crash or trigger assertions when calling offsetFromUtc()
|
||||||
|
const QDateTime now = QDateTime::currentDateTime();
|
||||||
|
QTimeZone barf("QUT4tCZ0 , /");
|
||||||
|
if (barf.isValid())
|
||||||
|
barf.offsetFromUtc(now);
|
||||||
|
barf = QTimeZone("QtC+09,,MA");
|
||||||
|
if (barf.isValid())
|
||||||
|
barf.offsetFromUtc(now);
|
||||||
|
}
|
||||||
|
|
||||||
void tst_QTimeZone::utcTest()
|
void tst_QTimeZone::utcTest()
|
||||||
{
|
{
|
||||||
#ifdef QT_BUILD_INTERNAL
|
#ifdef QT_BUILD_INTERNAL
|
||||||
|
Loading…
x
Reference in New Issue
Block a user