Skip to content

Conversation

KAVYANSHTYAGI
Copy link

@KAVYANSHTYAGI KAVYANSHTYAGI commented Sep 10, 2025

Description

This PR addresses a bug in the date query handler where NaiveDate::from_ymd_opt was constructed with month0()/day0(), leading to invalid or missing dates when substituting a parsed year.

Changes

  • Replaced month0()/day0() with 1-based month() and day() to correctly construct dates.
  • Added an async regression test (parses_year_from_query) to ensure queries like "June 5 2024" correctly format to "2024-06-05".

Notes

  • Preserves fallback behavior: if the constructed date is invalid (e.g., leap year rollover), the handler falls back to the original parsed date string.
  • No API changes; only internal correctness and test coverage improvements.

Summary by Sourcery

Fix the date query handler to use 1-based month and day in NaiveDate construction and add a regression test to verify correct year parsing.

Bug Fixes:

  • Use 1-based month() and day() instead of month0()/day0() when constructing dates to prevent invalid or missing dates

Tests:

  • Add an async regression test to ensure queries like "June 5 2024" format correctly to "2024-06-05"

Copy link
Contributor

sourcery-ai bot commented Sep 10, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Fix date query handler to use 1-based month/day indexing and bolster test coverage with an async regression test

Sequence diagram for date query handling with year substitution

sequenceDiagram
    participant "AFPluginData"
    participant "query_date_handler()"
    participant "NaiveDate"
    participant "FlowyError"
    "AFPluginData"->>"query_date_handler()": pass query (e.g., "June 5 2024")
    "query_date_handler()"->>"NaiveDate": extract month() and day() (1-based)
    "query_date_handler()"->>"NaiveDate": from_ymd_opt(year, month, day)
    alt valid date
        "NaiveDate"-->>"query_date_handler()": formatted date string
    else invalid date
        "query_date_handler()"->>"FlowyError": fallback to original date string
    end
    "query_date_handler()"-->>"AFPluginData": return result
Loading

Class diagram for updated date query handler and test

classDiagram
    class DateQueryPB {
        +String query
    }
    class AFPluginData {
        +DateQueryPB inner
    }
    class FlowyError {
        +internal()
        +with_context(str)
    }
    class NaiveDate {
        +from_ymd_opt(year: i32, month: u32, day: u32)
        +month()
        +day()
        +to_string()
    }
    class query_date_handler {
        +async fn query_date_handler(AFPluginData) -> Result
    }
    class tests {
        +async fn parses_year_from_query()
    }
    AFPluginData --> DateQueryPB
    query_date_handler --> AFPluginData
    query_date_handler --> NaiveDate
    query_date_handler --> FlowyError
    tests --> query_date_handler
Loading

File-Level Changes

Change Details Files
Switched to 1-based month/day when constructing dates
  • Replaced month0()/day0() with month()/day() in NaiveDate::from_ymd_opt
  • Maintained fallback to original parsed date string on invalid dates
frontend/rust-lib/flowy-date/src/event_handler.rs
Added async regression test for date query handler
  • Introduced parses_year_from_query test with tokio::test attribute
  • Verified output "2024-06-05" for query "June 5 2024"
frontend/rust-lib/flowy-date/src/event_handler.rs

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@CLAassistant
Copy link

CLAassistant commented Sep 10, 2025

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

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