bongabdo 0.1.0

A Rust library for converting Gregorian dates to Bengali calendar dates
Documentation
# Bongabdo

A Rust library for converting Gregorian dates to Bengali calendar dates across multiple regional standards.

This crate supports:

- the current official Bangladesh civil calendar
- the older Bangladesh revised calendar
- the traditional West Bengal solar calendar

It is designed for cases where Bengali dates differ by region and where "today" should respect the local civil day in Dhaka or Kolkata rather than a UTC day boundary.

## Supported Standards

- `CalendarStandard::Bangladesh`
  Current official Bangladesh civil calendar after the 2019 revision.
- `CalendarStandard::BangladeshLegacy`
  Earlier Bangladesh fixed calendar adopted in 1987.
- `CalendarStandard::WestBengalTraditional`
  Traditional West Bengal solar calendar modeled from sidereal solar ingress.

## Installation

Add this to your `Cargo.toml`:

```toml
[dependencies]
bongabdo = "0.1.0"
```

## Quick Start

```rust
use bongabdo::{Bongabdo, CalendarStandard};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let bd = Bongabdo::from_ymd(2026, 4, 14, CalendarStandard::Bangladesh)?;
    let wb = Bongabdo::from_ymd(2026, 4, 15, CalendarStandard::WestBengalTraditional)?;

    println!("Bangladesh: {}", bd.to_roman_string());
    println!("West Bengal: {}", wb.to_roman_string());

    Ok(())
}
```

## Choosing A Standard

Use `CalendarStandard::Bangladesh` when you want the current official Bangladesh civic calendar.

```rust
use bongabdo::{Bongabdo, CalendarStandard};

let date = Bongabdo::from_ymd(2026, 4, 14, CalendarStandard::Bangladesh)?;
assert_eq!((date.year, date.month, date.day), (1433, 1, 1));
# Ok::<(), bongabdo::BongabdoError>(())
```

Use `CalendarStandard::BangladeshLegacy` when you need compatibility with the older Bangladesh revised calendar.

```rust
use bongabdo::{Bongabdo, CalendarStandard};

let date = Bongabdo::from_ymd(2024, 3, 14, CalendarStandard::BangladeshLegacy)?;
assert_eq!((date.year, date.month, date.day), (1430, 11, 31));
# Ok::<(), bongabdo::BongabdoError>(())
```

Use `CalendarStandard::WestBengalTraditional` when you want the traditional solar calendar used in West Bengal and commonly in India-facing Bengali date contexts.

```rust
use bongabdo::{Bongabdo, CalendarStandard};

let date = Bongabdo::from_ymd(2026, 4, 15, CalendarStandard::WestBengalTraditional)?;
assert_eq!((date.year, date.month, date.day), (1433, 1, 1));
# Ok::<(), bongabdo::BongabdoError>(())
```

## Parsing `BD`, `WB`, `IN`, And Other Aliases

`CalendarStandard` implements `FromStr`, so you can accept string input in your own API and map it into a strongly typed standard.

```rust
use bongabdo::CalendarStandard;

let bd: CalendarStandard = "BD".parse()?;
let legacy: CalendarStandard = "BD_LEGACY".parse()?;
let wb: CalendarStandard = "WB".parse()?;
let india: CalendarStandard = "IN".parse()?;

assert_eq!(bd, CalendarStandard::Bangladesh);
assert_eq!(legacy, CalendarStandard::BangladeshLegacy);
assert_eq!(wb, CalendarStandard::WestBengalTraditional);
assert_eq!(india, CalendarStandard::WestBengalTraditional);
# Ok::<(), Box<dyn std::error::Error>>(())
```

These aliases are supported:

- `BD`, `BANGLADESH`, `BANGLADESH_MODERN`, `BD_MODERN`
- `BD_LEGACY`, `BANGLADESH_LEGACY`, `BANGLADESH_1987`
- `WB`, `WEST_BENGAL`, `WESTBENGAL`, `WEST_BENGAL_TRADITIONAL`
- `IN`, `INDIA`, `INDIAN_BENGALI`, `INDIA_BENGALI`

## Converting Explicit Gregorian Dates

`Bongabdo::from_ymd(...)` is the most deterministic API in the crate.

```rust
use bongabdo::{Bongabdo, CalendarStandard};

let date = Bongabdo::from_ymd(2026, 12, 16, CalendarStandard::Bangladesh)?;
assert_eq!(date.year, 1433);
assert_eq!(date.month, 9);
assert_eq!(date.day, 1);
# Ok::<(), bongabdo::BongabdoError>(())
```

This is the best choice when:

- you already have a Gregorian date
- you want reproducible behavior in tests
- you do not want any dependence on the current machine clock

## Converting The Current Date

`Bongabdo::today(...)` computes the Bengali date for the current local civil day of the chosen standard.

- Bangladesh standards use the current Dhaka civil offset, `UTC+06:00`
- West Bengal uses the current Kolkata civil offset, `UTC+05:30`

This is a fixed-offset model. The crate does not currently use IANA timezone database history for timestamp conversion.

```rust
use bongabdo::{Bongabdo, CalendarStandard};

let today_bd = Bongabdo::today(CalendarStandard::Bangladesh)?;
let today_wb = Bongabdo::today(CalendarStandard::WestBengalTraditional)?;

assert_eq!(today_bd.standard, CalendarStandard::Bangladesh);
assert_eq!(today_wb.standard, CalendarStandard::WestBengalTraditional);
# Ok::<(), bongabdo::BongabdoError>(())
```

## Converting From `SystemTime`

If you already have a fixed timestamp, use `Bongabdo::from_system_time(...)`.

