Skip to content

Split date-time intent handler code#188

Closed
goldyfruit wants to merge 4 commits into
devfrom
feat/date-check-intent-handlers
Closed

Split date-time intent handler code#188
goldyfruit wants to merge 4 commits into
devfrom
feat/date-check-intent-handlers

Conversation

@goldyfruit
Copy link
Copy Markdown
Collaborator

@goldyfruit goldyfruit commented Mar 9, 2026

Summary

Context

This splits the __init__.py changes out of #184 to keep code changes separate from locale changes.

Summary by CodeRabbit

  • New Features
    • Answer leap-year questions with scope awareness (current, next, or either year).
    • Evaluate whether a given date matches a requested weekday, including past/future/today branches.
    • Enhanced multilingual weekday extraction and localized responses (English and French).
  • Improvements
    • Safer handling of ambiguous or unparsable date/weekday inputs with clearer fallback responses.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 9, 2026

Warning

Rate limit exceeded

@goldyfruit has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 15 minutes and 58 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 886390d2-cfe5-4879-b2b1-dbf2285ad74f

📥 Commits

Reviewing files that changed from the base of the PR and between 3522a37 and 5d5f704.

📒 Files selected for processing (1)
  • __init__.py
📝 Walkthrough

Walkthrough

Adds locale-aware weekday extraction and phrase-stripping, a leap-year query scope classifier, and two public intent handlers (is.leap.year.intent, weekday.matches.date.intent) plus caching helpers and leap-year logic; integrates safer parsing early exits and calendar-based isleap checks. (≤50 words)

Changes

Cohort / File(s) Summary
TimeSkill core
__init__.py
Imported calendar; added caching loader (_load_cached_list), weekday match map loader (_load_weekday_match_map), weekday extraction and cleanup helpers (_extract_requested_weekday, _strip_requested_weekday_phrase), and leap-year scope classifier (_get_leap_year_query_scope).
Public intent handlers
__init__.py
Added handle_is_leap_year (is.leap.year.intent) and handle_weekday_match (weekday.matches.date.intent); integrated new helpers, added leap-year checks with calendar.isleap, and safer early-return parsing/control flow adjustments.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I hop through months and phrases bright,
I hunt the weekday, morning or night,
I count the leaps with careful cheer,
Match dates to days both far and near,
Tiny paws, precise delight.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Split date-time intent handler code' directly describes the main purpose: extracting and separating intent handler code from another PR to keep changes organized and focused.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/date-check-intent-handlers

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@goldyfruit
Copy link
Copy Markdown
Collaborator Author

This PR contains only the __init__.py code split out of #184.\n\n#184 now stays focused on locale resources and translation snapshots.

Copy link
Copy Markdown

@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

🧹 Nitpick comments (1)
__init__.py (1)

167-250: Avoid baking the locale parsing rules into __init__.py.

_extract_requested_weekday, _strip_requested_weekday_phrase, and _get_leap_year_query_scope only understand en and fr right now. That means every new locale for these intents needs a Python change instead of just resource updates, and any other locale will currently fall back to extract.date.error / "current" behavior. Moving these phrase lists into locale resources would keep the new intents aligned with the rest of the skill’s resource-driven translations.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@__init__.py` around lines 167 - 250, The code hardcodes English/French locale
rules in _extract_requested_weekday, _strip_requested_weekday_phrase, and
_get_leap_year_query_scope; move those phrase lists and weekday maps into locale
resources (e.g. resource keys like "weekdays", "weekday_patterns",
"leap_year_phrases" per locale) and change each function to load their
locale-specific maps/patterns via the existing resource API (falling back to a
safe default or empty dict/list); ensure _extract_requested_weekday still builds
the regex-safe names via re.escape on the resource-provided weekday keys and
that _strip_requested_weekday_phrase uses the resource phrase as the phrase to
remove, and make _get_leap_year_query_scope check resource-provided "either" and
"next" phrase lists instead of hardcoded tuples so adding locales requires only
resource updates.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@__init__.py`:
- Around line 595-597: The call to self.speak_dialog with both "date" and
"weekday" is executed even when extract_datetime(...) failed, causing
UnboundLocalError because dt and dialog are unset; update the control flow in
the handler so that the self.speak_dialog(... {"date": nice_date(...),
"weekday": nice_weekday(...)}) call is performed only inside the
successful-parse branch (the branch where extract_datetime returns a valid dt
and dialog), and leave the error branch to call the error dialog (e.g.,
"extract.date.error") without referencing dt or nice_weekday; locate
extract_datetime usage and the speak_dialog invocation to adjust the branches
accordingly.

