Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
2025 November
┌─────┬─────┬─────┬─────┬─────┬─────┬─────┐
│ Sun │ Mon │ Tue │ Wed │ Thu │ Fri │ Sat │
├─────┼─────┼─────┼─────┼─────┼─────┼─────┤
│ │ │ │ │ │ │ 1 │
│ 2 │ 3 │ 4 │ 5 │ 6 │ 7 │ 8 │
│ 9 │ 10 │ 11 │ 12 │ 13 │ 14 │ 15 │
│ 16 │ 17 │ 18 │ 19 │ 20 │ 21 │ 22 │
│ 23 │ 24 │ 25 │ 26 │ 27 │ 28 │ 29 │
│ 30 │ │ │ │ │ │ │
└─────┴─────┴─────┴─────┴─────┴─────┴─────┘
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
2025 November
┌─────┬─────┬─────┬─────┬─────┬─────┬─────┐
│ Sun │ Mon │ Tue │ Wed │ Thu │ Fri │ Sat │
├─────┼─────┼─────┼─────┼─────┼─────┼─────┤
│ │ │ │ │ │ │ 1* │
│ 2 │ 3 │ 4 │ 5 │ 6 │ 7 │ 8 │
│ 9 │ 10 │ 11 │ 12 │ 13* │ 14 │ 15 │
│ 16 │ 17 │ 18 │ 19 │ 20 │ 21 │ 22 │
│ 23 │ 24 │ 25 │ 26 │ 27* │ 28 │ 29 │
│ 30 │ │ │ │ │ │ │
└─────┴─────┴─────┴─────┴─────┴─────┴─────┘
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
2025 November
┌─────┬─────┬─────┬─────┬─────┬─────┬─────┐
│ Sun │ Mon │ Tue │ Wed │ Thu │ Fri │ Sat │
├─────┼─────┼─────┼─────┼─────┼─────┼─────┤
│ │ │ │ │ │ │ 1* │
│ 2 │ 3 │ 4 │ 5 │ 6 │ 7 │ 8 │
│ 9 │ 10 │ 11 │ 12 │ 13* │ 14 │ 15 │
│ 16 │ 17 │ 18 │ 19 │ 20 │ 21 │ 22 │
│ 23 │ 24 │ 25 │ 26 │ 27 │ 28 │ 29 │
│ 30 │ │ │ │ │ │ │
└─────┴─────┴─────┴─────┴─────┴─────┴─────┘
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
2025 November
┌─────┬─────┬─────┬─────┬─────┬─────┬─────┐
│ Sun │ Mon │ Tue │ Wed │ Thu │ Fri │ Sat │
├─────┼─────┼─────┼─────┼─────┼─────┼─────┤
│ │ │ │ │ │ │ 1 │
│ 2 │ 3 │ 4 │ 5 │ 6 │ 7 │ 8 │
│ 9 │ 10 │ 11 │ 12 │ 13 │ 14 │ 15 │
│ 16 │ 17 │ 18 │ 19 │ 20 │ 21 │ 22 │
│ 23 │ 24 │ 25 │ 26 │ 27 │ 28 │ 29 │
│ 30 │ │ │ │ │ │ │
└─────┴─────┴─────┴─────┴─────┴─────┴─────┘
77 changes: 77 additions & 0 deletions src/Spectre.Console.Tests/Unit/Widgets/CalendarTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,83 @@ namespace Spectre.Console.Tests.Unit;
[ExpectationPath("Widgets/Calendar")]
public sealed class CalendarTests
{
[Fact]
[Expectation("RenderNov2025woEvents")]
public Task Should_Render_Calendar()
{
//Given
var console = new TestConsole();
var calendar = new Calendar(2025, 11);

//When
console.Write(calendar);

//Then
return Verifier.Verify(console.Output);
}

[Fact]
[Expectation("RenderNov2025RemoveEvent")]
public Task Should_Render_Calendar_Remove_Event()
{
//Given
var console = new TestConsole();
var calendar = new Calendar(2025, 11)
.AddCalendarEvent(2025, 11, 26);

calendar.RemoveCalendarEvent(2025, 11, 26);
//When
console.Write(calendar);

//Then
return Verifier.Verify(console.Output);
}

[Fact]
[Expectation("RenderNov2025RemoveEvents")]
public Task Should_Render_Calendar_Remove_Events()
{
//Given
var console = new TestConsole();
var calendar = new Calendar(2025, 11)
.AddCalendarEvent(2025, 11, 1)
.AddCalendarEvent(2025, 11, 15)
.AddCalendarEvent(2025, 11, 13)
.AddCalendarEvent(2025, 11, 23)
.AddCalendarEvent(2025, 11, 27);

calendar.RemoveCalendarEvent(2025, 11, 15);
calendar.RemoveCalendarEvent(2025, 11, 23);
//When
console.Write(calendar);

//Then
return Verifier.Verify(console.Output);
}

[Fact]
[Expectation("RenderNov2025RemoveFaultyEvent")]
public Task Should_Render_Calendar_Remove_Faulty_Event()
{
//Given
var console = new TestConsole();
var calendar = new Calendar(2025, 11)
.AddCalendarEvent(2025, 11, 1)
.AddCalendarEvent(2025, 11, 15)
.AddCalendarEvent(2025, 11, 13);

calendar.RemoveCalendarEvent(2025, 11, 15);

// Remove event from May -> not in this calendar
calendar.RemoveCalendarEvent(2025, 5, 23);

//When
console.Write(calendar);

//Then
return Verifier.Verify(console.Output);
}

[Fact]
[Expectation("Render")]
public Task Should_Render_Calendar_Correctly()
Expand Down
25 changes: 25 additions & 0 deletions src/Spectre.Console/Extensions/CalendarExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,31 @@ public static Calendar AddCalendarEvent(this Calendar calendar, string descripti
calendar.CalendarEvents.Add(new CalendarEvent(description, year, month, day, customEventHighlightStyle));
return calendar;
}
/// <summary>
/// Removes a calendar event.
/// </summary>
/// <param name="calendar">The calendar.</param>
/// <param name="year">The year of the calendar event.</param>
/// <param name="month">The month of the calendar event.</param>
/// <param name="day">The day of the calendar event.</param>
/// <returns>The same instance so that multiple calls can be chained.</returns>
public static Calendar RemoveCalendarEvent(this Calendar calendar, int year, int month, int day)
{
if (calendar is null)
{
throw new ArgumentNullException(nameof(calendar));
}

var calendarEvent = calendar.CalendarEvents.Where(e => e.Year == year && e.Month == month && e.Day == day)
.ToList()
.SingleOrDefault();
if (calendarEvent != null)
{
calendar.CalendarEvents.Remove(calendarEvent);
}

return calendar;
}

/// <summary>
/// Sets the calendar's highlight <see cref="Style"/>.
Expand Down