Skip to content

Conversation

@geoperez
Copy link
Member

@geoperez geoperez commented Mar 8, 2025

Refactor code to change Next and Previous properties to methods with an optional offset parameter.

  • Interfaces/ILinkedEntity.cs

    • Change Previous property to Previous(int offset = 1) method
    • Change Next property to Next(int offset = 1) method
  • YearAbstract.cs

    • Change Previous property to Previous(int offset = 1) method
    • Change Next property to Next(int offset = 1) method
  • YearEntity.cs

    • Change Previous property to Previous(int offset = 1) method
    • Change Next property to Next(int offset = 1) method
  • YearMonth.cs

    • Change Previous property to Previous(int offset = 1) method
    • Change Next property to Next(int offset = 1) method
  • YearQuarter.cs

    • Change Previous property to Previous(int offset = 1) method
    • Change Next property to Next(int offset = 1) method
  • YearToDate.cs

    • Change Previous property to Previous(int offset = 1) method
    • Change Next property to Next(int offset = 1) method
  • YearWeek.cs

    • Change Previous property to Previous(int offset = 1) method
    • Change Next property to Next(int offset = 1) method
  • YearWeekBase.cs

    • Change Previous property to Previous(int offset = 1) method
    • Change Next property to Next(int offset = 1) method
  • YearWeekIso.cs

    • Change Previous property to Previous(int offset = 1) method
    • Change Next property to Next(int offset = 1) method
  • Unit Tests

    • Update tests in YearMonth-Tests.cs, YearQuarter-Tests.cs, YearToDate-Tests.cs, YearWeek-Tests.cs, and YearWeekIsoTests.cs to use Previous(int offset = 1) and Next(int offset = 1) methods

For more details, open the Copilot Workspace session.

Refactor code to change `Next` and `Previous` properties to methods with an optional `offset` parameter.

* **Interfaces/ILinkedEntity.cs**
  - Change `Previous` property to `Previous(int offset = 1)` method
  - Change `Next` property to `Next(int offset = 1)` method

* **YearAbstract.cs**
  - Change `Previous` property to `Previous(int offset = 1)` method
  - Change `Next` property to `Next(int offset = 1)` method

* **YearEntity.cs**
  - Change `Previous` property to `Previous(int offset = 1)` method
  - Change `Next` property to `Next(int offset = 1)` method

* **YearMonth.cs**
  - Change `Previous` property to `Previous(int offset = 1)` method
  - Change `Next` property to `Next(int offset = 1)` method

* **YearQuarter.cs**
  - Change `Previous` property to `Previous(int offset = 1)` method
  - Change `Next` property to `Next(int offset = 1)` method

* **YearToDate.cs**
  - Change `Previous` property to `Previous(int offset = 1)` method
  - Change `Next` property to `Next(int offset = 1)` method

* **YearWeek.cs**
  - Change `Previous` property to `Previous(int offset = 1)` method
  - Change `Next` property to `Next(int offset = 1)` method

* **YearWeekBase.cs**
  - Change `Previous` property to `Previous(int offset = 1)` method
  - Change `Next` property to `Next(int offset = 1)` method

* **YearWeekIso.cs**
  - Change `Previous` property to `Previous(int offset = 1)` method
  - Change `Next` property to `Next(int offset = 1)` method

* **Unit Tests**
  - Update tests in `YearMonth-Tests.cs`, `YearQuarter-Tests.cs`, `YearToDate-Tests.cs`, `YearWeek-Tests.cs`, and `YearWeekIsoTests.cs` to use `Previous(int offset = 1)` and `Next(int offset = 1)` methods

---

For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/unosquare/unodatetime?shareId=XXXX-XXXX-XXXX-XXXX).
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Hello @geoperez, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

Summary of Changes

This pull request refactors the ILinkedEntity interface and several classes (YearAbstract, YearEntity, YearMonth, YearQuarter, YearToDate, YearWeek, YearWeekBase, and YearWeekIso) to change the Next and Previous properties into methods that accept an optional offset parameter. This change provides more flexibility when navigating between entities. Additionally, the pull request includes updates to the unit tests to accommodate these changes.

Highlights

  • Refactor: The Next and Previous properties are changed to methods with an optional offset parameter in the ILinkedEntity interface and several classes.
  • Unit Tests: Unit tests are updated to use the new Next(int offset = 1) and Previous(int offset = 1) methods.

Changelog

