Expand description
§rosetta-date
A powerful, multi-language, multi-format timezone-aware date parser written
in Rust. Inspired by Python’s dateparser, it can parse natural-language
expressions (“2 hours ago”, “昨天”, “January 15th 2025”) as well as all
common machine-readable formats (ISO 8601, RFC 2822/3339, …).
§Features
| Feature | Description |
|---|---|
time-backend | Use the time crate (default) |
chrono-backend | Use the chrono crate |
lang-en | English language data (default) |
lang-zh | Chinese language data |
all-languages | Enable all language packs |
serde | Serde serialisation support |
wasm | WASM / wasm-bindgen bindings |
§Quick Start
use rosetta_date::{parse, RosettaDateTime};
// Standard format
let dt = parse("2023-10-15T12:30:45+08:00").unwrap();
assert_eq!(dt.year(), 2023);
// Natural language (requires a language feature)
let dt = parse("3 hours ago").unwrap();
// Formatting
use rosetta_date::format_datetime;
let s = format_datetime(&dt, "%Y-%m-%d %H:%M:%S", None);Re-exports§
pub use datetime::RosettaDateTime;pub use delta::RosettaDelta;pub use error::Result;pub use error::RosettaError;pub use formatter::format_datetime;pub use formatter::time_ago;pub use parser::ParseOptions;pub use parser::parse;pub use parser::parse_with_options;pub use timezone::TzOffset;
Modules§
- dateparser
- Extended format parser inspired by the
dateparsercrate (https://github.com/waltzofpearls/dateparser). - datetime
- Unified date-time representation that abstracts over
timeandchronobackends. - delta
- Time delta calculation between two
RosettaDateTimevalues. - error
- formatter
- Formatting module: date-time output and relative-time descriptions.
- i18n
- Internationalization module: language data structures and registry.
- nlp
- Natural language date parsing: tokenizer, relative & absolute time parsing.
- parser
- Main parsing orchestrator: combines format-based, heuristic, and NLP parsing.
- timezone
- Timezone handling: abbreviation mapping, offset parsing, and conversion.
- wasm
- WASM bindings – exposes core functionality to JavaScript via
wasm-bindgen.