Title: Use `datetime.timedelta` to Represent Time Periods · Issue #4575 · python-telegram-bot/python-telegram-bot · GitHub
Open Graph Title: Use `datetime.timedelta` to Represent Time Periods · Issue #4575 · python-telegram-bot/python-telegram-bot
X Title: Use `datetime.timedelta` to Represent Time Periods · Issue #4575 · python-telegram-bot/python-telegram-bot
Description: What kind of feature are you missing? Where do you notice a shortcoming of PTB? Several Telegram Objects and methods currently contain fields/parameters with names \w+_period, wherer the integer value represents a time span in seconds. W...
Open Graph Description: What kind of feature are you missing? Where do you notice a shortcoming of PTB? Several Telegram Objects and methods currently contain fields/parameters with names \w+_period, wherer the integer va...
X Description: What kind of feature are you missing? Where do you notice a shortcoming of PTB? Several Telegram Objects and methods currently contain fields/parameters with names \w+_period, wherer the integer va...
Opengraph URL: https://github.com/python-telegram-bot/python-telegram-bot/issues/4575
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Use `datetime.timedelta` to Represent Time Periods","articleBody":"### What kind of feature are you missing? Where do you notice a shortcoming of PTB?\n\nSeveral Telegram Objects and methods currently contain fields/parameters with names `\\w+_period`, wherer the integer value represents a time span in seconds.\nWorking with plain seconds is not very pythonic, just like working with posix timestamps isn't. \n\n### Describe the solution you'd like\n\nIn the long run, we should convert the attributes to `timedelta` objects and make the parameters accept timedelta objects.\n\n#### Methods Parameters\n\nThis is realtively easy, simply accept `timedelta` as well as integers and pass `totalseconds()` to TG. Converting `dtm.timedelta` to `int` can probably be done in the internals of `Bot` or requests so that it doesn't have to happen in each bot method.\n\n#### Classes\n\n* Both attributes and arguments should *only* accept timedeltas in the long run.\n* Since this is a breaking change, we should issue a warning for now about this changing in the future and encouraging users to harden their code against the change\n* For making the `timedelta` support available early, I have two ideas, ~both optional~\n * ~We can provide a temporary property that returns the timedelta object (e.g. `xy_period_timedelta`). This would need to issue a warning stating that it will be removed once `timedelta` is natively supported. Not overly clean …~\n * We anyways need to make the `*_period` attributes properties to issue the deprecation warning. We could use this and look for an environment variable, say `PTB_TIMEDELTA`. If set, we return the timedelta object, otherwise the `int`. → let's do this\n\n### Describe alternatives you've considered\n\n_No response_\n\n### Additional context\n\nAdding support for method parameters can be done independently of handling classes.","author":{"url":"https://github.com/Bibo-Joshi","@type":"Person","name":"Bibo-Joshi"},"datePublished":"2024-11-24T21:13:20.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":5},"url":"https://github.com/4575/python-telegram-bot/issues/4575"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:3d01b091-4afc-ce64-69d4-ee23d892f0f7 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 96B0:25CE84:75A370:9E1D00:6A5B3D14 |
| html-safe-nonce | 4e622b92c93a34e9324fc32321b30cf87c11c697a502bd4dbac90ac436d7b884 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NkIwOjI1Q0U4NDo3NUEzNzA6OUUxRDAwOjZBNUIzRDE0IiwidmlzaXRvcl9pZCI6IjUwNjY4NzcxMzM5NjIwMzQ0NTIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | eafb0ceaf23cff4dd637919b78e90c159335355b1e0b0a5e932095c80d619705 |
| hovercard-subject-tag | issue:2688392527 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python-telegram-bot/python-telegram-bot/4575/issue_layout |
| twitter:image | https://opengraph.githubassets.com/9e70b96fc2bf54d3d3379954a339c47954e79102e235e0c1e9c85ff1856a38f3/python-telegram-bot/python-telegram-bot/issues/4575 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/9e70b96fc2bf54d3d3379954a339c47954e79102e235e0c1e9c85ff1856a38f3/python-telegram-bot/python-telegram-bot/issues/4575 |
| og:image:alt | What kind of feature are you missing? Where do you notice a shortcoming of PTB? Several Telegram Objects and methods currently contain fields/parameters with names \w+_period, wherer the integer va... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Bibo-Joshi |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5290d7e14309ad1e76106a9c4237bd1041517e83ea182c8ab756752cb0c6940b |
| turbo-cache-control | no-preview |
| go-import | github.com/python-telegram-bot/python-telegram-bot git https://github.com/python-telegram-bot/python-telegram-bot.git |
| octolytics-dimension-user_id | 16178365 |
| octolytics-dimension-user_login | python-telegram-bot |
| octolytics-dimension-repository_id | 38696925 |
| octolytics-dimension-repository_nwo | python-telegram-bot/python-telegram-bot |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 38696925 |
| octolytics-dimension-repository_network_root_nwo | python-telegram-bot/python-telegram-bot |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 9c975978430e9ad293956f2bbdaf153b1bd84a99 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width