Skip to content

Commit

Permalink
Merge pull request #208 from rprouse:feature/month
Browse files Browse the repository at this point in the history
Create next month's calendar
  • Loading branch information
rprouse authored Feb 25, 2025
2 parents 95e7d6c + bf08aef commit b54c212
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 18 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/continuous_integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:

steps:
- name: 📥 Checkout Code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
submodules: true # Fetch and checkout submodules
fetch-depth: 0 # Ensure the full history is fetched, useful when dealing with submodules
Expand All @@ -30,7 +30,7 @@ jobs:
run: dotnet pack --no-build --configuration Release

- name: 📤 Upload Artifacts
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: nupkg
path: Guppi.Console/nupkg/*.nupkg
Expand All @@ -43,7 +43,7 @@ jobs:
if: github.ref == 'refs/heads/main'
steps:
- name: 📥 Download Artifacts
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: nupkg

Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -358,3 +358,8 @@ MigrationBackup/

# Code coverage
coverage.json

# AI Tools
.aider*
repomix-output.txt

4 changes: 2 additions & 2 deletions Guppi.Console/Guppi.Console.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
Expand All @@ -13,7 +13,7 @@
<PackageProjectUrl>https://github.com/rprouse/guppi</PackageProjectUrl>
<RepositoryUrl>https://github.com/rprouse/guppi</RepositoryUrl>
<PackageId>dotnet-guppi</PackageId>
<Version>6.4.0</Version>
<Version>6.5.0</Version>
<PackAsTool>true</PackAsTool>
<ToolCommandName>guppi</ToolCommandName>
<PackageOutputPath>./nupkg</PackageOutputPath>
Expand Down
32 changes: 19 additions & 13 deletions Guppi.Console/Skills/CalendarSkill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,14 @@

namespace Guppi.Console.Skills;

internal class CalendarSkill(ICalendarService service) : ISkill
internal class CalendarSkill : ISkill
{
private readonly ICalendarService _service = service;
private readonly ICalendarService _service;

public CalendarSkill(ICalendarService service)
{
_service = service;
}

public IEnumerable<Command> GetCommands()
{
Expand Down Expand Up @@ -44,12 +49,13 @@ public IEnumerable<Command> GetCommands()
await Agenda(midnight, "Tomorrow's agenda", markdown, table);
}, markdown, table);

var month = new Command("month", "Displays this month's calendar") { markdown };
month.SetHandler(async (bool markdown) =>
var nextMonth = new Option<bool>(["--next", "-n"], "Display next month's calendar");
var month = new Command("month", "Displays this month's calendar") { markdown, nextMonth };
month.SetHandler(async (bool markdown, bool nextMonth) =>
{
if (markdown) await MonthMarkdown();
else Month();
}, markdown);
if (markdown) await MonthMarkdown(nextMonth);
else Month(nextMonth);
}, markdown, nextMonth);

var free = new Command("free", "Displays free time for a given day");
free.AddArgument(new Argument<DateTime>("date", "The date to check"));
Expand Down Expand Up @@ -270,9 +276,9 @@ private static string JoinLink(Core.Entities.Calendar.Event eventItem) =>
private static string TableLinkedSummary(Core.Entities.Calendar.Event eventItem) =>
string.IsNullOrEmpty(eventItem.MeetingUrl) ? eventItem.Summary : $"[{eventItem.Summary}]({eventItem.MeetingUrl})";

private static void Month()
private static void Month(bool nextMonth)
{
(DateOnly start, DateOnly end) = GetMonthRange();
(DateOnly start, DateOnly end) = GetMonthRange(nextMonth);

AnsiConsoleHelper.TitleRule($":calendar: {start:MMMM yyyy}");

Expand Down Expand Up @@ -307,9 +313,9 @@ private static void Month()
AnsiConsoleHelper.Rule("white");
}

private static async Task MonthMarkdown()
private static async Task MonthMarkdown(bool nextMonth)
{
(DateOnly start, DateOnly end) = GetMonthRange();
(DateOnly start, DateOnly end) = GetMonthRange(nextMonth);
StringBuilder cal = new();
cal.AppendLine("| Day | Date | Habits | Notes |");
cal.AppendLine("| --- | ---- | ------ | ----- |");
Expand All @@ -330,9 +336,9 @@ private static async Task MonthMarkdown()
AnsiConsoleHelper.Rule("white");
}

private static (DateOnly start, DateOnly end) GetMonthRange()
private static (DateOnly start, DateOnly end) GetMonthRange(bool nextMonth)
{
var now = DateTime.Now;
var now = nextMonth ? DateTime.Now.AddMonths(1) : DateTime.Now;
var start = new DateOnly(now.Year, now.Month, 1);
var end = new DateOnly(now.Year, now.Month, DateTime.DaysInMonth(now.Year, now.Month));
return (start, end);
Expand Down

0 comments on commit b54c212

Please sign in to comment.