mirror of
https://codeberg.org/vyn/mirai.git
synced 2025-07-01 17:03:19 +00:00
Add hint to show how many days left relative to today
This commit is contained in:
parent
53b1280115
commit
534da46a26
4 changed files with 33 additions and 13 deletions
|
@ -25,6 +25,15 @@ struct Date {
|
|||
bool operator<(const Date &other) const;
|
||||
bool operator>(const Date &other) const;
|
||||
|
||||
std::chrono::year_month_day toStdChrono() const
|
||||
{
|
||||
return std::chrono::year_month_day{
|
||||
std::chrono::year(year),
|
||||
std::chrono::month(month),
|
||||
std::chrono::day(day),
|
||||
};
|
||||
}
|
||||
|
||||
int year;
|
||||
unsigned month;
|
||||
unsigned day;
|
||||
|
|
|
@ -223,7 +223,7 @@ void UiState::setupUtilsCallbacks()
|
|||
std::chrono::month(date.month),
|
||||
std::chrono::day(date.day),
|
||||
};
|
||||
return std::format("{:%d %B}", chronoDate);
|
||||
return std::format("{:%B %d}", chronoDate);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -361,15 +361,21 @@ void UiState::reloadTasks()
|
|||
auto ¤tDay = view_[dayIndex];
|
||||
auto slintEvents = std::make_shared<slint::VectorModel<Event>>();
|
||||
auto slintDayTasks = std::make_shared<slint::VectorModel<TaskData>>();
|
||||
slintDays->push_back(Day{
|
||||
.sourceId = currentDay.day->source()->id(),
|
||||
.id = dayIndex,
|
||||
.date = MiraiDateToSlintDate(currentDay.day->getDate()),
|
||||
.events = slintEvents,
|
||||
.tasks = slintDayTasks,
|
||||
.isLate = currentDay.day->getDate() < todayDate,
|
||||
.isToday = currentDay.day->getDate() == todayDate,
|
||||
});
|
||||
auto relativeDaysDiff = std::chrono::duration_cast<std::chrono::days>(
|
||||
std::chrono::sys_days(currentDay.day->getDate().toStdChrono()) -
|
||||
std::chrono::sys_days(todayDate.toStdChrono())
|
||||
)
|
||||
.count();
|
||||
slintDays->push_back(
|
||||
Day{.sourceId = currentDay.day->source()->id(),
|
||||
.id = dayIndex,
|
||||
.date = MiraiDateToSlintDate(currentDay.day->getDate()),
|
||||
.events = slintEvents,
|
||||
.tasks = slintDayTasks,
|
||||
.isLate = currentDay.day->getDate() < todayDate,
|
||||
.isToday = currentDay.day->getDate() == todayDate,
|
||||
.relativeDaysDiff = static_cast<int>(relativeDaysDiff)}
|
||||
);
|
||||
for (int taskIndex = 0; taskIndex < currentDay.filteredTasks.size(); ++taskIndex) {
|
||||
auto &task = currentDay.filteredTasks.at(taskIndex);
|
||||
std::vector<slint::SharedString> tags;
|
||||
|
|
|
@ -26,7 +26,8 @@ export struct Day {
|
|||
events: [Event],
|
||||
tasks: [TaskData],
|
||||
isLate: bool,
|
||||
isToday: bool
|
||||
isToday: bool,
|
||||
relativeDaysDiff: int
|
||||
}
|
||||
|
||||
struct OpenNewTaskFormParams {
|
||||
|
|
|
@ -80,10 +80,14 @@ export component MainView inherits Rectangle {
|
|||
color: day.isLate ? Palette.orange : Palette.foreground;
|
||||
font-size: 1.2rem;
|
||||
}
|
||||
if day.isToday : VerticalLayout {
|
||||
VerticalLayout {
|
||||
alignment: center;
|
||||
VText {
|
||||
text: " - Today";
|
||||
text: day.relativeDaysDiff == 0 ? " - today" :
|
||||
day.relativeDaysDiff == 1 ? " - tomorrow" :
|
||||
day.relativeDaysDiff == -1 ? " - yesterday" :
|
||||
day.relativeDaysDiff > 0 ? " - in \{day.relativeDaysDiff} days" :
|
||||
" - \{-day.relativeDaysDiff} days ago";
|
||||
color: Palette.foreground-hint;
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue