{"id":16616899,"url":"https://github.com/sebastienrousseau/dtt","last_synced_at":"2026-06-07T20:01:09.805Z","repository":{"id":90289994,"uuid":"599490160","full_name":"sebastienrousseau/dtt","owner":"sebastienrousseau","description":"A Rust library for parsing, validating, manipulating, and formatting dates and times 🦀","archived":false,"fork":false,"pushed_at":"2024-10-21T05:46:37.000Z","size":4387,"stargazers_count":6,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-10-21T08:37:20.736Z","etag":null,"topics":["date","datetime","dtt","rust","time","timezone"],"latest_commit_sha":null,"homepage":"https://dttlib.com/","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sebastienrousseau.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":".github/funding.yml","license":"LICENSE-APACHE","code_of_conduct":".github/CODE-OF-CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":".github/SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":"AUTHORS.md","dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"sebastienrousseau","custom":"https://paypal.me/wwdseb"}},"created_at":"2023-02-09T08:48:09.000Z","updated_at":"2024-10-21T05:46:38.000Z","dependencies_parsed_at":"2024-01-12T23:28:18.197Z","dependency_job_id":"40171ae7-d828-4ceb-8eda-fcede251c8f7","html_url":"https://github.com/sebastienrousseau/dtt","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/sebastienrousseau/dtt","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sebastienrousseau%2Fdtt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sebastienrousseau%2Fdtt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sebastienrousseau%2Fdtt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sebastienrousseau%2Fdtt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sebastienrousseau","download_url":"https://codeload.github.com/sebastienrousseau/dtt/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sebastienrousseau%2Fdtt/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279007136,"owners_count":26084246,"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","status":"online","status_checked_at":"2025-10-11T02:00:06.511Z","response_time":55,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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","dtt","rust","time","timezone"],"created_at":"2024-10-12T02:14:35.629Z","updated_at":"2025-10-11T12:10:26.968Z","avatar_url":"https://github.com/sebastienrousseau.png","language":"Rust","funding_links":["https://github.com/sponsors/sebastienrousseau","https://paypal.me/wwdseb"],"categories":[],"sub_categories":[],"readme":"\u003c!-- markdownlint-disable MD033 MD041 --\u003e\n\u003cimg src=\"https://kura.pro/dtt/images/logos/dtt.svg\"\nalt=\"DateTime (DTT) logo\" height=\"66\" align=\"right\" /\u003e\n\u003c!-- markdownlint-enable MD033 MD041 --\u003e\n\n# `DateTime` (DTT)\n\nA Rust library for parsing, validating, manipulating, and formatting dates and times.\n\n[![Made With Love][made-with-rust]][14] [![Crates.io][crates-badge]][08] [![lib.rs][libs-badge]][10] [![Docs.rs][docs-badge]][09] [![Codecov][codecov-badge]][15] [![Build Status][build-badge]][16] [![Codecov][github-badge]][07]\n\n\u003c!-- markdownlint-disable MD033 MD041 --\u003e\n\u003ccenter\u003e\n\u003c!-- markdownlint-enable MD033 MD041 --\u003e\n\n• [Website][01] • [Documentation][09] • [Report Bug][04] • [Request Feature][04] • [Contributing Guidelines][05]\n\n\u003c!-- markdownlint-disable MD033 MD041 --\u003e\n\u003c/center\u003e\n\u003c!-- markdownlint-enable MD033 MD041 --\u003e\n\n## Overview\n\nThe **`DateTime` (DTT)** library is a comprehensive, flexible toolkit for managing dates and times in Rust. It includes functions, macros, and data structures that enable you to create, parse, validate, and format date-time objects with minimal effort.\n\nYou can construct `DateTime` objects in UTC or in a fixed offset timezone, ensuring accurate date and time information for varied use cases. The library also offers validation methods, which help maintain precision and correctness in time-critical operations.\n\n## Features\n\nThe `DateTime` (DTT) library provides:\n\n- **Core Fields**  \n  - `datetime`: Internal `PrimitiveDateTime` (UTC by default)\n  - `offset`: A `UtcOffset` representing the timezone offset from UTC\n\n- **Core Methods**  \n  - `new()`: Create a `DateTime` with the current UTC time  \n  - `new_with_tz(tz: \u0026str)`: Construct a `DateTime` in a specified timezone  \n  - `new_with_custom_offset(hours: i8, minutes: i8)`: Create a `DateTime` with a custom offset  \n  - `from_components(...)`: Build a `DateTime` from year, month, day, hour, minute, second, and offset  \n  - `update(\u0026self)`: Refresh the `DateTime` to the current instant (preserving offset)  \n  - `now()`: Return the current `DateTime` (an alias for `new()`)  \n  - `from_str(...)`: Parse a `DateTime` from a string (implements `FromStr`)  \n  - `default()`: Provide the current UTC time by default\n\n- **Parsing and Formatting**  \n  - `parse(...)`: Parse a date-time string into a `DateTime`  \n  - `parse_custom_format(...)`: Use a custom format pattern for parsing  \n  - `format(...)`: Format a `DateTime` with a user-defined pattern  \n  - `format_rfc3339(\u0026self)`: Output RFC 3339 text  \n  - `format_iso8601(\u0026self)`: Output ISO 8601 text\n\n- **Date-Time Manipulation**  \n  - `convert_to_tz(...)`: Switch to a different timezone  \n  - `unix_timestamp(\u0026self)`: Retrieve the Unix timestamp  \n  - `add_days(...)`, `add_months(...)`, `add_years(...)`: Advance the date by days, months, or years  \n  - `sub_months(...)`, `sub_years(...)`: Move the date backwards by months or years  \n  - `next_day()`, `previous_day()`: Obtain the following or preceding day  \n  - `start_of_week()`, `end_of_week()`: Jump to the beginning or end of the week  \n  - `start_of_month()`, `end_of_month()`: Jump to the beginning or end of the month  \n  - `start_of_year()`, `end_of_year()`: Jump to the beginning or end of the year  \n  - `is_within_range(\u0026self, start: \u0026Self, end: \u0026Self)`: Check if a date-time is in a specific range  \n  - `duration_since(\u0026self, other: \u0026Self)`: Calculate duration between two `DateTime`s\n\n- **Getters**  \n  - `year(...)`, `month(...)`, `day(...)`, `hour(...)`, `minute(...)`, `second(...)`, `microsecond(...)`\n  - `weekday(...)`, `ordinal(...)`, `iso_week(...)`, `offset(...)`\n\n- **Setters**  \n  - `set_date(...)`: Update the year, month, and day  \n  - `set_time(...)`: Update the hour, minute, and second  \n\n- **Validation**  \n  - `is_valid_day(...)`, `is_valid_hour(...)`, `is_valid_minute(...)`, `is_valid_second(...)`\n  - `is_valid_month(...)`, `is_valid_year(...)`, `is_valid_microsecond(...)`\n  - `is_valid_ordinal(...)`, `is_valid_iso_week(...)`, `is_valid_time(...)`\n  - `is_valid_iso_8601(date: \u0026str)`: Check if an input is valid ISO 8601\n\n- **Utility Functions**  \n  - `format_time_in_timezone(...)`: Format a date-time for a specified timezone\n\n- **Arithmetic Operations**  \n  - `Add\u003cDuration\u003e` and `Sub\u003cDuration\u003e` traits for adding or subtracting durations\n\n- **Comparison Operations**  \n  - `PartialOrd` and `Ord` for ordering comparisons\n\n- **Hashing**  \n  - `Hash` implementation for use with hash-based collections\n\n- **Macros**  \n  - Examples include `dtt_now!()`, `dtt_parse!()`, `dtt_add_days!()`, and many more, simplifying routine tasks like date parsing or arithmetic\n\n- **Helper Functions**  \n  - `days_in_month(year, month)`: Returns the number of days in a specific month and year  \n  - `is_leap_year(year)`: Checks if a year is a leap year\n\n- **Error Handling**  \n  - `DateTimeError`: Comprehensive error handling for invalid dates, times, or offsets\n\n- **Timezone Support**  \n  - Create or convert `DateTime` objects across multiple named timezones or custom offsets\n\n- **Serialisation and Deserialisation**  \n  - `serde`-enabled for easy reading and writing of `DateTime` objects\n\n## Installation\n\nAdd this to your `Cargo.toml`:\n\n```toml\n[dependencies]\ndtt = \"0.0.9\"\n```\n\nThen in your `main.rs` or lib crate:\n\n```rust\nextern crate dtt;\nuse dtt::*;\n```\n\n## Usage\n\nBelow are some quick examples showing how to use the core features of the `DateTime (DTT)` library.\n\n### Basic Usage\n\n```rust\nuse dtt::datetime::DateTime;\nuse dtt::dtt_print;\n\n// Create a new DateTime in UTC\nlet now = DateTime::new();\ndtt_print!(now);\n\n// Create a DateTime in a specified timezone\nlet ny_time = DateTime::new_with_tz(\"EST\").expect(\"Valid timezone\");\nprintln!(\"Current time in New York: {}\", ny_time);\n\n// Parse a date-time string\nlet date = DateTime::parse(\"2023-05-20T15:30:00Z\").expect(\"Valid date and time\");\nprintln!(\"Parsed date: {}\", date);\n\n// Add days to a date-time\nlet future_date = date.add_days(7).expect(\"Should be valid\");\nprintln!(\"Date after 7 days: {}\", future_date);\n```\n\n### Macro Usage\n\nThe library includes macros that streamline common operations:\n\n```rust\nuse dtt::{dtt_now, dtt_parse, dtt_add_days};\n\nlet now = dtt_now!();\nlet parsed_date = dtt_parse!(\"2023-05-20T15:30:00Z\").expect(\"Valid date\");\nlet future_date = dtt_add_days!(parsed_date, 7).expect(\"Should be valid\");\n\n```\n\n### Error Handling\n\nThe `DateTimeError` enum is used to handle invalid or out-of-range dates and times:\n\n```rust\nuse dtt::datetime::DateTime;\nuse dtt::error::DateTimeError;\n\nfn example_with_error_handling() -\u003e Result\u003c(), DateTimeError\u003e {\n    let date = DateTime::parse(\"2023-05-20T15:30:00Z\")?;\n    println!(\"Parsed date: {}\", date);\n\n    // Attempt to parse an invalid date string\n    let result = DateTime::parse(\"2023-13-20T15:30:00Z\");\n    match result {\n        Ok(_) =\u003e println!(\"Unexpected success.\"),\n        Err(e) =\u003e println!(\"Failed to parse date-time: {}\", e),\n    }\n\n    Ok(())\n}\n```\n\n## Documentation\n\nComprehensive API documentation is available at:\n\n- [Website][01]  \n- [Docs.rs][09]  \n- [https://doc.dttlib.com/][17]\n\n## Rust Version Compatibility\n\nRequires **rustc 1.56.0** or above.  \n\n## Contributing\n\nAll contributions are appreciated! Please follow our [contributing instructions][05] for details on reporting issues, requesting features, or submitting pull requests. Contributions are subject to [Rust's Code of Conduct][12].\n\nBy submitting any contribution, you agree to license your contribution under the same dual licence chosen by this project.\n\n## License\n\nLicensed under either of these:\n\n- [Apache License, Version 2.0][02]\n- [MIT license][03]\n\nYou may select either licence as needed.\n\n## Credits and Acknowledgements\n\nMany thanks to all the contributors of the [DateTime (DTT) Library][06]. We also extend our gratitude to the [Rust Reddit][13] community for their helpful suggestions and feedback.\n\n[01]: https://dttlib.com \"DateTime (DTT) Library Website\"\n[02]: https://opensource.org/license/apache-2-0/ \"Apache License, Version 2.0\"\n[03]: https://opensource.org/licenses/MIT \"MIT license\"\n[04]: https://github.com/sebastienrousseau/dtt/issues \"Issues\"\n[05]: https://github.com/sebastienrousseau/dtt/blob/main/CONTRIBUTING.md \"Contributing Instructions\"\n[06]: https://github.com/sebastienrousseau/dtt/graphs/contributors \"Contributors\"\n[07]: https://github.com/sebastienrousseau/dtt \"DateTime (DTT) Library\"\n[08]: https://crates.io/crates/dtt \"Crates.io\"\n[09]: https://docs.rs/dtt \"Docs.rs\"\n[10]: https://lib.rs/crates/dtt \"Lib.rs\"\n[12]: https://www.rust-lang.org/policies/code-of-conduct \"Rust's Code of Conduct\"\n[13]: https://reddit.com/r/rust \"Rust Reddit\"\n[14]: https://www.rust-lang.org \"The Rust Programming Language\"\n[15]: https://codecov.io/gh/sebastienrousseau/dtt \"Codecov\"\n[16]: https://github.com/sebastienrousseau/dtt/actions?query=branch%3Amain \"Build Status\"\n[17]: https://doc.dttlib.com/ \"DateTime (DTT) Library Documentation\"\n\n[build-badge]: https://img.shields.io/github/actions/workflow/status/sebastienrousseau/dtt/release.yml?branch=main\u0026style=for-the-badge\u0026logo=github \"Build Status\"\n[github-badge]: https://img.shields.io/badge/github-sebastienrousseau/main-8da0cb?style=for-the-badge\u0026labelColor=555555\u0026logo=github \"GitHub\"\n[codecov-badge]: https://img.shields.io/codecov/c/github/sebastienrousseau/dtt?style=for-the-badge\u0026token=X3ZP0K1SGI 'Codecov'\n[crates-badge]: https://img.shields.io/crates/v/dtt.svg?style=for-the-badge 'Crates.io badge'\n[docs-badge]: https://img.shields.io/docsrs/dtt.svg?style=for-the-badge 'Docs.rs badge'\n[libs-badge]: https://img.shields.io/badge/lib.rs-v0.0.9-orange.svg?style=for-the-badge 'Lib.rs badge'\n[made-with-rust]: https://img.shields.io/badge/rust-f04041?style=for-the-badge\u0026labelColor=c0282d\u0026logo=rust 'Made With Rust badge'\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsebastienrousseau%2Fdtt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsebastienrousseau%2Fdtt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsebastienrousseau%2Fdtt/lists"}