---

Nitpick comments:
In `@__init__.py`:
- Around line 167-250: The code hardcodes English/French locale rules in
_extract_requested_weekday, _strip_requested_weekday_phrase, and
_get_leap_year_query_scope; move those phrase lists and weekday maps into locale
resources (e.g. resource keys like "weekdays", "weekday_patterns",
"leap_year_phrases" per locale) and change each function to load their
locale-specific maps/patterns via the existing resource API (falling back to a
safe default or empty dict/list); ensure _extract_requested_weekday still builds
the regex-safe names via re.escape on the resource-provided weekday keys and
that _strip_requested_weekday_phrase uses the resource phrase as the phrase to
remove, and make _get_leap_year_query_scope check resource-provided "either" and
"next" phrase lists instead of hardcoded tuples so adding locales requires only
resource updates.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b296e0de-91be-4054-b2b7-bf10a0bb3410

📥 Commits

Reviewing files that changed from the base of the PR and between d8ed365 and 3e43e1d.

📒 Files selected for processing (1)
  • __init__.py

Comment thread __init__.py
@goldyfruit goldyfruit self-assigned this Mar 9, 2026
Copy link
Copy Markdown

@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.

🧹 Nitpick comments (2)
__init__.py (2)

227-250: Avoid hardcoded leap-year scope phrases.

