Rust
nepdate converts between BS and AD, formats and parses Nepali dates, does date arithmetic and
fiscal years. nepdate-patro adds tithi, public holidays and events. The core is no_std with no
dependencies by default, allocates nothing, and contains no unsafe code.
Install
Section titled “Install”[dependencies]nepdate = "=0.1.0-beta.1"nepdate-patro = "=0.1.0-beta.1" # only if you need tithi, holidays or eventsCargo never picks a pre-release for a plain "0.1" requirement, so the beta is pinned exactly.
The MSRV is Rust 1.85. The std feature is on by default; serde, chrono and jiff are
optional features.
Convert and format
Section titled “Convert and format”use nepdate::{Lang, NepaliDate};
fn main() -> Result<(), nepdate::Error> { let date = NepaliDate::new(2081, 4, 15)?; let ad = date.to_gregorian(); assert_eq!((ad.year(), ad.month(), ad.day()), (2024, 7, 30)); assert_eq!(date.weekday().name(Lang::En), "Tuesday"); println!("{}", date.long(nepdate::LongDate::default(), Lang::En)); Ok(())}It prints Shrawan 15, 2081. Formatting in Nepali takes Lang::Ne, which gives Devanagari names
and digits (साउन १५, २०८१).
Tithi, holidays and events
Section titled “Tithi, holidays and events”use nepdate::{Lang, NepaliDate};
fn main() -> Result<(), nepdate::Error> { let date = NepaliDate::new(2081, 1, 1)?; let info = nepdate_patro::info(date); assert_eq!(info.tithi().map(|t| t.name(Lang::En)), Some("Panchami")); assert!(info.is_public_holiday()); Ok(())}nepdate-patro depends on nepdate, never the other way round, so an app that only converts dates
carries no patro data. The data covers BS 2077-01-01 to 2084-08-20.
Reference
Section titled “Reference”| Topic | Where |
|---|---|
| Every public item | docs.rs/nepdate, docs.rs/nepdate-patro |
| The API in one page | docs/API.md |
| Speed against C# NepDate and other crates | docs/benchmarks.md |
| What changed | nepdate, nepdate-patro |
| Source | sanamhub/nepdate-rust |
The same repository holds MitiBar, the desktop calendar built on these crates.