-
-
Notifications
You must be signed in to change notification settings - Fork 264
Add options for 5 days, 7 days, and work week #893
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
CampAsAChamp
wants to merge
1
commit into
leits:master
Choose a base branch
from
CampAsAChamp:feature/event-and-statusbar-improvements
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -321,6 +321,33 @@ final class StatusBarItemController { | |
| * ------------------------ | ||
| */ | ||
|
|
||
| /// Returns the start-of-day dates for each day in the given period, from today (or next Monday for work week on weekend). | ||
| private static func daysInPeriod(_ period: ShowEventsForPeriod, from today: Date, calendar: Calendar) -> [Date] { | ||
| switch period { | ||
| case .fiveDays: | ||
| return (0 ..< 5).map { calendar.date(byAdding: .day, value: $0, to: today)! } | ||
| case .sevenDays: | ||
| return (0 ..< 7).map { calendar.date(byAdding: .day, value: $0, to: today)! } | ||
| case .workWeek: | ||
| let weekday = calendar.component(.weekday, from: today) // 1 = Sunday, 7 = Saturday | ||
| if weekday == 1 { | ||
| // Sunday: next week Mon–Fri | ||
| let nextMonday = calendar.date(byAdding: .day, value: 1, to: today)! | ||
| return (0 ..< 5).map { calendar.date(byAdding: .day, value: $0, to: nextMonday)! } | ||
| } else if weekday == 7 { | ||
| // Saturday: next week Mon–Fri | ||
| let nextMonday = calendar.date(byAdding: .day, value: 2, to: today)! | ||
| return (0 ..< 5).map { calendar.date(byAdding: .day, value: $0, to: nextMonday)! } | ||
| } else { | ||
| // Monday (2) through Friday (6): today through Friday | ||
| let daysUntilFriday = 6 - weekday | ||
| return (0 ... daysUntilFriday).map { calendar.date(byAdding: .day, value: $0, to: today)! } | ||
| } | ||
| case .today, .today_n_tomorrow: | ||
| return [today] | ||
| } | ||
| } | ||
|
|
||
| func updateMenu() { | ||
| // Don't update the menu while it's open to avoid flickering | ||
| if statusItem.menu != nil { | ||
|
|
@@ -368,6 +395,27 @@ final class StatusBarItemController { | |
| let tomorrowEvents = events.filter { Calendar.current.isDate($0.startDate, inSameDayAs: tomorrow) } | ||
| statusItemMenu.items += builder.buildDateSection(date: tomorrow, title: "status_bar_section_tomorrow".loco(), events: tomorrowEvents) | ||
|
|
||
| case .fiveDays, .sevenDays, .workWeek: | ||
| let calendar = Calendar.current | ||
| let dayDates = Self.daysInPeriod(Defaults[.showEventsForPeriod], from: today, calendar: calendar) | ||
| let dateFormatter = DateFormatter() | ||
| dateFormatter.dateFormat = "E, d MMM" | ||
| dateFormatter.locale = I18N.instance.locale | ||
| for (index, dayStart) in dayDates.enumerated() { | ||
| if index > 0 { | ||
| statusItemMenu.addItem(NSMenuItem.separator()) | ||
| } | ||
| let dayEvents = events.filter { calendar.isDate($0.startDate, inSameDayAs: dayStart) } | ||
| let sectionTitle: String | ||
| if calendar.isDate(dayStart, inSameDayAs: today) { | ||
| sectionTitle = "status_bar_section_today".loco() | ||
| } else if calendar.isDate(dayStart, inSameDayAs: tomorrow) { | ||
| sectionTitle = "status_bar_section_tomorrow".loco() | ||
| } else { | ||
| sectionTitle = dateFormatter.string(from: dayStart) | ||
| } | ||
| statusItemMenu.items += builder.buildDateSection(date: dayStart, title: sectionTitle, events: dayEvents) | ||
|
Comment on lines
+398
to
+417
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid duplicated date labels in multi‑day sections.
✅ Suggested fix- let dateFormatter = DateFormatter()
- dateFormatter.dateFormat = "E, d MMM"
- dateFormatter.locale = I18N.instance.locale
+ let weekdayFormatter = DateFormatter()
+ weekdayFormatter.dateFormat = "EEEE"
+ weekdayFormatter.locale = I18N.instance.locale
for (index, dayStart) in dayDates.enumerated() {
@@
} else if calendar.isDate(dayStart, inSameDayAs: tomorrow) {
sectionTitle = "status_bar_section_tomorrow".loco()
} else {
- sectionTitle = dateFormatter.string(from: dayStart)
+ sectionTitle = weekdayFormatter.string(from: dayStart)
}🤖 Prompt for AI Agents |
||
| } | ||
| } | ||
| } else { | ||
| let text = "status_bar_empty_calendar_message".loco() | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix
.today_n_tomorrowto include tomorrow indaysInPeriod.The helper’s switch returns only
todayfor.today_n_tomorrow, which is incorrect if the helper is reused for that period.✅ Suggested fix
📝 Committable suggestion
🤖 Prompt for AI Agents