Skip to content
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

Month calendars #207

Merged
merged 1 commit into from
Nov 29, 2024
Merged

Month calendars #207

merged 1 commit into from
Nov 29, 2024

Conversation

rprouse
Copy link
Owner

@rprouse rprouse commented Nov 29, 2024

Month calendars

Fixes #206

Summary by CodeRabbit

  • New Features
    • Updated version of the Guppi command line utility to 6.4.0.
    • Introduced a new command to display the current month's calendar, available in both standard and Markdown formats.
  • Bug Fixes
    • Changed command-line arguments from "weather daily" to "calendar month," aligning functionality with the new features.

Copy link

coderabbitai bot commented Nov 29, 2024

Walkthrough

The pull request introduces several updates to the Guppi.Console project. The version number in the project file Guppi.Console.csproj is incremented from 6.3.3 to 6.4.0. Additionally, the command-line arguments in launchSettings.json are modified from "weather daily" to "calendar month". Furthermore, the CalendarSkill class has been enhanced by adding a new command, month, which allows users to view the current month's calendar in both standard and Markdown formats.

Changes

File Change Summary
Guppi.Console/Guppi.Console.csproj Version updated from 6.3.3 to 6.4.0.
Guppi.Console/Properties/launchSettings.json commandLineArgs updated from "weather daily" to "calendar month".
Guppi.Console/Skills/CalendarSkill.cs Added methods: Month(), MonthMarkdown(), and GetMonthRange() to enhance calendar functionality.

Assessment against linked issues

Objective Addressed Explanation
Display month calendar
Display month calendar as markdown for Obsidian

Possibly related PRs

  • Remove calendar table columns #196: This PR updates the version number in Guppi.Console.csproj from 6.2.0 to 6.2.1, which is similar to the main PR's version increment from 6.3.3 to 6.4.0.
  • Download Enbridge bills #201: This PR also updates the version number in Guppi.Console.csproj from 6.3.0 to 6.3.1, reflecting a similar change in versioning as seen in the main PR.
  • Update to the v3.0 weather API #205: This PR updates the version number in Guppi.Console.csproj from 6.3.2 to 6.3.3, which is another instance of version incrementing related to the main PR's changes.

🐇 In the garden of code, I hop and play,
With calendars bright, I show the way.
From weather to months, I change my tune,
Markdown magic under the moon.
Version updated, all is well,
Join me, dear friends, in this coding spell! 🌼


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@rprouse rprouse merged commit 95e7d6c into main Nov 29, 2024
2 checks passed
@rprouse rprouse deleted the issue/206 branch November 29, 2024 21:09
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Outside diff range and nitpick comments (3)
Guppi.Console/Skills/CalendarSkill.cs (3)

47-52: LGTM! Consider enhancing the command description.

The command registration follows the established pattern and correctly implements the markdown option. Consider making the description more descriptive, e.g., "Displays the current month's calendar with optional markdown format for Obsidian".

-var month = new Command("month", "Displays this month's calendar") { markdown };
+var month = new Command("month", "Displays the current month's calendar with optional markdown format for Obsidian") { markdown };

310-331: Enhance markdown format for better Obsidian integration.

The markdown implementation is good but could be improved for better organization in Obsidian.

Consider these enhancements:

 private static async Task MonthMarkdown()
 {
     (DateOnly start, DateOnly end) = GetMonthRange();
     StringBuilder cal = new();
+    cal.AppendLine($"# {start:MMMM yyyy}");
+    cal.AppendLine();
-    cal.AppendLine("| Day | Date | Habits | Notes |");
-    cal.AppendLine("| --- | ---- | ------ | ----- |");
+    cal.AppendLine("| Day | Date | Tasks |");
+    cal.AppendLine("| --- | ---- | ----- |");
     for (var day = start; day <= end; day = day.AddDays(1))
     {
-        cal.AppendLine($"| **{day:ddd}** | [[{day:yyyy-MM-dd}]] | | |");
+        cal.AppendLine($"| **{day:ddd}** | [[{day:yyyy-MM-dd}]] | |");
     }
     // ... rest of the method
 }

333-339: Improve testability and documentation of the helper method.

Consider these improvements:

