{"id":18707517,"url":"https://github.com/pydantic/speedate","last_synced_at":"2025-05-14T18:04:03.853Z","repository":{"id":37926591,"uuid":"496006028","full_name":"pydantic/speedate","owner":"pydantic","description":"Fast and simple datetime, date, time and duration parsing for rust.","archived":false,"fork":false,"pushed_at":"2025-03-03T09:52:10.000Z","size":149,"stargazers_count":220,"open_issues_count":8,"forks_count":21,"subscribers_count":10,"default_branch":"main","last_synced_at":"2025-04-13T12:45:53.858Z","etag":null,"topics":["date","datetime","iso8601","parse","parser","pydantic","rfc3339","rust","time","timezone"],"latest_commit_sha":null,"homepage":"https://docs.rs/speedate/latest/speedate/","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pydantic.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","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},"funding":{"github":"samuelcolvin"}},"created_at":"2022-05-24T22:26:51.000Z","updated_at":"2025-04-09T09:42:25.000Z","dependencies_parsed_at":"2023-11-06T12:39:31.870Z","dependency_job_id":"b9dde96c-419c-4ca1-8dab-f67aae45af22","html_url":"https://github.com/pydantic/speedate","commit_stats":null,"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pydantic%2Fspeedate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pydantic%2Fspeedate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pydantic%2Fspeedate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pydantic%2Fspeedate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pydantic","download_url":"https://codeload.github.com/pydantic/speedate/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254198452,"owners_count":22030964,"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":["date","datetime","iso8601","parse","parser","pydantic","rfc3339","rust","time","timezone"],"created_at":"2024-11-07T12:18:44.844Z","updated_at":"2025-05-14T18:04:03.323Z","avatar_url":"https://github.com/pydantic.png","language":"Rust","readme":"# speedate\n\n[![CI](https://github.com/pydantic/speedate/actions/workflows/ci.yml/badge.svg?event=push)](https://github.com/pydantic/speedate/actions/workflows/ci.yml?query=branch%3Amain)\n[![Coverage](https://codecov.io/gh/pydantic/speedate/branch/main/graph/badge.svg)](https://codecov.io/gh/pydantic/speedate)\n[![Crates.io](https://img.shields.io/crates/v/speedate?color=green)](https://crates.io/crates/speedate)\n\nFast and simple datetime, date, time and duration parsing for rust.\n\n**speedate** is a lax† **RFC 3339** date and time parser, in other words, it parses common **ISO 8601**\nformats.\n\n**†** - all relaxations of from [RFC 3339](https://tools.ietf.org/html/rfc3339)\nare compliant with [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601).\n\nThe following formats are supported:\n* Date: `YYYY-MM-DD`\n* Time: `HH:MM:SS`\n* Time: `HH:MM:SS.FFFFFF` 1 to 6 digits are reflected in the `time.microsecond`, extra digits are ignored\n* Time: `HH:MM`\n* Date time: `YYYY-MM-DDTHH:MM:SS` - all the above time formats are allowed for the time part\n* Date time: `YYYY-MM-DD HH:MM:SS` - `T`, `t`, ` ` and `_` are allowed as separators\n* Date time: `YYYY-MM-DDTHH:MM:SSZ` - `Z` or `z` is allowed as timezone\n* Date time: `YYYY-MM-DDTHH:MM:SS+08:00`- positive and negative timezone are allowed, as per ISO 8601, U+2212 minus `−`\n  is allowed as well as ascii minus `-` (U+002D)\n* Date time: `YYYY-MM-DDTHH:MM:SS+0800` - the colon (`:`) in the timezone is optional\n* Duration: `PnYnMnDTnHnMnS` - ISO 8601 duration format,\n  see [wikipedia](https://en.wikipedia.org/wiki/ISO_8601#Durations) for more details, `W` for weeks is also allowed\n* Duration: `HH:MM:SS` - any of the above time formats are allowed to represent a duration\n* Duration: `D days, HH:MM:SS` - time prefixed by `X days`, case-insensitive, spaces `s` and `,` are all optional\n* Duration: `D d, HH:MM:SS` - time prefixed by `X d`, case-insensitive, spaces and `,` are optional\n* Duration: `±...` - all duration formats shown here can be prefixed with `+` or `-` to indicate\n  positive and negative durations respectively\n\nIn addition, unix timestamps (both seconds and milliseconds) can be used to create dates and datetimes.\n\nSee [the documentation](https://docs.rs/speedate/latest/speedate/index.html#structs) for each struct for more details.\n\nThis will be the datetime parsing logic for [pydantic-core](https://github.com/pydantic/pydantic-core).\n\n## Usage\n\n```rust\nuse speedate::{DateTime, Date, Time};\n\nlet dt = DateTime::parse_str(\"2022-01-01T12:13:14Z\").unwrap();\nassert_eq!(\n    dt,\n    DateTime {\n        date: Date {\n            year: 2022,\n            month: 1,\n            day: 1,\n        },\n        time: Time {\n            hour: 12,\n            minute: 13,\n            second: 14,\n            microsecond: 0,\n            tz_offset: Some(0),\n        },\n    }\n);\nassert_eq!(dt.to_string(), \"2022-01-01T12:13:14Z\");\n```\n\nTo control the specifics of time parsing you can use provide a `TimeConfig`:\n\n```rust\nuse speedate::{DateTime, Date, Time, TimeConfig, MicrosecondsPrecisionOverflowBehavior};\nlet dt = DateTime::parse_bytes_with_config(\n    \"1689102037.5586429\".as_bytes(),\n    \u0026TimeConfig::builder()\n        .unix_timestamp_offset(Some(0))\n        .microseconds_precision_overflow_behavior(MicrosecondsPrecisionOverflowBehavior::Truncate)\n        .build(),\n).unwrap();\nassert_eq!(\n    dt,\n    DateTime {\n        date: Date {\n            year: 2023,\n            month: 7,\n            day: 11,\n        },\n        time: Time {\n            hour: 19,\n            minute: 0,\n            second: 37,\n            microsecond: 558643,\n            tz_offset: Some(0),\n        },\n    }\n);\nassert_eq!(dt.to_string(), \"2023-07-11T19:00:37.558643Z\");\n```\n\n## Performance\n\n**speedate** is significantly faster than\n[chrono's `parse_from_rfc3339`](https://docs.rs/chrono/latest/chrono/struct.DateTime.html#method.parse_from_rfc3339)\nand [iso8601](https://crates.io/crates/iso8601).\n\nMicro-benchmarking from [`benches/main.rs`](https://github.com/pydantic/speedate/blob/main/benches/main.rs):\n\n```text\ntest datetime_error_speedate ... bench:           6 ns/iter (+/- 0)\ntest datetime_error_chrono   ... bench:          50 ns/iter (+/- 1)\ntest datetime_error_iso8601  ... bench:         118 ns/iter (+/- 2)\ntest datetime_ok_speedate    ... bench:           9 ns/iter (+/- 0)\ntest datetime_ok_chrono      ... bench:         182 ns/iter (+/- 0)\ntest datetime_ok_iso8601     ... bench:          77 ns/iter (+/- 1)\ntest duration_ok_speedate    ... bench:          23 ns/iter (+/- 0)\ntest duration_ok_iso8601     ... bench:          48 ns/iter (+/- 0)\ntest timestamp_ok_speedate   ... bench:           9 ns/iter (+/- 0)\ntest timestamp_ok_chrono     ... bench:          10 ns/iter (+/- 0)\n```\n\n## Why not full iso8601?\n\nISO8601 allows many formats, see\n[ijmacd.github.io/rfc3339-iso8601](https://ijmacd.github.io/rfc3339-iso8601/).\n\nMost of these are unknown to most users, and not desired. This library aims to support the most common formats\nwithout introducing ambiguity.\n","funding_links":["https://github.com/sponsors/samuelcolvin"],"categories":["Rust"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpydantic%2Fspeedate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpydantic%2Fspeedate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpydantic%2Fspeedate/lists"}