[Calendar] Wrap day name index around
ClosedPublic

Authored by broulik on Sep 6 2018, 7:25 AM.

Details

Summary

Otherwise when the week starts on a day other than Sunday or Monday we access invalid day names.

BUG: 390330

Test Plan

TIL there's locales where weeks start on a Saturday :)
Ran LC_TIME=ar_EG plasmawindowed org.kde.plasma.digitalclock and hat all weekdays shown properly. Previously it would only show Saturday and Sunday headings

  • Verified that en_US locale where week starts on a Sunday still works
  • Verified that de_DE locale where week starts on a Monday still works

Diff Detail

Repository
R242 Plasma Framework (Library)
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
broulik created this revision.Sep 6 2018, 7:25 AM
Restricted Application added a project: Frameworks. · View Herald TranscriptSep 6 2018, 7:25 AM
Restricted Application added a subscriber: kde-frameworks-devel. · View Herald Transcript
broulik requested review of this revision.Sep 6 2018, 7:25 AM
broulik added a reviewer: Zren.
broulik edited the test plan for this revision. (Show Details)Sep 6 2018, 7:30 AM

I thought that this is a feature/cool look :D
Thanks a lot!

This revision was not accepted when it landed; it landed in state Needs Review.Sep 6 2018, 10:43 AM
This revision was automatically updated to reflect the committed changes.
Zren added a comment.Sep 6 2018, 10:23 PM

Nice thinking on using repeater.count instead of the hardcoded 7!

Hmm, was worried days.count would trigger onCountChanged every time a delegate is made (count=1, count=2, etc), but it seems that the delegate.text is only calculated twice (delegate creation and after onCountChanged=7).
For reference, before the patch, it only calculates the delegate.text once. Using a hardcoded 7 also only calls it once, but it's bad practice to have magic numbers. I assume it won't reattempt to render the labels since the text didn't change.

Thanks for doing the patch broulik.

qml: days.count 0
Both point size and pixel size set. Using pixel size.
qml: days.delegate.text 0 Sun
Both point size and pixel size set. Using pixel size.
qml: days.delegate.text 1 Mon
Both point size and pixel size set. Using pixel size.
qml: days.delegate.text 2 Tue
Both point size and pixel size set. Using pixel size.
qml: days.delegate.text 3 Wed
Both point size and pixel size set. Using pixel size.
qml: days.delegate.text 4 Thu
Both point size and pixel size set. Using pixel size.
qml: days.delegate.text 5 Fri
Both point size and pixel size set. Using pixel size.
qml: days.delegate.text 6 Sat
Both point size and pixel size set. Using pixel size.
qml: days.count 7
qml: days.delegate.text 0 Sun
qml: days.delegate.text 1 Mon
qml: days.delegate.text 2 Tue
qml: days.delegate.text 3 Wed
qml: days.delegate.text 4 Thu
qml: days.delegate.text 5 Fri
qml: days.delegate.text 6 Sat
Repeater {
    id: days
    onCountChanged: console.log('days.count', count)

    Components.Label {
        text: {
            var s = Qt.locale(Qt.locale().uiLanguages[0]).dayName((calendarBackend.firstDayOfWeek + index) % 7, Locale.ShortFormat)
            console.log('days.delegate.text', index, s)
            return s
        }