+    /// <summary>
+    /// Gets the start and end dates for the current month.
+    /// </summary>
+    /// <param name="now">The current date and time. Defaults to DateTime.Now.</param>
+    /// <returns>A tuple containing the first and last day of the month.</returns>
-    private static (DateOnly start, DateOnly end) GetMonthRange()
+    private static (DateOnly start, DateOnly end) GetMonthRange(DateTime? now = null)
     {
-        var now = DateTime.Now;
+        now ??= 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));
+        var start = new DateOnly(now.Value.Year, now.Value.Month, 1);
+        var end = new DateOnly(now.Value.Year, now.Value.Month, 
+            DateTime.DaysInMonth(now.Value.Year, now.Value.Month));
         return (start, end);
     }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 51ee1f1 and 5dd83cb.

📒 Files selected for processing (3)
  • Guppi.Console/Guppi.Console.csproj (1 hunks)
  • Guppi.Console/Properties/launchSettings.json (1 hunks)
  • Guppi.Console/Skills/CalendarSkill.cs (4 hunks)
✅ Files skipped from review due to trivial changes (1)
  • Guppi.Console/Guppi.Console.csproj
🔇 Additional comments (1)
Guppi.Console/Properties/launchSettings.json (1)

5-5: LGTM! Command line argument update aligns with new feature.

The change from "weather daily" to "calendar month" correctly reflects the new calendar feature being implemented.

Let's verify that the new command exists in the codebase:

✅ Verification successful

✅ Command line argument change is valid and properly implemented

The verification confirms that:

  • The calendar month command is properly implemented in CalendarSkill.cs
  • The command is registered with both text and markdown output options
  • The implementation includes proper month calendar display functionality
  • The command is correctly integrated into the calendar command hierarchy
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the calendar month command implementation exists
# Expected: Find the command implementation in CalendarSkill.cs

# Search for the calendar month command implementation
ast-grep --pattern 'public class CalendarSkill {
  $$$
  public $$ Month($$$) {
    $$$
  }
  $$$
}'

# Also check for any command registration
rg -l "calendar.*month" --type cs

Length of output: 138


Script:

#!/bin/bash
# Let's try a broader search to find calendar-related implementations

# Search for any calendar-related classes
ast-grep --pattern 'class $_ {
  $$$
  calendar
  $$$
}'

# Search for calendar command registrations with more flexible pattern
rg -i "command.*calendar" --type cs -A 5

# Search for month-related methods in any class
ast-grep --pattern 'class $_ {
  $$$
  Month($$$) {
    $$$
  }
  $$$
}'

# Look for calendar-related files
fd -e cs -e fs calendar -i

Length of output: 2281


Script:

#!/bin/bash
# Let's check the specific Month method implementation in CalendarSkill.cs
rg -A 10 "void Month\(" Guppi.Console/Skills/CalendarSkill.cs
rg -A 10 "MonthMarkdown\(" Guppi.Console/Skills/CalendarSkill.cs

# Also verify the command registration structure
rg -A 15 "new Command\(\"calendar\"" Guppi.Console/Skills/CalendarSkill.cs

Length of output: 1874

Comment on lines +273 to +339
private static void Month()
{
(DateOnly start, DateOnly end) = GetMonthRange();

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

var table = new Table();
table.Border(TableBorder.Rounded);

table.AddColumn(new TableColumn(new Markup("[yellow]Sun[/]")).RightAligned());
table.AddColumn(new TableColumn(new Markup("[yellow]Mon[/]")).RightAligned());
table.AddColumn(new TableColumn(new Markup("[yellow]Tue[/]")).RightAligned());
table.AddColumn(new TableColumn(new Markup("[yellow]Wed[/]")).RightAligned());
table.AddColumn(new TableColumn(new Markup("[yellow]Thu[/]")).RightAligned());
table.AddColumn(new TableColumn(new Markup("[yellow]Fri[/]")).RightAligned());
table.AddColumn(new TableColumn(new Markup("[yellow]Sat[/]")).RightAligned());

// Add empty cells for the last days of the previous month
var row = Enumerable.Range(0, 7).Select(_ => "").ToArray();
for (var day = start; day <= end; day = day.AddDays(1))
{
row[(int)day.DayOfWeek] = day.Day.ToString();
if (day.DayOfWeek == DayOfWeek.Saturday)
{
table.AddRow(row);
row = Enumerable.Range(0, 7).Select(_ => "").ToArray();
}
}
if (end.DayOfWeek != DayOfWeek.Saturday)
table.AddRow(row);

AnsiConsole.Write(table);

AnsiConsole.WriteLine();
AnsiConsoleHelper.Rule("white");
}

