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

refactor: simplify calculation of days and other part of IPeriod #57

Merged
merged 2 commits into from
Feb 20, 2025

Conversation

Seddryck
Copy link
Owner

@Seddryck Seddryck commented Feb 20, 2025

Summary by CodeRabbit

  • Refactor

    • Improved date period definitions by replacing older attributes with clearer, subdivision-based parameters (e.g., 12 parts for months, 4 for quarters, and 2 for semesters). Adjustments also enhance leap year and historical date handling.
  • Tests

    • Added a validation to ensure that historical calendar calculations (such as the day count for October 1582) meet expected outcomes.

Seddryck and others added 2 commits February 18, 2025 08:46

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
…of functions and predicates
@Seddryck Seddryck changed the title Refactor/iperiod refactor: simplify calculation of days and other part of IPeriod Feb 20, 2025
Copy link

coderabbitai bot commented Feb 20, 2025

Walkthrough

Multiple files have been updated to adjust how date period data is defined and processed. The YAML definitions for various date structures no longer include a duration or an "intrayear" attribute; instead, a "byYear" attribute is used. In parallel, the source generator logic has been modified to output the new properties and simplified date calculations. Additionally, a new test case has been added to the YearMonth test suite to verify the correct day count for October 1582.

Changes

File(s) Change Summary
docs/_data/structs.yml, src/Chrononuensis.Core/Structs.yml Removed duration from YearDay and YearWeek; replaced intrayear with byYear (with values 12 for YearMonth, 4 for YearQuarter, 2 for YearSemester).
src/Chrononuensis.Core.Testing/YearMonthTests.cs Added new test method Days_GregorianCalendar_Expected to verify that October 1582 has 31 days.
src/Chrononuensis.SourceGenerator/Definitions/StructPeriod.cs Removed properties Intrayear and Duration; added new property ByYear.
src/Chrononuensis.SourceGenerator/StructGenerator.cs, src/Chrononuensis.SourceGenerator/Templates/Period.scriban-cs Modified the period generation logic by replacing max with by_year, consolidating year-related data into an anonymous object, and simplifying date calculations.

Sequence Diagram(s)

Loading
sequenceDiagram
    participant TR as Test Runner
    participant YM as YearMonthTests
    participant YMCalc as YearMonth / DateCalc Module

    TR->>YM: Run Days_GregorianCalendar_Expected(input, expected)
    YM->>YMCalc: Calculate Days in October 1582
    YMCalc-->>YM: Return computed day count
    YM-->>TR: Test result (pass/fail)
Loading
sequenceDiagram
    participant SD as StructDefinition
    participant SG as StructGenerator
    participant TP as Templates/Period.scriban-cs
    participant GC as Generated Code

    SD->>SG: Request GeneratePeriod(structDefinition)
    SG->>SD: Retrieve period attributes (ByYear, Year, YearDuration)
    SG->>TP: Render period template with new properties (by_year, year value/duration)
    TP-->>SG: Return generated period code
    SG-->>GC: Output final code structure

Possibly related PRs

Suggested labels

new-feature

Poem

I'm a little rabbit, hopping through the code,
Changing periods and dates down every lane.
Gone are the days of duration and "intrayear" mode,
Now "byYear" rules the date domain.
A test for October's history makes my heart skip a beat,
As I munch on carrots and celebrate each tweak!
🥕🐇 Happy hops in every commit!

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

🪧 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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.

Sorry, something went wrong.

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: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 70201d1 and 77badf8.

📒 Files selected for processing (6)
  • docs/_data/structs.yml (3 hunks)
  • src/Chrononuensis.Core.Testing/YearMonthTests.cs (1 hunks)
  • src/Chrononuensis.Core/Structs.yml (3 hunks)
  • src/Chrononuensis.SourceGenerator/Definitions/StructPeriod.cs (1 hunks)
  • src/Chrononuensis.SourceGenerator/StructGenerator.cs (1 hunks)
  • src/Chrononuensis.SourceGenerator/Templates/Period.scriban-cs (1 hunks)
🔇 Additional comments (11)
src/Chrononuensis.SourceGenerator/Definitions/StructPeriod.cs (1)

12-12: LGTM! Property changes improve clarity.

The introduction of ByYear property and removal of Intrayear and Duration properties simplifies the period definition while making the intent clearer.

src/Chrononuensis.SourceGenerator/Templates/Period.scriban-cs (3)

7-8: LGTM! Simplified days calculation.

The calculation has been simplified to a more direct and readable formula.


13-14: LGTM! Improved date calculation logic.

The new by_year based calculation provides a clearer way to handle month divisions within a year.


22-23: LGTM! Consistent date range handling.

The LastDate calculation now consistently uses the by_year value to determine period boundaries.

src/Chrononuensis.SourceGenerator/StructGenerator.cs (1)

