Changeset View
Changeset View
Standalone View
Standalone View
src/lib/util/kformatprivate.cpp
Show First 20 Lines • Show All 504 Lines • ▼ Show 20 Line(s) | |||||
505 | 505 | | |||
506 | QString KFormatPrivate::formatRelativeDate(const QDate &date, QLocale::FormatType format) const | 506 | QString KFormatPrivate::formatRelativeDate(const QDate &date, QLocale::FormatType format) const | ||
507 | { | 507 | { | ||
508 | if (!date.isValid()) { | 508 | if (!date.isValid()) { | ||
509 | return tr("Invalid date", "used when a relative date string can't be generated because the date is invalid"); | 509 | return tr("Invalid date", "used when a relative date string can't be generated because the date is invalid"); | ||
510 | } | 510 | } | ||
511 | 511 | | |||
512 | const qint64 daysTo = QDate::currentDate().daysTo(date); | 512 | const qint64 daysTo = QDate::currentDate().daysTo(date); | ||
513 | if (daysTo > 7 || daysTo < -7) { | 513 | if (daysTo > 2 || daysTo < -2) { | ||
514 | return m_locale.toString(date, format); | 514 | return m_locale.toString(date, format); | ||
515 | } | 515 | } | ||
516 | 516 | | |||
517 | switch (daysTo) { | 517 | switch (daysTo) { | ||
518 | case 2: | ||||
519 | return tr("In two days"); | ||||
518 | case 1: | 520 | case 1: | ||
519 | return tr("Tomorrow"); | 521 | return tr("Tomorrow"); | ||
520 | case 0: | 522 | case 0: | ||
521 | return tr("Today"); | 523 | return tr("Today"); | ||
522 | case -1: | 524 | case -1: | ||
523 | return tr("Yesterday"); | 525 | return tr("Yesterday"); | ||
524 | } | 526 | case -2: | ||
525 | 527 | return tr("Two days ago"); | |||
526 | if (daysTo < -1) { | | |||
527 | switch (date.dayOfWeek()) { | | |||
528 | case 1: | | |||
529 | return tr("Last Monday", "most recent such day before today"); | | |||
530 | case 2: | | |||
531 | return tr("Last Tuesday", "most recent such day before today"); | | |||
532 | case 3: | | |||
533 | return tr("Last Wednesday", "most recent such day before today"); | | |||
534 | case 4: | | |||
535 | return tr("Last Thursday", "most recent such day before today"); | | |||
536 | case 5: | | |||
537 | return tr("Last Friday", "most recent such day before today"); | | |||
538 | case 6: | | |||
539 | return tr("Last Saturday", "most recent such day before today"); | | |||
540 | case 7: | | |||
541 | return tr("Last Sunday", "most recent such day before today"); | | |||
542 | } | | |||
543 | } else if (daysTo > 1) { | | |||
544 | switch (date.dayOfWeek()) { | | |||
545 | case 1: | | |||
546 | return tr("Next Monday", "the next such day after today"); | | |||
547 | case 2: | | |||
548 | return tr("Next Tuesday", "the next such day after today"); | | |||
549 | case 3: | | |||
550 | return tr("Next Wednesday", "the next such day after today"); | | |||
551 | case 4: | | |||
552 | return tr("Next Thursday", "the next such day after today"); | | |||
553 | case 5: | | |||
554 | return tr("Next Friday", "the next such day after today"); | | |||
555 | case 6: | | |||
556 | return tr("Next Saturday", "the next such day after today"); | | |||
557 | case 7: | | |||
558 | return tr("Next Sunday", "the next such day after today"); | | |||
559 | } | | |||
560 | } | 528 | } | ||
561 | Q_UNREACHABLE(); | 529 | Q_UNREACHABLE(); | ||
562 | } | 530 | } | ||
563 | 531 | | |||
564 | QString KFormatPrivate::formatRelativeDateTime(const QDateTime &dateTime, QLocale::FormatType format) const | 532 | QString KFormatPrivate::formatRelativeDateTime(const QDateTime &dateTime, QLocale::FormatType format) const | ||
565 | { | 533 | { | ||
566 | const qint64 daysTo = QDate::currentDate().daysTo(dateTime.date()); | 534 | const qint64 daysTo = QDate::currentDate().daysTo(dateTime.date()); | ||
567 | if (daysTo > 7 || daysTo < -7) { | 535 | if (daysTo > 2 || daysTo < -2) { | ||
568 | return m_locale.toString(dateTime, format); | 536 | return m_locale.toString(dateTime, format); | ||
569 | } | 537 | } | ||
570 | 538 | | |||
571 | /*: relative datetime with %1 result of formatReleativeDate() and %2 the formatted time | 539 | /*: relative datetime with %1 result of formatReleativeDate() and %2 the formatted time | ||
572 | If this does not fit the grammar of your language please contact the i18n team to solve the problem */ | 540 | If this does not fit the grammar of your language please contact the i18n team to solve the problem */ | ||
573 | return tr("%1, %2").arg(formatRelativeDate(dateTime.date(), format), m_locale.toString(dateTime.time(), format)); | 541 | return tr("%1, %2").arg(formatRelativeDate(dateTime.date(), format), m_locale.toString(dateTime.time(), format)); | ||
574 | } | 542 | } |