{"id":19543288,"url":"https://github.com/uutils/parse_datetime","last_synced_at":"2025-12-12T14:11:09.131Z","repository":{"id":154073300,"uuid":"631627650","full_name":"uutils/parse_datetime","owner":"uutils","description":"Parses a relative time string and returns a `Duration` ","archived":false,"fork":false,"pushed_at":"2025-02-26T12:44:40.000Z","size":230,"stargazers_count":24,"open_issues_count":14,"forks_count":21,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-03-29T01:03:12.652Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/uutils.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"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}},"created_at":"2023-04-23T16:10:32.000Z","updated_at":"2025-03-27T21:30:27.000Z","dependencies_parsed_at":"2024-01-21T17:23:48.884Z","dependency_job_id":"1d81c13d-aeb3-4f24-9df6-a4aa6948f844","html_url":"https://github.com/uutils/parse_datetime","commit_stats":null,"previous_names":["uutils/parse_datetime","uutils/humantime_to_duration"],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uutils%2Fparse_datetime","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uutils%2Fparse_datetime/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uutils%2Fparse_datetime/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uutils%2Fparse_datetime/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/uutils","download_url":"https://codeload.github.com/uutils/parse_datetime/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247276159,"owners_count":20912288,"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":[],"created_at":"2024-11-11T03:18:12.616Z","updated_at":"2025-12-12T14:11:09.095Z","avatar_url":"https://github.com/uutils.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# parse_datetime\n\n[![Crates.io](https://img.shields.io/crates/v/parse_datetime.svg)](https://crates.io/crates/parse_datetime)\n[![License](http://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/uutils/parse_datetime/blob/main/LICENSE)\n[![CodeCov](https://codecov.io/gh/uutils/parse_datetime/branch/main/graph/badge.svg)](https://codecov.io/gh/uutils/parse_datetime)\n\nA Rust crate for parsing human-readable relative time strings and human-readable datetime strings and converting them to a `DateTime`.\n\n## Features\n\n- Parses a variety of human-readable and standard time formats.\n- Supports positive and negative durations.\n- Allows for chaining time units (e.g., \"1 hour 2 minutes\" or \"2 days and 2 hours\").\n- Calculate durations relative to a specified date.\n- Relies on Chrono\n\n## Usage\n\nAdd `parse_datetime` to your `Cargo.toml` with:\n\n```\ncargo add parse_datetime\n```\n\nThen, import the crate and use the `parse_datetime_at_date` function:\n\n```rs\nuse chrono::{Duration, Local};\nuse parse_datetime::parse_datetime_at_date;\n\nlet now = Local::now();\nlet after = parse_datetime_at_date(now, \"+3 days\");\n\nassert_eq!(\n  (now + Duration::days(3)).naive_utc(),\n  after.unwrap().naive_utc()\n);\n```\n\nFor DateTime parsing, import the `parse_datetime` function:\n\n```rs\nuse parse_datetime::parse_datetime;\nuse chrono::{Local, TimeZone};\n\nlet dt = parse_datetime(\"2021-02-14 06:37:47\");\nassert_eq!(dt.unwrap(), Local.with_ymd_and_hms(2021, 2, 14, 6, 37, 47).unwrap());\n```\n\n### Supported Formats\n\nThe `parse_datetime` and `parse_datetime_at_date` functions support absolute datetime and the following relative times:\n\n- `num` `unit` (e.g., \"-1 hour\", \"+3 days\")\n- `unit` (e.g., \"hour\", \"day\")\n- \"now\" or \"today\"\n- \"yesterday\"\n- \"tomorrow\"\n- use \"ago\" for the past\n- use \"next\" or \"last\" with `unit` (e.g., \"next week\", \"last year\")\n- combined units with \"and\" or \",\" (e.g., \"2 years and 1 month\", \"1 day, 2 hours\" or \"2 weeks 1 second\")\n- unix timestamps (for example \"@0\" \"@1344000\")\n\n`num` can be a positive or negative integer.\n`unit` can be one of the following: \"fortnight\", \"week\", \"day\", \"hour\", \"minute\", \"min\", \"second\", \"sec\" and their plural forms.\n\n## Return Values\n\n### parse_datetime and parse_datetime_at_date\n\nThe `parse_datetime` and `parse_datetime_at_date` function return:\n\n- `Ok(DateTime\u003cFixedOffset\u003e)` - If the input string can be parsed as a datetime\n- `Err(ParseDateTimeError::InvalidInput)` - If the input string cannot be parsed\n\n## Fuzzer\n\nTo run the fuzzer:\n\n```\n$ cd fuzz\n$ cargo install cargo-fuzz\n$ cargo +nightly fuzz run fuzz_parse_datetime\n```\n\n## License\n\nThis project is licensed under the [MIT License](LICENSE).\n\n## Note\n\nAt some point, this crate was called humantime_to_duration.\nIt has been renamed to cover more cases.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuutils%2Fparse_datetime","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fuutils%2Fparse_datetime","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuutils%2Fparse_datetime/lists"}