```rust
use bongabdo::{Bongabdo, CalendarStandard};
use std::time::{Duration, UNIX_EPOCH};

let timestamp = UNIX_EPOCH + Duration::from_secs(1_776_105_900);
let wb = Bongabdo::from_system_time(timestamp, CalendarStandard::WestBengalTraditional)?;

assert_eq!(wb, Bongabdo::from_ymd(2026, 4, 14, CalendarStandard::WestBengalTraditional)?);
# Ok::<(), bongabdo::BongabdoError>(())
```

This is useful for:

- backend services with timestamp-based data
- tests around local date rollover
- replaying historical conversions from stored timestamps

This is not a timezone-history-accurate API. It applies the current civil offset for the chosen standard rather than full timezone database rules.

## Accessing Date Fields

Each `Bongabdo` value gives you direct access to the computed components.

```rust
use bongabdo::{Bongabdo, CalendarStandard};

let date = Bongabdo::from_ymd(2026, 4, 14, CalendarStandard::Bangladesh)?;

assert_eq!(date.year, 1433);
assert_eq!(date.month, 1);
assert_eq!(date.day, 1);
assert_eq!(date.weekday, 2);
assert_eq!(date.standard, CalendarStandard::Bangladesh);
# Ok::<(), bongabdo::BongabdoError>(())
```

Weekday numbering is:

- `0 = Sunday`
- `1 = Monday`
- `2 = Tuesday`
- `3 = Wednesday`
- `4 = Thursday`
- `5 = Friday`
- `6 = Saturday`

## Month And Weekday Names

You can access both Bengali-script and Roman-script names.

```rust
use bongabdo::{Bongabdo, CalendarStandard};

let date = Bongabdo::from_ymd(2026, 4, 14, CalendarStandard::Bangladesh)?;

assert_eq!(date.month_name(), "বৈশাখ");
assert_eq!(date.month_name_roman(), "Boishakh");
assert_eq!(date.weekday_name(), "মঙ্গলবার");
assert_eq!(date.weekday_name_roman(), "Mangalbar");
# Ok::<(), bongabdo::BongabdoError>(())
```

## Formatting

### Bengali Output

Use `to_bengali_string()` when you want Bengali digits and Bengali script.

```rust
use bongabdo::{Bongabdo, CalendarStandard};

let date = Bongabdo::from_ymd(2026, 4, 14, CalendarStandard::Bangladesh)?;
assert_eq!(date.to_bengali_string(), "মঙ্গলবার ১ বৈশাখ, ১৪৩৩");
# Ok::<(), bongabdo::BongabdoError>(())
```

### Roman Output

Use `to_roman_string()` when you want Roman-script month and weekday names.

```rust
use bongabdo::{Bongabdo, CalendarStandard};

let date = Bongabdo::from_ymd(2026, 4, 15, CalendarStandard::WestBengalTraditional)?;
assert_eq!(date.to_roman_string(), "Budhbar 1 Boishakh, 1433");
# Ok::<(), bongabdo::BongabdoError>(())
```

### `Display` And Standard `to_string()`

`Bongabdo` implements `Display`, so the standard Rust `ToString::to_string()` output is the Roman-script form.

```rust
use bongabdo::{Bongabdo, CalendarStandard};

let date = Bongabdo::from_ymd(2026, 4, 14, CalendarStandard::Bangladesh)?;

assert_eq!(date.to_string(), "Mangalbar 1 Boishakh, 1433");
assert_eq!(format!("{date}"), "Mangalbar 1 Boishakh, 1433");
# Ok::<(), bongabdo::BongabdoError>(())
```

## Error Handling

Invalid Gregorian input returns `BongabdoError::InvalidGregorianDate`.

```rust
use bongabdo::{Bongabdo, BongabdoError, CalendarStandard};

let result = Bongabdo::from_ymd(2026, 2, 29, CalendarStandard::Bangladesh);

assert_eq!(
    result,
    Err(BongabdoError::InvalidGregorianDate {
        year: 2026,
        month: 2,
        day: 29,
    })
);
```

Parsing an unsupported alias returns an error from `FromStr`.

```rust
use bongabdo::CalendarStandard;

assert!("XX".parse::<CalendarStandard>().is_err());
```

## Backwards Compatibility

`Bongabdo::now()` is still available for compatibility with older versions of the crate, but it is intentionally deprecated because it is ambiguous. It currently maps to `CalendarStandard::BangladeshLegacy`.

For new code, prefer:

- `Bongabdo::today(CalendarStandard::Bangladesh)`
- `Bongabdo::today(CalendarStandard::BangladeshLegacy)`
- `Bongabdo::today(CalendarStandard::WestBengalTraditional)`

## Notes

- `WB` and `IN` are aliases for the same traditional solar standard.
- West Bengal support is implemented as a separate traditional solar calculation, not as a one-day offset from Bangladesh.
- The West Bengal path is modeled from sidereal solar ingress. For exact archival or panjika-grade historical work, verify important boundaries against an authoritative published panjika.
- `from_ymd(...)` is the best API for deterministic conversions.
- `today(...)` and `from_system_time(...)` use fixed current civil offsets, not historical timezone database rules.
- `today(...)` and `from_system_time(...)` are appropriate when present-day "current day" or timestamp-based behavior matters.

## Features

- Convert explicit Gregorian dates with `Bongabdo::from_ymd(...)`
- Convert the current local date with `Bongabdo::today(...)`
- Convert timestamps with `Bongabdo::from_system_time(...)`
- Parse `BD`, `WB`, `IN`, and related aliases into `CalendarStandard`
- Support Bangladesh modern, Bangladesh legacy, and West Bengal traditional standards
- Format dates in Bengali and Roman script
- Access individual date components, month names, and weekday names

## License

This project is licensed under the MIT License. See [LICENSE](LICENSE) for details.