Commit 52eacd23 authored by Claudio Cambra's avatar Claudio Cambra
Browse files

Fix 'smart' section date labels for due date sort



Signed-off-by: Claudio Cambra's avatarClaudio Cambra <claudio.cambra@gmail.com>
parent 15550b33
Pipeline #236355 failed with stage
in 1 minute and 59 seconds
......@@ -210,26 +210,26 @@ function getIncidenceLabelColor(background, darkMode) {
function todoDateTimeLabel(datetime, allDay, completed) {
if(!isNaN(datetime.getTime())) {
let now = new Date();
let dateFormat = datetime.getFullYear() == now.getFullYear() ? "dddd dd MMMM" : "dddd dd MMMM yyyy";
let dateString = datetime.toLocaleDateString(Qt.locale(), dateFormat);
let timeString = allDay === true ?
" " :
i18nc("%1 is the time, spaces included to allow use of 'empty' string when an event is allday and has no time", " at %1 ", datetime.toLocaleTimeString(Qt.locale(), 1));
const now = new Date();
const dateFormat = datetime.getFullYear() == now.getFullYear() ? "dddd dd MMMM" : "dddd dd MMMM yyyy";
const dateString = datetime.toLocaleDateString(Qt.locale(), dateFormat);
const timeString = allDay === true ? " " :
i18nc("%1 is the time, spaces included to allow use of 'empty' string when an event is allday and has no time", " at %1 ", datetime.toLocaleTimeString(Qt.locale(), 1));
if(DateUtils.sameDay(datetime, now)) {
return (datetime < now) && !completed && !allDay ?
i18nc("No space since the %1 string, which includes the time (or not), includes this space", "Today%1(overdue)", timeString) :
i18nc("No space since the %1 string, which includes the time (or not), includes this space", "Today%1", timeString);
return datetime < now && !completed && !allDay ?
i18nc("No space since the %1 string, which includes the time (or not), includes this space", "Today%1(overdue)", timeString) :
i18nc("No space since the %1 string, which includes the time (or not), includes this space", "Today%1", timeString);
} else if(DateUtils.sameDay(DateUtils.addDaysToDate(datetime, - 1), now)) { // Tomorrow
return i18nc("No space since the %1 string, which includes the time (or not), includes this space", "Tomorrow%1", timeString);
} else if(DateUtils.sameDay(DateUtils.addDaysToDate(datetime, 1), now)) { // Yesterday
return !completed ?
i18nc("No space since the %1 string, which includes the time (or not), includes this space", "Yesterday%1(overdue)", timeString) :
i18nc("No space since the %1 string, which includes the time (or not), includes this space", "Yesterday");
i18nc("No space since the %1 string, which includes the time (or not), includes this space", "Yesterday%1(overdue)", timeString) :
i18nc("No space since the %1 string, which includes the time (or not), includes this space", "Yesterday");
}
return datetime < now && !completed ? dateString + timeString + i18n("(overdue)") : dateString + timeString;
const dateAndTime = dateString + timeString
return datetime < now && !completed ? dateAndTime + i18n("(overdue)") : dateAndTime;
} else {
return "";
}
......
......@@ -67,21 +67,24 @@ TreeListView {
activeFocusOnTab: false
contentItem: Kirigami.Heading {
readonly property bool dateSort: root.sortBy === Kalendar.TodoSortFilterProxyModel.DueDateColumn
readonly property date sectionDate: dateSort ? new Date(section) : null
readonly property bool sectionDateValid: dateSort && !isNaN(sectionDate.getTime());
readonly property bool isOverdue: dateSort && section === i18n("Overdue")
readonly property bool isToday: dateSort && section === i18n("Today")
text: {
switch(sortBy) {
switch(root.sortBy) {
case Kalendar.TodoSortFilterProxyModel.PriorityColumn:
return section !== "--" ? i18n("Priority %1", section) : i18n("No set priority");
case Kalendar.TodoSortFilterProxyModel.DueDateColumn:
let sectionDate = new Date(section);
return !isNaN(sectionDate.getTime()) ? LabelUtils.todoDateTimeLabel(new Date(section), true, false) : section;
// We sometimes return non-date strings from the model for overdue/no set due date
return sectionDateValid ? LabelUtils.todoDateTimeLabel(sectionDate, true, false) : section;
case Kalendar.TodoSortFilterProxyModel.SummaryColumn:
default:
return section;
}
}
readonly property bool isOverdue: section === i18n("Overdue")
readonly property bool isToday: DateUtils.sameDay(new Date(section), new Date())
level: 3
font.weight: Font.Bold
......
......@@ -160,9 +160,21 @@ QVariant TodoSortFilterProxyModel::data(const QModelIndex &index, int role) cons
case TopMostParentSummary:
return todo->summary();
case TopMostParentDueDate: {
bool isOverdue = (todo->hasDueDate() && todo->dtDue().date() < QDate::currentDate() && todo->allDay())
|| (todo->hasDueDate() && todo->dtDue() < QDateTime::currentDateTime() && !todo->allDay());
return isOverdue ? i18n("Overdue") : todo->hasDueDate() ? QLocale::system().toString(todo->dtDue().date()) : i18n("No set date");
if (!todo->hasDueDate()) {
return i18n("No set date");
}
const auto isOverdue =
(todo->allDay() && todo->dtDue().date() < QDate::currentDate()) || (!todo->allDay() && todo->dtDue() < QDateTime::currentDateTime());
if (isOverdue) {
return i18n("Overdue");
}
const auto dateInCurrentTZ = todo->dtDue().toLocalTime().date();
const auto isToday = dateInCurrentTZ == QDate::currentDate();
return isToday ? i18n("Today") : todo->dtDue().toString();
}
case TopMostParentPriority:
return todo->priority();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment