powertools-lambda-python icon indicating copy to clipboard operation
powertools-lambda-python copied to clipboard

Bug: SCHEDULE_BETWEEN_DAYS_OF_WEEK stops matching when LC_TIME is not English

Open anishmehta24 opened this issue 1 month ago • 5 comments

Expected Behaviour

A SCHEDULE_BETWEEN_DAYS_OF_WEEK rule with "DAYS": ["FRIDAY"] matches on Fridays whatever locale the function runs with.

Current Behaviour

compare_days_of_week gets the current day with strftime("%A").upper(), which names the day in the process's LC_TIME locale. If the function calls locale.setlocale(locale.LC_TIME, ...) (or LC_ALL) for a non-English locale, the day comes back as FREITAG, VENDREDI, etc., never equals the English names the schema requires, and every day-of-week rule silently stops matching.

Code snippet

import locale
from aws_lambda_powertools.utilities.feature_flags.comparators import compare_days_of_week

cond = {"DAYS": ["FRIDAY"], "TIMEZONE": "UTC"}  # run on a Friday
compare_days_of_week(None, cond)  # True

locale.setlocale(locale.LC_TIME, "de_DE.UTF-8")
compare_days_of_week(None, cond)  # False, the current day is "FREITAG"

Steps to Reproduce

  1. Configure a feature flag rule with SCHEDULE_BETWEEN_DAYS_OF_WEEK and today's day in DAYS.
  2. Set a non-English LC_TIME in the function.
  3. Evaluate the flag: the rule no longer matches.

Possible Solution

Look the day up from datetime.weekday() (Monday is 0) instead of formatting its name, so the result does not depend on the locale. I can open a PR.

Powertools for AWS Lambda (Python) version

latest (develop, 3.38.0)

AWS Lambda function runtime

3.12

Packaging format used

PyPi

Debugging logs

No response

anishmehta24 avatar Oct 30 '26 16:10 anishmehta24

Thanks for opening your first issue here! We'll come back to you as soon as we can. In the meantime, check out the #python channel on our Powertools for AWS Lambda Discord: Invite link

boring-cyborg[bot] avatar Oct 30 '26 16:10 boring-cyborg[bot]

Thanks for opening your first issue here! We'll come back to you as soon as we can. In the meantime, check out our GitHub Discussions: Join the conversation

Thanks @anishmehta24, confirmed with de_DE here, the day comes back as FREITAG. Honestly most people never touch the locale in Lambda, but comparing against weekday() is the right thing anyway. I'll review #8707. Goes into 3.40.0.

leandrodamascena avatar Oct 30 '26 17:10 leandrodamascena

[!warning] This issue is now closed. Please be mindful that future comments are hard for our team to see. If you need more assistance, please either reopen the issue, or open a new issue referencing this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.

This is now released under 3.40.0 version!

github-actions[bot] avatar Nov 10 '26 11:11 github-actions[bot]