Changeset View
Changeset View
Standalone View
Standalone View
applets/digital-clock/package/contents/ui/CalendarView.qml
Show First 20 Lines • Show All 145 Lines • ▼ Show 20 Line(s) | 143 | function formatDateWithoutYear(date) { | |||
---|---|---|---|---|---|
146 | // formats, with its dumb version that only supports Qt::DateFormat | 146 | // formats, with its dumb version that only supports Qt::DateFormat | ||
147 | // enum subset. So to get a day-and-month-only date format string we | 147 | // enum subset. So to get a day-and-month-only date format string we | ||
148 | // must resort to this magic and hope there are no locales that use | 148 | // must resort to this magic and hope there are no locales that use | ||
149 | // other separators... | 149 | // other separators... | ||
150 | var format = Qt.locale().dateFormat(Locale.ShortFormat).replace(/[./ ]*Y{2,4}[./ ]*/i, ''); | 150 | var format = Qt.locale().dateFormat(Locale.ShortFormat).replace(/[./ ]*Y{2,4}[./ ]*/i, ''); | ||
151 | return Qt.formatDate(date, format); | 151 | return Qt.formatDate(date, format); | ||
152 | } | 152 | } | ||
153 | 153 | | |||
154 | function dateEquals(date1, date2) { | ||||
broulik: Can't you do `date1.getTime() == date2.getTime()` (`time` returns the msecs since epoch) | |||||
epopov: How can I compare only the date using your expression? | |||||
155 | var values1 = [ | ||||
156 | date1.getFullYear(), | ||||
157 | date1.getMonth(), | ||||
158 | date1.getDate() | ||||
159 | ]; | ||||
160 | | ||||
161 | var values2 = [ | ||||
162 | date2.getFullYear(), | ||||
163 | date2.getMonth(), | ||||
164 | date2.getDate() | ||||
165 | ]; | ||||
166 | | ||||
167 | return values1.every((value, index) => { | ||||
168 | return (value === values2[index]); | ||||
169 | }, false) | ||||
170 | } | ||||
171 | | ||||
154 | Connections { | 172 | Connections { | ||
155 | target: monthView | 173 | target: monthView | ||
156 | 174 | | |||
157 | onCurrentDateChanged: { | 175 | onCurrentDateChanged: { | ||
158 | // Apparently this is needed because this is a simple QList being | 176 | // Apparently this is needed because this is a simple QList being | ||
159 | // returned and if the list for the current day has 1 event and the | 177 | // returned and if the list for the current day has 1 event and the | ||
160 | // user clicks some other date which also has 1 event, QML sees the | 178 | // user clicks some other date which also has 1 event, QML sees the | ||
161 | // sizes match and does not update the labels with the content. | 179 | // sizes match and does not update the labels with the content. | ||
162 | // Resetting the model to null first clears it and then correct data | 180 | // Resetting the model to null first clears it and then correct data | ||
163 | // are displayed. | 181 | // are displayed. | ||
164 | holidaysList.model = null; | 182 | holidaysList.model = null; | ||
165 | holidaysList.model = monthView.daysModel.eventsForDate(monthView.currentDate); | 183 | holidaysList.model = monthView.daysModel.eventsForDate(monthView.currentDate); | ||
166 | } | 184 | } | ||
167 | } | 185 | } | ||
168 | 186 | | |||
169 | Connections { | 187 | Connections { | ||
170 | target: monthView.daysModel | 188 | target: monthView.daysModel | ||
171 | 189 | | |||
172 | onAgendaUpdated: { | 190 | onAgendaUpdated: { | ||
173 | // Checks if the dates are the same, comparing the date objects | 191 | if (agenda.dateEquals(updatedDate, monthView.currentDate)) { | ||
174 | // directly won't work and this does a simple integer subtracting | | |||
175 | // so should be fastest. One of the JS weirdness. | | |||
176 | if (updatedDate - monthView.currentDate === 0) { | | |||
177 | holidaysList.model = null; | 192 | holidaysList.model = null; | ||
178 | holidaysList.model = monthView.daysModel.eventsForDate(monthView.currentDate); | 193 | holidaysList.model = monthView.daysModel.eventsForDate(monthView.currentDate); | ||
179 | } | 194 | } | ||
180 | } | 195 | } | ||
181 | } | 196 | } | ||
182 | 197 | | |||
183 | Connections { | 198 | Connections { | ||
184 | target: plasmoid.configuration | 199 | target: plasmoid.configuration | ||
▲ Show 20 Lines • Show All 299 Lines • Show Last 20 Lines |
Can't you do date1.getTime() == date2.getTime() (time returns the msecs since epoch)