-
First Check
Commit to Help
Example Codeimport datetime
from typing import Optional
import typer
from rich import print
def main(now: Optional[datetime.datetime] = typer.Option(None)):
print(f"now: {now}")
if __name__ == "__main__":
typer.run(main)DescriptionSo the previous code runs easily with: python foo.py --now 2024-07-06T01:05:00But it crashes if I add timezone information python foo.py --now 2024-07-06T01:05:00+05:00The error I'm given is: Operating SystemWindows Operating System DetailsNo response Typer Version0.12.3 Python VersionPython 3.9.7 Additional ContextNo response |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
Hi! You can find the answer to your question in the documentation here: https://typer.tiangolo.com/tutorial/parameter-types/datetime/#custom-date-format In short, Typer allows you to specify the date formats that should be used instead of relying on the default ones. You can edit your code to something like this: With |
Beta Was this translation helpful? Give feedback.
Hi!
You can find the answer to your question in the documentation here: https://typer.tiangolo.com/tutorial/parameter-types/datetime/#custom-date-format
In short, Typer allows you to specify the date formats that should be used instead of relying on the default ones.
You can edit your code to something like this:
With
%zreferring to the timezone offset (see here) and then it should be able to parse your input string.