NPDateTime
High-performance Nepali (Bikram Sambat) datetime library for Rust and beyond.
NPDateTime is a modern, fast, and accurate library for working with the Bikram Sambat (BS) calendar. It uniquely combines the speed of lookup tables with the precision of astronomical calculations.
This version achieves 100% feature parity with the original Python npdatetime.old library, while adding an advanced high-precision astronomical engine.
๐ Key Design Decisions
- Hybrid Engine: Use
lookup-tablesfor historical accuracy (1975-2100 BS) orastronomicalfor high-precision calculations based on VSOP87 and ELP-2000 theories. - Zero Overhead: Minimal dependencies and
no_stdcompatibility for embedded systems. - Feature Flags: Take only what you need. Small binary size by default.
- Reliability: Verified against official government calendars and astronomical ephemeris.
๐ Quick Start
Add to your Cargo.toml:
[]
= "0.1.0"
Basic Usage
use *;
Astronomical Calculations
Enable the astronomical feature to access high-precision tools:
๐ Feature Flags
| Feature | Description | Default |
|---|---|---|
lookup-tables |
Embedded CSV data (1975-2100 BS) | Yes |
astronomical |
High-precision solar/lunar models | No |
std |
Standard library features (Chrono) | No |
wasm |
JS/WASM interop support | No |
python |
PyO3 bindings | No |
๐ Performance
NPDateTime achieves exceptional performance through compile-time CSV embedding:
| Operation | Time | Notes |
|---|---|---|
days_in_month |
9-12 ns | Lookup table access |
| Date creation | 12 ns | Validates and constructs |
| BS โ AD conversion | 6-8 ยตs | Full date conversion |
| Format operations | 98-640 ns | strftime-style formatting |
Benchmarks on Rust 1.92, release mode
๐ Multi-Language Support
NPDateTime provides official bindings for multiple languages:
Python (PyO3)
=
, , =
# 2020-09-04
JavaScript/WASM
import init from '@4mritgiri/npdatetime';
await ;
const date = ;
const = date.;
console.log; // 2020-9-4
See bindings/ for detailed setup and API documentation.
๐ Documentation
- CHANGELOG: Release notes and version history.
- CONTRIBUTING: How to contribute.
- SECURITY: Security policy and vulnerability reporting.
- Roadmap: Future plans and progress.
- Development Guide: Architecture and coding standards.
- Astronomy Theory: The math behind calculations.
- Project Structure: Codebase layout.
๐ Project Structure
src/core/: Shared types (NepaliDate, error handling, formatting).src/lookup/: Fast table-based calendar logic (1975-2100 BS).src/astronomical/: High-precision solar (VSOP87) and lunar (ELP-2000) calculations.bindings/python/: PyO3 bindings for Python.bindings/javascript/: wasm-bindgen bindings for JavaScript/WASM.examples/: Usage examples and demonstrations.benches/: Performance benchmarks.
๐งช Testing
# Run all tests
# Run with all features
# Run benchmarks
Test Coverage: 67 tests, 100% passing
๐ License
This project is licensed under the MIT License.