diff --git a/autotests/kformattest.cpp b/autotests/kformattest.cpp --- a/autotests/kformattest.cpp +++ b/autotests/kformattest.cpp @@ -351,34 +351,25 @@ QCOMPARE(format.formatRelativeDate(testDate, QLocale::ShortFormat), QStringLiteral("Yesterday")); QCOMPARE(format.formatRelativeDate(testDate, QLocale::NarrowFormat), QStringLiteral("Yesterday")); - // Relative dates within a week are up to translators but there's no - // expectation that day names are shortened -- per the API docs, the date - // format is only used when the date is outside the relative window - testDate = QDate::currentDate().addDays(-7); - QCOMPARE(format.formatRelativeDate(testDate, QLocale::LongFormat), - QStringLiteral("Last %1").arg(QLocale::c().dayName(testDate.dayOfWeek(), QLocale::LongFormat))); - QCOMPARE(format.formatRelativeDate(testDate, QLocale::ShortFormat), - QStringLiteral("Last %1").arg(QLocale::c().dayName(testDate.dayOfWeek(), QLocale::LongFormat))); - QCOMPARE(format.formatRelativeDate(testDate, QLocale::NarrowFormat), - QStringLiteral("Last %1").arg(QLocale::c().dayName(testDate.dayOfWeek(), QLocale::LongFormat))); + testDate = QDate::currentDate().addDays(2); + QCOMPARE(format.formatRelativeDate(testDate, QLocale::LongFormat), QStringLiteral("In two days")); + QCOMPARE(format.formatRelativeDate(testDate, QLocale::ShortFormat), QStringLiteral("In two days")); + QCOMPARE(format.formatRelativeDate(testDate, QLocale::NarrowFormat), QStringLiteral("In two days")); - testDate = QDate::currentDate().addDays(7); - QCOMPARE(format.formatRelativeDate(testDate, QLocale::LongFormat), - QStringLiteral("Next %1").arg(QLocale::c().dayName(testDate.dayOfWeek(), QLocale::LongFormat))); - QCOMPARE(format.formatRelativeDate(testDate, QLocale::ShortFormat), - QStringLiteral("Next %1").arg(QLocale::c().dayName(testDate.dayOfWeek(), QLocale::LongFormat))); - QCOMPARE(format.formatRelativeDate(testDate, QLocale::NarrowFormat), - QStringLiteral("Next %1").arg(QLocale::c().dayName(testDate.dayOfWeek(), QLocale::LongFormat))); + testDate = QDate::currentDate().addDays(-2); + QCOMPARE(format.formatRelativeDate(testDate, QLocale::LongFormat), QStringLiteral("Two days ago")); + QCOMPARE(format.formatRelativeDate(testDate, QLocale::ShortFormat), QStringLiteral("Two days ago")); + QCOMPARE(format.formatRelativeDate(testDate, QLocale::NarrowFormat), QStringLiteral("Two days ago")); - testDate = QDate::currentDate().addDays(-8); + testDate = QDate::currentDate().addDays(-3); QCOMPARE(format.formatRelativeDate(testDate, QLocale::LongFormat), QLocale::c().toString(testDate, QLocale::LongFormat)); QCOMPARE(format.formatRelativeDate(testDate, QLocale::ShortFormat), QLocale::c().toString(testDate, QLocale::ShortFormat)); QCOMPARE(format.formatRelativeDate(testDate, QLocale::NarrowFormat), QLocale::c().toString(testDate, QLocale::NarrowFormat)); - testDate = QDate::currentDate().addDays(8); + testDate = QDate::currentDate().addDays(3); QCOMPARE(format.formatRelativeDate(testDate, QLocale::LongFormat), QLocale::c().toString(testDate, QLocale::LongFormat)); QCOMPARE(format.formatRelativeDate(testDate, QLocale::ShortFormat), diff --git a/src/lib/util/kformatprivate.cpp b/src/lib/util/kformatprivate.cpp --- a/src/lib/util/kformatprivate.cpp +++ b/src/lib/util/kformatprivate.cpp @@ -510,61 +510,29 @@ } const qint64 daysTo = QDate::currentDate().daysTo(date); - if (daysTo > 7 || daysTo < -7) { + if (daysTo > 2 || daysTo < -2) { return m_locale.toString(date, format); } switch (daysTo) { + case 2: + return tr("In two days"); case 1: return tr("Tomorrow"); case 0: return tr("Today"); case -1: return tr("Yesterday"); - } - - if (daysTo < -1) { - switch (date.dayOfWeek()) { - case 1: - return tr("Last Monday", "most recent such day before today"); - case 2: - return tr("Last Tuesday", "most recent such day before today"); - case 3: - return tr("Last Wednesday", "most recent such day before today"); - case 4: - return tr("Last Thursday", "most recent such day before today"); - case 5: - return tr("Last Friday", "most recent such day before today"); - case 6: - return tr("Last Saturday", "most recent such day before today"); - case 7: - return tr("Last Sunday", "most recent such day before today"); - } - } else if (daysTo > 1) { - switch (date.dayOfWeek()) { - case 1: - return tr("Next Monday", "the next such day after today"); - case 2: - return tr("Next Tuesday", "the next such day after today"); - case 3: - return tr("Next Wednesday", "the next such day after today"); - case 4: - return tr("Next Thursday", "the next such day after today"); - case 5: - return tr("Next Friday", "the next such day after today"); - case 6: - return tr("Next Saturday", "the next such day after today"); - case 7: - return tr("Next Sunday", "the next such day after today"); - } + case -2: + return tr("Two days ago"); } Q_UNREACHABLE(); } QString KFormatPrivate::formatRelativeDateTime(const QDateTime &dateTime, QLocale::FormatType format) const { const qint64 daysTo = QDate::currentDate().daysTo(dateTime.date()); - if (daysTo > 7 || daysTo < -7) { + if (daysTo > 2 || daysTo < -2) { return m_locale.toString(dateTime, format); }