Changeset View
Changeset View
Standalone View
Standalone View
src/lib/util/kformatprivate.cpp
Show First 20 Lines • Show All 356 Lines • ▼ Show 20 Line(s) | 356 | } else if (minutes) { | |||
---|---|---|---|---|---|
357 | return formatSingleDuration(Minutes, minutes); | 357 | return formatSingleDuration(Minutes, minutes); | ||
358 | } else { | 358 | } else { | ||
359 | return formatSingleDuration(Seconds, seconds); | 359 | return formatSingleDuration(Seconds, seconds); | ||
360 | } | 360 | } | ||
361 | } | 361 | } | ||
362 | 362 | | |||
363 | QString KFormatPrivate::formatRelativeDate(const QDate &date, QLocale::FormatType format) const | 363 | QString KFormatPrivate::formatRelativeDate(const QDate &date, QLocale::FormatType format) const | ||
364 | { | 364 | { | ||
365 | if (!date.isValid()) { | ||||
366 | return tr("Invalid date", "used when a relative date string can't be generated because the date is invalid"); | ||||
367 | } | ||||
368 | | ||||
365 | const int daysTo = QDate::currentDate().daysTo(date); | 369 | const int daysTo = QDate::currentDate().daysTo(date); | ||
366 | if (daysTo > 7 || daysTo < -7) { | 370 | if (daysTo > 7 || daysTo < -7) { | ||
367 | return m_locale.toString(date, format); | 371 | return m_locale.toString(date, format); | ||
368 | } | 372 | } | ||
369 | 373 | | |||
370 | switch (daysTo) { | 374 | switch (daysTo) { | ||
371 | case 1: | 375 | case 1: | ||
372 | return tr("Tomorrow"); | 376 | return tr("Tomorrow"); | ||
373 | case 0: | 377 | case 0: | ||
374 | return tr("Today"); | 378 | return tr("Today"); | ||
375 | case -1: | 379 | case -1: | ||
376 | return tr("Yesterday"); | 380 | return tr("Yesterday"); | ||
377 | } | 381 | } | ||
aspotashev: Needs a space: "switch (" | |||||
378 | 382 | | |||
aspotashev: Indentation of "case " lines is probably against the coding style. | |||||
379 | if (daysTo < -1) | 383 | if (daysTo < -1) { | ||
380 | /*: a day of the week, eg "Monday" (but translated). Refers to the most recent such day that | 384 | switch (date.dayOfWeek()) { | ||
381 | has already happened. */ | 385 | case 1: | ||
382 | { | 386 | return tr("Last Monday", "most recent such day before today"); | ||
383 | return tr("Last %1").arg(m_locale.dayName(date.dayOfWeek(), format)); | 387 | case 2: | ||
384 | } else if (daysTo > 1) | 388 | return tr("Last Tuesday", "most recent such day before today"); | ||
385 | /*: a day of the week, eg "Monday" (but translated). Refers to the soonest such day that | 389 | case 3: | ||
386 | has not already happened. */ | 390 | return tr("Last Wednesday", "most recent such day before today"); | ||
387 | { | 391 | case 4: | ||
388 | return tr("Next %1").arg(m_locale.dayName(date.dayOfWeek(), format)); | 392 | return tr("Last Thursday", "most recent such day before today"); | ||
393 | case 5: | ||||
394 | return tr("Last Friday", "most recent such day before today"); | ||||
395 | case 6: | ||||
396 | return tr("Last Saturday", "most recent such day before today"); | ||||
397 | case 7: | ||||
398 | return tr("Last Sunday", "most recent such day before today"); | ||||
399 | } | ||||
400 | } else if (daysTo > 1) { | ||||
http://doc.qt.io/qt-5/qdate.html#dayOfWeek says "Returns 0 if the date is invalid". What happens when the input date is invalid? aspotashev: http://doc.qt.io/qt-5/qdate.html#dayOfWeek says "Returns 0 if the date is invalid". What… | |||||
401 | switch (date.dayOfWeek()) { | ||||
402 | case 1: | ||||
403 | return tr("Next Monday", "the next such day after today"); | ||||
404 | case 2: | ||||
405 | return tr("Next Tuesday", "the next such day after today"); | ||||
406 | case 3: | ||||
407 | return tr("Next Wednesday", "the next such day after today"); | ||||
408 | case 4: | ||||
409 | return tr("Next Thursday", "the next such day after today"); | ||||
410 | case 5: | ||||
411 | return tr("Next Friday", "the next such day after today"); | ||||
412 | case 6: | ||||
413 | return tr("Next Saturday", "the next such day after today"); | ||||
414 | case 7: | ||||
415 | return tr("Next Sunday", "the next such day after today"); | ||||
416 | } | ||||
389 | } | 417 | } | ||
390 | Q_UNREACHABLE(); | 418 | Q_UNREACHABLE(); | ||
391 | } | 419 | } | ||
392 | 420 | | |||
393 | QString KFormatPrivate::formatRelativeDateTime(const QDateTime &dateTime, QLocale::FormatType format) const | 421 | QString KFormatPrivate::formatRelativeDateTime(const QDateTime &dateTime, QLocale::FormatType format) const | ||
394 | { | 422 | { | ||
395 | int daysTo = QDate::currentDate().daysTo(dateTime.date()); | 423 | int daysTo = QDate::currentDate().daysTo(dateTime.date()); | ||
396 | if (daysTo > 7 || daysTo < -7) { | 424 | if (daysTo > 7 || daysTo < -7) { | ||
397 | return m_locale.toString(dateTime, format); | 425 | return m_locale.toString(dateTime, format); | ||
398 | } | 426 | } | ||
399 | 427 | | |||
400 | /*: relative datetime with %1 result of formatReleativeDate() and %2 the formatted time | 428 | /*: relative datetime with %1 result of formatReleativeDate() and %2 the formatted time | ||
401 | If this does not fit the grammar of your language please contact the i18n team to solve the problem */ | 429 | If this does not fit the grammar of your language please contact the i18n team to solve the problem */ | ||
402 | return tr("%1, %2").arg(formatRelativeDate(dateTime.date(), format)) | 430 | return tr("%1, %2").arg(formatRelativeDate(dateTime.date(), format)) | ||
403 | .arg(m_locale.toString(dateTime.time(), format)); | 431 | .arg(m_locale.toString(dateTime.time(), format)); | ||
404 | } | 432 | } |
Needs a space: "switch ("