Skip to content

fix(feature_flags): handle same-hour midnight rollover and reject malformed HH:MM - #8428

Open
dreamorosi wants to merge 1 commit into
developfrom
fix/time-range-rollover-and-validation
Open

fix(feature_flags): handle same-hour midnight rollover and reject malformed HH:MM#8428
dreamorosi wants to merge 1 commit into
developfrom
fix/time-range-rollover-and-validation

Conversation

@dreamorosi

@dreamorosi dreamorosi commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Issue number: closes #8423

Summary

Changes

SCHEDULE_BETWEEN_TIME_RANGE now treats any range whose end is earlier than its start on the clock as crossing midnight, and schema validation only accepts values that are exactly HH:MM.

Rollover was decided by comparing hours alone, so a range like START: "23:30", END: "23:00" (equal hours) fell into the same-day branch start <= now <= end, which can never hold. The comparator now compares minutes since midnight.

Separately, TIME_RANGE_PATTERN was unanchored and used with re.match, so "10:00abc" validated and then raised inside int() at evaluation time, where _match_by_action swallows the error and returns False. The pattern is now anchored (^(?:2[0-3]|[01]\d):[0-5]\d$) so the misconfiguration surfaces as a SchemaValidationError.

Regression tests cover a same-hour overnight range at a time inside it (10:00) and at the only uncovered gap (23:15), plus malformed START/END strings with trailing or leading garbage and extra digits. All four new cases fail against the previous code.

This also aligns evaluation with the TypeScript port in aws-powertools/powertools-lambda-typescript#5614.

User experience

Before

  • A rule with {"START": "23:30", "END": "23:00"} silently never matched, at any time of day.
  • A rule with {"START": "10:00abc", "END": "12:00"} passed SchemaValidator().validate() and then silently evaluated to False.

After

  • {"START": "23:30", "END": "23:00"} matches from 23:30 through 23:00 the next day, i.e. everything except 23:00-23:30.
  • {"START": "10:00abc", "END": "12:00"} raises SchemaValidationError: 'START' and 'END' must be a valid time format, time_format=%H:%M, rule=... at validation time.

Existing valid HH:MM configurations are unaffected.


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

…formed HH:MM

SCHEDULE_BETWEEN_TIME_RANGE decided whether a range crossed midnight by
comparing hours only, so a range like 23:30 -> 23:00 (equal hours) took
the same-day branch and could never match. Compare minutes since midnight
instead.

TIME_RANGE_PATTERN was unanchored and used with re.match, so values such
as "10:00abc" passed schema validation and then failed silently at
evaluation time. Anchor the pattern so only exact HH:MM strings validate.

Fixes #8423
@powertools-for-aws-oss-automation powertools-for-aws-oss-automation Bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Sep 3, 2026
@boring-cyborg boring-cyborg Bot added the tests label Sep 3, 2026
@sonarqubecloud

sonarqubecloud Bot commented Sep 3, 2026

Copy link
Copy Markdown

@codecov

codecov Bot commented Sep 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.65%. Comparing base (a39e101) to head (832691b).
⚠️ Report is 2 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #8428   +/-   ##
========================================
  Coverage    96.65%   96.65%           
========================================
  Files          296      296           
  Lines        14767    14769    +2     
  Branches      1246     1246           
========================================
+ Hits         14273    14275    +2     
  Misses         359      359           
  Partials       135      135           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dreamorosi
dreamorosi marked this pull request as ready for review September 3, 2026 16:26
@dreamorosi
dreamorosi requested a review from a team as a code owner September 3, 2026 16:26
@dreamorosi
dreamorosi requested review from hjgraca and leandrodamascena and removed request for hjgraca September 3, 2026 16:26
@leandrodamascena

Copy link
Copy Markdown
Contributor

I'll review this by tomorrow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do-not-merge size/M Denotes a PR that changes 30-99 lines, ignoring generated files. tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: SCHEDULE_BETWEEN_TIME_RANGE mishandles same-hour midnight rollover and accepts malformed HH:MM

2 participants