Click here to see the changelog
  • src/Unosquare.DateTimeExt/Interfaces/ILinkedEntity.cs
    • Changed Previous property to Previous(int offset = 1) method (line 5).
    • Changed Next property to Next(int offset = 6) method.
  • src/Unosquare.DateTimeExt/YearAbstract.cs
    • Changed Previous property to Previous(int offset = 1) method (line 33).
    • Changed Next property to Next(int offset = 1) method (line 35).
  • src/Unosquare.DateTimeExt/YearEntity.cs
    • Changed Next property to Next(int offset = 1) method (line 13).
    • Changed Previous property to Previous(int offset = 1) method (line 15).
  • src/Unosquare.DateTimeExt/YearMonth.cs
    • Changed Next property to Next(int offset = 1) method (line 37).
    • Changed Previous property to Previous(int offset = 1) method (line 39).
  • src/Unosquare.DateTimeExt/YearQuarter.cs
    • Changed Next property to Next(int offset = 1) method (line 37).
    • Changed Previous property to Previous(int offset = 1) method (line 39).
  • src/Unosquare.DateTimeExt/YearToDate.cs
    • Changed Previous property to Previous(int offset = 1) method (line 34).
    • Changed Next property to Next(int offset = 1) method (line 36).
  • src/Unosquare.DateTimeExt/YearWeek.cs
    • Changed Next property to Next(int offset = 1) method (line 34).
    • Changed Previous property to Previous(int offset = 1) method (line 36).
  • src/Unosquare.DateTimeExt/YearWeekBase.cs
    • Changed Previous property to Previous(int offset = 1) method (line 10).
    • Changed Next property to Next(int offset = 1) method (line 11).
  • src/Unosquare.DateTimeExt/YearWeekIso.cs
    • Changed Next property to Next(int offset = 1) method (line 29).
    • Changed Previous property to Previous(int offset = 1) method (line 31).
  • test/Unosquare.DateTimeExt.Test/Unosquare.DateTimeExt.Test/YearMonth-Tests.cs
    • Updated tests to use Next() method (line 26).
    • Updated tests to use Previous() method (line 34).
  • test/Unosquare.DateTimeExt.Test/Unosquare.DateTimeExt.Test/YearToDate-Tests.cs
    • Added tests for Previous() method (line 117).
    • Added tests for Next() method (line 126).
  • test/Unosquare.DateTimeExt.Test/Unosquare.DateTimeExt.Test/YearWeek-Tests.cs
    • Updated tests to use Previous() method (line 54).
    • Updated tests to use Next() method (line 62).
  • test/Unosquare.DateTimeExt.Test/Unosquare.DateTimeExt.Test/YearWeekIsoTests.cs
    • Updated tests to use Previous() method (line 54).
    • Updated tests to use Next() method (line 62).
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.


Trivia time!

What is the purpose of the ISO 8601 standard?

Click here for the answer
The ISO 8601 standard is an international standard covering the exchange of date and time-related data. It provides a consistent and unambiguous way to represent dates and times.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

The pull request refactors the Next and Previous properties to methods with an optional offset parameter, enhancing the flexibility of date navigation. The changes are well-structured and the inclusion of unit tests demonstrates a commitment to code quality. However, there are a few areas that could be improved to enhance clarity and maintainability.

Merge Readiness

The code changes are well-structured and the inclusion of unit tests demonstrates a commitment to code quality. I am unable to directly approve the pull request, and recommend that other reviewers also review and approve this code before merging. Given the absence of critical or high severity issues, the pull request is nearly ready for merging. Addressing the medium severity comments would further improve the code's quality and maintainability.

public IReadOnlyCollection<int> Quarters { get; }

public abstract T Previous { get; }
public abstract T Previous(int offset = 1);

Choose a reason for hiding this comment

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

medium

Consider adding XML documentation to describe the purpose of the offset parameter. This will improve the discoverability and usability of the method.

/// <param name="offset">The number of periods to move forward or backward.</param>
    public abstract T Previous(int offset = 1);

public abstract T Previous(int offset = 1);

public abstract T Next { get; }
public abstract T Next(int offset = 1);

Choose a reason for hiding this comment

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

medium

Consider adding XML documentation to describe the purpose of the offset parameter. This will improve the discoverability and usability of the method.

/// <param name="offset">The number of periods to move forward or backward.</param>
    public abstract T Next(int offset = 1);

public static YearEntity Current => new();

public override YearEntity Next => new(StartDate.AddYears(1));
public override YearEntity Next(int offset = 1) => new(StartDate.AddYears(offset));

Choose a reason for hiding this comment

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

medium

Consider adding XML documentation to describe the purpose of the offset parameter. This will improve the discoverability and usability of the method.

/// <param name="offset">The number of years to move forward.</param>
    public override YearEntity Next(int offset = 1) => new(StartDate.AddYears(offset));

public override YearEntity Next(int offset = 1) => new(StartDate.AddYears(offset));