private static async Task MonthMarkdown()
{
(DateOnly start, DateOnly end) = GetMonthRange();
StringBuilder cal = new();
cal.AppendLine("| Day | Date | Habits | Notes |");
cal.AppendLine("| --- | ---- | ------ | ----- |");
for (var day = start; day <= end; day = day.AddDays(1))
{
cal.AppendLine($"| **{day:ddd}** | [[{day:yyyy-MM-dd}]] | | |");
}

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

AnsiConsole.WriteLine();
AnsiConsole.WriteLine(cal.ToString());
await TextCopy.ClipboardService.SetTextAsync(cal.ToString());
AnsiConsole.WriteLine();
AnsiConsole.MarkupLine("[green]:green_circle: Copied to clipboard[/]");

AnsiConsole.WriteLine();
AnsiConsoleHelper.Rule("white");
}

private static (DateOnly start, DateOnly end) GetMonthRange()
{
var now = 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);
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Add unit tests and improve error handling.

The new calendar functionality needs test coverage and better error handling:

  1. Unit tests should cover:

    • Calendar display logic
    • Markdown generation
    • Date range calculations
    • Edge cases (month transitions, leap years)
  2. Error handling:

    • Clipboard operations should be wrapped in try-catch
    • User feedback for clipboard failures

Would you like me to help create:

  1. Unit test templates for the new functionality?
  2. Error handling implementation for clipboard operations?

Comment on lines +273 to +308
private static void Month()
{
(DateOnly start, DateOnly end) = GetMonthRange();

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

var table = new Table();
table.Border(TableBorder.Rounded);

table.AddColumn(new TableColumn(new Markup("[yellow]Sun[/]")).RightAligned());
table.AddColumn(new TableColumn(new Markup("[yellow]Mon[/]")).RightAligned());
table.AddColumn(new TableColumn(new Markup("[yellow]Tue[/]")).RightAligned());
table.AddColumn(new TableColumn(new Markup("[yellow]Wed[/]")).RightAligned());
table.AddColumn(new TableColumn(new Markup("[yellow]Thu[/]")).RightAligned());
table.AddColumn(new TableColumn(new Markup("[yellow]Fri[/]")).RightAligned());
table.AddColumn(new TableColumn(new Markup("[yellow]Sat[/]")).RightAligned());

// Add empty cells for the last days of the previous month
var row = Enumerable.Range(0, 7).Select(_ => "").ToArray();
for (var day = start; day <= end; day = day.AddDays(1))
{
row[(int)day.DayOfWeek] = day.Day.ToString();
if (day.DayOfWeek == DayOfWeek.Saturday)
{
table.AddRow(row);
row = Enumerable.Range(0, 7).Select(_ => "").ToArray();
}
}
if (end.DayOfWeek != DayOfWeek.Saturday)
table.AddRow(row);

AnsiConsole.Write(table);

AnsiConsole.WriteLine();
AnsiConsoleHelper.Rule("white");
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Enhance calendar display with current day highlight and events.

The calendar display implementation is functional but could be improved:

  1. Highlight the current day for better user experience
  2. Include all-day events as mentioned in the PR objectives
  3. Consider adding padding for better number alignment

Here's a suggested improvement:

 private static void Month()
 {
     (DateOnly start, DateOnly end) = GetMonthRange();
+    var today = DateOnly.FromDateTime(DateTime.Now);
 
     AnsiConsoleHelper.TitleRule($":calendar: {start:MMMM yyyy}");
 
     var table = new Table();
     table.Border(TableBorder.Rounded);
+    table.Padding(1, 1);
 
     // ... column definitions ...
 
     var row = Enumerable.Range(0, 7).Select(_ => "").ToArray();
     for (var day = start; day <= end; day = day.AddDays(1))
     {
-        row[(int)day.DayOfWeek] = day.Day.ToString();
+        var dayStr = day.Day.ToString().PadLeft(2);
+        row[(int)day.DayOfWeek] = day == today 
+            ? $"[green]{dayStr}[/]" 
+            : dayStr;
         if (day.DayOfWeek == DayOfWeek.Saturday)
         {
             table.AddRow(row);
             row = Enumerable.Range(0, 7).Select(_ => "").ToArray();
         }
     }
     // ... rest of the method
 }

Would you like me to provide an implementation for including all-day events in the calendar display?

Committable suggestion skipped: line range outside the PR's diff.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Display month calendar
1 participant