_get_leap_year_query_scope bakes the supported wording into code even though those variants are defined in the locale intent files. If the locale resources change, this helper can silently default back to "current" while the intent still resolves. Prefer separate intents or a structured scope value from the intent parser instead of substring checks.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@__init__.py` around lines 227 - 250, _get_leap_year_query_scope currently
hardcodes language-specific phrase lists and uses substring checks, which will
break if locale intent resources change; replace this logic by consuming the
structured scope value produced by the intent parser (or a dedicated
"leap_year_scope" intent slot) instead of inferring from utterance text, i.e.,
change callers to pass the parsed scope into _get_leap_year_query_scope (or
rename it to accept that scope) and remove the language-specific phrase
dictionaries and substring checks so the function simply returns/normalizes the
intent-provided value ("current"/"next"/"either").

167-225: Move weekday phrase matching out of Python.

These helpers duplicate weekday wording that already lives in the locale intent resources, so a translation or phrasing update can keep the intent match working while this post-parse regex starts failing and falls back to extract.date.error. Prefer passing the matched weekday from the intent layer or vocabulary files instead of reparsing raw utterances here.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@__init__.py` around lines 167 - 225, The current _extract_requested_weekday
re-parses utterances with hard-coded locale regexes; instead remove this
internal regex logic and have the date-parsing flow accept the weekday already
resolved by the intent/vocabulary layer. Update _extract_requested_weekday to
either be removed or changed to a thin adapter that returns the weekday tuple
only when a weekday slot/parameter is provided by the caller, and change callers
to pass the intent-provided weekday (name or index) into
_strip_requested_weekday_phrase; adjust _strip_requested_weekday_phrase to
accept the weekday tuple or simple weekday name/index and only perform phrase
stripping (no language-specific regex matching of raw utterances). Ensure
callers of _extract_requested_weekday and _strip_requested_weekday_phrase (same
symbol names) are updated to supply the intent slot value so locale translations
live in the intent resources rather than in these functions.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@__init__.py`:
- Around line 227-250: _get_leap_year_query_scope currently hardcodes
language-specific phrase lists and uses substring checks, which will break if
locale intent resources change; replace this logic by consuming the structured
scope value produced by the intent parser (or a dedicated "leap_year_scope"
intent slot) instead of inferring from utterance text, i.e., change callers to
pass the parsed scope into _get_leap_year_query_scope (or rename it to accept
that scope) and remove the language-specific phrase dictionaries and substring
checks so the function simply returns/normalizes the intent-provided value
("current"/"next"/"either").
- Around line 167-225: The current _extract_requested_weekday re-parses
utterances with hard-coded locale regexes; instead remove this internal regex
logic and have the date-parsing flow accept the weekday already resolved by the
intent/vocabulary layer. Update _extract_requested_weekday to either be removed
or changed to a thin adapter that returns the weekday tuple only when a weekday
slot/parameter is provided by the caller, and change callers to pass the
intent-provided weekday (name or index) into _strip_requested_weekday_phrase;
adjust _strip_requested_weekday_phrase to accept the weekday tuple or simple
weekday name/index and only perform phrase stripping (no language-specific regex
matching of raw utterances). Ensure callers of _extract_requested_weekday and
_strip_requested_weekday_phrase (same symbol names) are updated to supply the
intent slot value so locale translations live in the intent resources rather
than in these functions.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: bd8c6480-a5e5-4858-b38a-6809d8cf8983

📥 Commits

Reviewing files that changed from the base of the PR and between 3e43e1d and 355b2ad.

📒 Files selected for processing (1)
  • __init__.py

@goldyfruit
Copy link
Copy Markdown
Collaborator Author

The hardcoded language-specific weekday/leap-year parsing rules have been removed from this branch.\n\nThe matching locale resources now live on #184, so this PR stays code-only while #184 carries the parser data files.

Copy link
Copy Markdown

@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

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@__init__.py`:
- Around line 167-187: The cached resources in _load_cached_list and
_load_weekday_match_map are stored under fixed keys and therefore collide across
different locales; update the cache keys to include the instance language
(self.lang) so they are keyed per-language (e.g., use f"{self.lang}.{name}.list"
in _load_cached_list and f"{self.lang}.weekday.match.weekdays.value" in
_load_weekday_match_map), keep the rest of the loading logic the same, and
ensure you reference the new cache_key variable when reading/writing
self.resources.static so each TimeSkill instance caches locale-specific data
separately.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e38658b7-e86e-4ae8-b01a-880f7d186d7a

📥 Commits

Reviewing files that changed from the base of the PR and between 355b2ad and 3522a37.

📒 Files selected for processing (1)
  • __init__.py

Comment thread __init__.py
@mikejgray
Copy link
Copy Markdown
Collaborator

@goldyfruit thanks for splitting these out — and I owe you a clearer explanation of what I was actually asking for on #184. My "intents have no handlers" feedback was about the PR being un-mergeable in isolation, not about the file split itself. Splitting #184 into intent-files-only and #188 for handler code addresses the literal text of my comment but creates a new operational problem.

The biggest issue is the release workflow. Each merged PR triggers publish_alpha, which cuts a new alpha release on PyPI. If we merge #184 and #188 separately, that's two alpha releases — and one of them is necessarily incomplete (either intents with no handlers, or handlers with no intent files to fire them). We should prefer a single working update.

There's also a secondary concern: if #184 lands first, the intents fire with no handlers. If #188 lands first, the handlers try to read .list files that don't exist yet. There's no safe ordering.

The cleaner fix is to recombine #184 and #188 into a single PR that contains the intent files, the locale resources, and the matching handler code in __init__.py. That makes the change atomically reviewable, atomically mergeable, and produces exactly one alpha release.

A few thoughts on doing the recombine:

Sorry for the back-and-forth. The split was a reasonable interpretation of what I asked for, but in retrospect I should have said "make this PR self-contained" instead of "the intents have no handlers." Let me know if you'd rather I reopen #184 with the combined work myself, or if you want to drive the recombine.

@goldyfruit
Copy link
Copy Markdown
Collaborator Author

Superseded by #184. The handler code has been recombined into that branch so the feature can merge as one self-contained alpha update.

@goldyfruit goldyfruit closed this Apr 7, 2026
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