Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Convenience Functionalty for BusinessOpeningHours #4194

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

Open
Bibo-Joshi opened this issue Apr 7, 2024 · 0 comments
Open

Convenience Functionalty for BusinessOpeningHours #4194

Bibo-Joshi opened this issue Apr 7, 2024 · 0 comments

Comments

@Bibo-Joshi
Copy link
Member

What kind of feature are you missing? Where do you notice a shortcoming of PTB?

API 7.2 introduced BusinessOpeningHours and BOHInterval. Parsing this information for different use cases can require some logic on the bot side. It would be nice to have functionality that allows to

  • check if the business is open at a given time
  • get the opening hours for a given day

Both should be able to deal with timezones

Describe the solution you'd like

Add a method BOH.get_opening_hours_for_day(dtm.date, tzinfo=None) -> tuple[tuple[dtm.datetime, dtm.datetime], …].
The user would provide a specific day and optionally a timezone/tzinfo object and get as return value a sequence of the opening intervals for that day in the desired timezone. If no tzinfo is provided, `BOH.time_zone_namez should be used

Add a method BOH.is_open(dtm.datetime) -> bool, i.e. a method that would allow you to check if the business is open at that specified time. If the parameter is tz-aware, the return value should be considered for that timezone. If it's timezone naive, it should be considered in BOH.time_zone_name.

Describe alternatives you've considered

No response

Additional context

See discussion in #4183

Handling of timezones currently requires additional dependencies like pytz. Once we drop support for Python3.8, we can instead use zoneinfo which as added to the std-lib in py3.9. Adding the 1st-party lib tzdata as required dependency to PTB would probably not be a bummer to me, though I'd also be okay with not doing that and instead giving hints to users that they might need to install that.

gtkacz added a commit to gtkacz/python-telegram-bot that referenced this issue Jun 26, 2024
gtkacz added a commit to gtkacz/python-telegram-bot that referenced this issue Jul 20, 2024
@harshil21 harshil21 moved this to 3.9 - starting 10-2024 in Python Versions for PTB Aug 11, 2024
@github-project-automation github-project-automation bot moved this to 3.9 - starting 10-2024 in Python Versions Aug 28, 2024
gtkacz added a commit to gtkacz/python-telegram-bot that referenced this issue Sep 2, 2024
gtkacz added a commit to gtkacz/python-telegram-bot that referenced this issue Sep 15, 2024
@Bibo-Joshi Bibo-Joshi changed the title [FEATURE] Convenience Functionalty for BusinessOpeningHours Convenience Functionalty for BusinessOpeningHours Nov 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 3.9 - starting 10-2024
Status: 3.9 - starting 10-2024
Development

Successfully merging a pull request may close this issue.

1 participant