231-238: LGTM! Better organization of year-related data.

The changes improve the structure by:

  1. Using by_year for period divisions
  2. Grouping year-related properties into a single object
docs/_data/structs.yml (3)

49-50: Define YearMonth Subdivision with byYear
The addition of byYear: 12 in the YearMonth structure clearly specifies that a year is divided into 12 parts, aligning with the new design approach. This makes the period definition more explicit and consistent with related structures.


61-62: Standardize YearQuarter Definition
Introducing byYear: 4 for the YearQuarter structure appropriately defines that there are 4 quarters per year. This change mirrors the updated logic in the core files and enhances clarity.


73-74: Clarify YearSemester Partitioning
Replacing the previous intrayear approach with byYear: 2 for YearSemester clearly indicates the year is split into 2 semesters. This improves consistency and maintainability across all period-based structures.

src/Chrononuensis.Core/Structs.yml (3)

49-50: Update YearMonth Period Definition
The new byYear: 12 attribute in the YearMonth structure succinctly establishes that the year is divided into 12 parts, which is in line with the overall strategy to simplify date period representations.


61-62: Consistent Quarter Segmentation
With byYear: 4 added to the YearQuarter structure, the specification now explicitly states that there are 4 quarters in a year, thereby aligning with traditional calendar division and similar updates in the documentation.


73-74: Standardize Semester Configuration
The introduction of byYear: 2 for the YearSemester structure standardizes the approach for defining period subdivisions. This change enhances both clarity and consistency across the system's various date structures.

Comment on lines +178 to +184
[Test]
[TestCase("1582-10", 31)]
public void Days_GregorianCalendar_Expected(string input, int expected)
{
var value = YearMonth.Parse(input, null);
Assert.That(value.Days, Is.EqualTo(expected));
}
Copy link

@coderabbitai coderabbitai bot Feb 20, 2025

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Verify historical accuracy of the October 1582 test case.

The test case for October 1582 assumes 31 days, but historically, this month had only 21 days in the Gregorian calendar as days 4-14 were skipped during the calendar reform.


🌐 Web query:

How many days were there in October 1582 when the Gregorian calendar was introduced?

💡 Result:

The introduction of the Gregorian calendar in October 1582 resulted in 21 calendar days for that month in regions adopting the new system[1][2][3][7][8][9]. Here’s why:

Calendar Transition Details

  • The Julian calendar (used since Julius Caesar’s time) had accumulated a 10-day discrepancy with astronomical events like the spring equinox due to its overestimation of solar year length[1][2][7].
  • To correct this:
    1. October 4, 1582 (Julian) was designated as the last day of the old system.
    2. The next day became October 15, 1582 (Gregorian), eliminating dates October 5–14[1][3][7].
  • This adjustment aligned seasonal markers (e.g., equinoxes) with liturgical requirements for Easter[1][2].

Regional Adoption

  • Catholic nations like Italy, Spain, Portugal, and Poland adopted this change immediately[3][8].
  • Protestant and Orthodox countries resisted initially:
    • England switched in 1752 (skipping 11 days)[9].
    • Russia delayed until 1918[8].

Key Implications

  • The month retained its usual 31-day structure but skipped 10 consecutive dates[7].
  • Days of the week continued uninterrupted: Thursday (October 4) was followed by Friday (October 15)[3][7].

This reform standardized timekeeping globally over centuries while resolving discrepancies critical to religious observances[1][5].

Citations:


Update the expected days count for October 1582.

The test case in src/Chrononuensis.Core.Testing/YearMonthTests.cs currently asserts that October 1582 has 31 days. However, due to the Gregorian calendar reform—which skipped October 5–14—October 1582 actually contained only 21 calendar days. Please update the expected value in the test case accordingly.

Copy link
Owner Author

Choose a reason for hiding this comment

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

No because it's not proletic Georgian CAlendar

Copy link

Choose a reason for hiding this comment

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

@Seddryck Thank you for the correction. You're absolutely right - since we're using the proleptic Gregorian calendar, October 1582 should indeed have 31 days as the test correctly asserts.


✏️ Learnings added
Learnt from: Seddryck
PR: Seddryck/Chrononuensis#57
File: src/Chrononuensis.Core.Testing/YearMonthTests.cs:178-184
Timestamp: 2025-02-20T20:39:00.092Z
Learning: The codebase uses proleptic Gregorian calendar which extends Gregorian calendar rules backwards in time, meaning dates before the historical Gregorian calendar adoption (October 1582) are calculated as if Gregorian calendar was always in effect. For example, October 1582 has 31 days in proleptic calendar (unlike 21 days in historical Gregorian calendar).

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

@Seddryck Seddryck merged commit b717041 into main Feb 20, 2025
4 checks passed
@Seddryck Seddryck deleted the refactor/iperiod branch February 20, 2025 20:41
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.

None yet

1 participant