Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,21 @@ $ reminders show Soon
3: Something really important (priority: high)
```

#### Show reminders due on or by a date

```
$ reminders show-all --due-date today
1: Contribute to open source (in 3 hours)
$ reminders show-all --due-date today --include-overdue
0: Ship reminders-cli (2 days ago)
1: Contribute to open source (in 3 hours)
$ reminders show-all --due-date 2025-02-16
1: Contribute to open source (in 3 hours)
$ reminders show Soon --due-date today --include-overdue
0: Ship reminders-cli (2 days ago)
1: Contribute to open source (in 3 hours)
```

#### See help for more examples

```
Expand Down
13 changes: 10 additions & 3 deletions Sources/RemindersLibrary/CLI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ private struct ShowAll: ParsableCommand {
@Flag(help: "Include completed items in output")
var includeCompleted = false

@Flag(help: "When using --due-date, also include items due before the due date")
var includeOverdue = false

@Option(
name: .shortAndLong,
help: "Show only reminders due on this date")
Expand All @@ -52,7 +55,8 @@ private struct ShowAll: ParsableCommand {
}

reminders.showAllReminders(
dueOn: self.dueDate, displayOptions: displayOptions, outputFormat: format)
dueOn: self.dueDate, includeOverdue: self.includeOverdue,
displayOptions: displayOptions, outputFormat: format)
}
}

Expand All @@ -71,6 +75,9 @@ private struct Show: ParsableCommand {
@Flag(help: "Include completed items in output")
var includeCompleted = false

@Flag(help: "When using --due-date, also include items due before the due date")
var includeOverdue = false

@Option(
name: .shortAndLong,
help: "Show the reminders in a specific order, one of: \(Sort.commaSeparatedCases)")
Expand Down Expand Up @@ -107,8 +114,8 @@ private struct Show: ParsableCommand {
}

reminders.showListItems(
withName: self.listName, dueOn: self.dueDate, displayOptions: displayOptions,
outputFormat: format, sort: sort, sortOrder: sortOrder)
withName: self.listName, dueOn: self.dueDate, includeOverdue: self.includeOverdue,
displayOptions: displayOptions, outputFormat: format, sort: sort, sortOrder: sortOrder)
}
}

Expand Down
19 changes: 13 additions & 6 deletions Sources/RemindersLibrary/Reminders.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,9 @@ public final class Reminders {
}
}

func showAllReminders(dueOn dueDate: DateComponents?,
displayOptions: DisplayOptions, outputFormat: OutputFormat) {
func showAllReminders(dueOn dueDate: DateComponents?, includeOverdue: Bool,
displayOptions: DisplayOptions, outputFormat: OutputFormat
) {
let semaphore = DispatchSemaphore(value: 0)
let calendar = Calendar.current

Expand All @@ -120,7 +121,10 @@ public final class Reminders {

let sameDay = calendar.compare(
reminderDueDate, to: dueDate, toGranularity: .day) == .orderedSame
if sameDay {
let earlierDay = calendar.compare(
reminderDueDate, to: dueDate, toGranularity: .day) == .orderedAscending

if sameDay || (includeOverdue && earlierDay) {
matchingReminders.append((reminder, i, listName))
}
}
Expand All @@ -140,8 +144,8 @@ public final class Reminders {
semaphore.wait()
}

func showListItems(withName name: String, dueOn dueDate: DateComponents?, displayOptions: DisplayOptions,
outputFormat: OutputFormat, sort: Sort, sortOrder: CustomSortOrder)
func showListItems(withName name: String, dueOn dueDate: DateComponents?, includeOverdue: Bool,
displayOptions: DisplayOptions, outputFormat: OutputFormat, sort: Sort, sortOrder: CustomSortOrder)
{
let semaphore = DispatchSemaphore(value: 0)
let calendar = Calendar.current
Expand All @@ -162,7 +166,10 @@ public final class Reminders {

let sameDay = calendar.compare(
reminderDueDate, to: dueDate, toGranularity: .day) == .orderedSame
if sameDay {
let earlierDay = calendar.compare(
reminderDueDate, to: dueDate, toGranularity: .day) == .orderedAscending

if sameDay || (includeOverdue && earlierDay) {
matchingReminders.append((reminder, index))
}
}
Expand Down