{"id":25236759,"url":"https://github.com/mttbernardini/datetypes","last_synced_at":"2025-07-18T03:34:22.343Z","repository":{"id":276934026,"uuid":"930777149","full_name":"mttbernardini/datetypes","owner":"mttbernardini","description":"Typed counterparts for built-in datetime module classes with zero runtime overhead","archived":false,"fork":false,"pushed_at":"2025-02-11T07:57:06.000Z","size":18,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-11T08:42:54.306Z","etag":null,"topics":["datetime","python","python-types","python-typing","timezone","type-annotations"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mttbernardini.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-02-11T07:36:42.000Z","updated_at":"2025-02-11T07:57:09.000Z","dependencies_parsed_at":"2025-02-11T08:52:55.969Z","dependency_job_id":null,"html_url":"https://github.com/mttbernardini/datetypes","commit_stats":null,"previous_names":["mttbernardini/datetypes"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mttbernardini%2Fdatetypes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mttbernardini%2Fdatetypes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mttbernardini%2Fdatetypes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mttbernardini%2Fdatetypes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mttbernardini","download_url":"https://codeload.github.com/mttbernardini/datetypes/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247378147,"owners_count":20929297,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["datetime","python","python-types","python-typing","timezone","type-annotations"],"created_at":"2025-02-11T15:31:49.229Z","updated_at":"2025-04-05T18:13:20.684Z","avatar_url":"https://github.com/mttbernardini.png","language":"Python","readme":"# datetypes\n\n```python\nfrom datetime import date, time, datetime, timezone\nfrom datetypes import Date, Time, DateTime, NaiveDateTime\n\nt = Time(12, 0)\nd = Date(2025, 2, 1)\ndt = DateTime.combine(d, t)\n\n# at type-checking, timezone info is carried via generics\nassert_type(dt, DateTime[None])\n# or, using an alias\nassert_type(dt, NaiveDateTime)\n\n# detect timezone incompatible comparisons\nTime(12, 0, tzinfo=timezone.utc) \u003c t  # mypy error! cannot compare Time[timezone] with Time[None]\n\n# DateTime doesn't subclass Date\ndef message(d: Date):\n    print(f\"Hello, date is: {d}\")\nmessage(dt) # mypy error! DateTime is not compatible with Date\n\n# at runtime, built-in types are used, zero overhead\ntype(d) is date\ntype(t) is time\ntype(dt) is datetime\n```\n\nAn effort to provide type annotated and timezone-aware versions of the built-in\n`datetime` module, only for static typing. At runtime the built-in classes from\n`datetime` will always be used with zero overhead, including when evaluating\ntype annotations at runtime (e.g. Pydantic, FastAPI, etc.).\n\nGreatly inspired by [`datetype`](https://github.com/glyph/DateType), but\nre-imagined to provide no runtime behaviour changes (the typed symbols are\nsimply aliases over the built-in types) + clean type information subclassing\ntypes from `datetime`, so that typed counterparts can be used in places where\noriginal types are expected (e.g. existing libraries) without having to manually\ncast (as compared to `datetype.concrete()`).\n\n## Caveats\n\nSince at runtime the typed versions are simply aliases to the built-in types,\ngenerics don't work when used in runtime contexts! i.e. don't do\n`DateTime[ZoneInfo]` in an expression that can be evaluated at runtime, it will\nfail without being caught by your type linter (as the type stubs make this use\nlegit!). I currently don't have any non-invasive workaround for this, but I\nexpect this library to be mainly used for static type annotations.\n\n## Documentation\n\nWIP, but for examples simply refer to [tests/test_basic.py](tests/test_basic.py)\nand other test files.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmttbernardini%2Fdatetypes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmttbernardini%2Fdatetypes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmttbernardini%2Fdatetypes/lists"}