public override YearEntity Previous => new(StartDate.AddYears(-1));
public override YearEntity Previous(int offset = 1) => new(StartDate.AddYears(-offset));

Choose a reason for hiding this comment

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

medium

Consider adding XML documentation to describe the purpose of the offset parameter. This will improve the discoverability and usability of the method.

/// <param name="offset">The number of years to move backward.</param>
    public override YearEntity Previous(int offset = 1) => new(StartDate.AddYears(-offset));

public YearEntity YearEntity => new(Year);

public override YearMonth Next => new(StartDate.AddMonths(1));
public override YearMonth Next(int offset = 1) => new(StartDate.AddMonths(offset));

Choose a reason for hiding this comment

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

medium

Consider adding XML documentation to describe the purpose of the offset parameter. This will improve the discoverability and usability of the method.

/// <param name="offset">The number of months to move forward.</param>
    public override YearMonth Next(int offset = 1) => new(StartDate.AddMonths(offset));

public override YearWeek Next(int offset = 1) => new(StartDate.AddDays(WeekDays * offset));

public override YearWeek Previous => new(StartDate.AddDays(-WeekDays));
public override YearWeek Previous(int offset = 1) => new(StartDate.AddDays(-WeekDays * offset));

Choose a reason for hiding this comment

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

medium

Consider adding XML documentation to describe the purpose of the offset parameter. This will improve the discoverability and usability of the method.

/// <param name="offset">The number of weeks to move backward.</param>
    public override YearWeek Previous(int offset = 1) => new(StartDate.AddDays(-WeekDays * offset));


public abstract T Previous { get; }
public abstract T Next { get; }
public abstract T Previous(int offset = 1);

Choose a reason for hiding this comment

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

medium

Consider adding XML documentation to describe the purpose of the offset parameter. This will improve the discoverability and usability of the method.

/// <param name="offset">The number of weeks to move backward.</param>
    public abstract T Previous(int offset = 1);

public abstract T Previous { get; }
public abstract T Next { get; }
public abstract T Previous(int offset = 1);
public abstract T Next(int offset = 1);

Choose a reason for hiding this comment

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

medium

Consider adding XML documentation to describe the purpose of the offset parameter. This will improve the discoverability and usability of the method.

/// <param name="offset">The number of weeks to move forward.</param>
    public abstract T Next(int offset = 1);

public override int Year => ISOWeek.GetYear(StartDate);

public override YearWeekIso Next => new(StartDate.AddDays(WeekDays));
public override YearWeekIso Next(int offset = 1) => new(StartDate.AddDays(WeekDays * offset));

Choose a reason for hiding this comment

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

medium

Consider adding XML documentation to describe the purpose of the offset parameter. This will improve the discoverability and usability of the method.

/// <param name="offset">The number of weeks to move forward.</param>
    public override YearWeekIso Next(int offset = 1) => new(StartDate.AddDays(WeekDays * offset));

public override YearWeekIso Next(int offset = 1) => new(StartDate.AddDays(WeekDays * offset));

public override YearWeekIso Previous => new(StartDate.AddDays(-WeekDays));
public override YearWeekIso Previous(int offset = 1) => new(StartDate.AddDays(-WeekDays * offset));

Choose a reason for hiding this comment

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

medium

Consider adding XML documentation to describe the purpose of the offset parameter. This will improve the discoverability and usability of the method.

/// <param name="offset">The number of weeks to move backward.</param>
    public override YearWeekIso Previous(int offset = 1) => new(StartDate.AddDays(-WeekDays * offset));

@geoperez
Copy link
Member Author

geoperez commented Mar 8, 2025

Gemini puedes aplicar los cambios que sugieres de documentacion XML?

@gemini-code-assist
Copy link

Unfortunately, I am not able to directly apply changes to the code in this pull request. However, I can provide you with the suggested changes in a format that you can easily copy and paste into your code. Let me know if you'd like me to generate the XML documentation suggestions as code snippets!

@sonarqubecloud
Copy link

sonarqubecloud bot commented Mar 8, 2025

@geoperez
Copy link
Member Author

geoperez commented Mar 8, 2025

Gemini porque si te hablo en español, me respondes en ingles?

@gemini-code-assist
Copy link

Hola @geoperez! That's a great question. I am programmed to respond primarily in English to ensure consistency and clarity across all interactions. However, I can understand questions in other languages. If you'd like me to try responding in Spanish, let me know, and I'll do my best! Keep in mind that the quality of the response might be better in English.

@geoperez geoperez merged commit 804c911 into master Mar 10, 2025
3 checks passed
@geoperez geoperez deleted the geoperez/refactor-methods branch March 10, 2025 16:54
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.

2 participants