Skip to main content

Crate rosetta_date

Crate rosetta_date 

Source
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

FeatureDescription
time-backendUse the time crate (default)
chrono-backendUse the chrono crate
lang-enEnglish language data (default)
lang-zhChinese language data
all-languagesEnable all language packs
serdeSerde serialisation support
wasmWASM / 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 dateparser crate (https://github.com/waltzofpearls/dateparser).
datetime
Unified date-time representation that abstracts over time and chrono backends.
delta
Time delta calculation between two RosettaDateTime values.
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.