calendar-core 0.1.0

Core traits and utilities for nusantara-calendar workspace
Documentation

Nusantara Calendar Core

This crate provides the foundational types, traits, and utilities for the nusantara-calendar workspace, which implements traditional Indonesian calendar systems with modern Rust ergonomics.

Julian Day Number (JDN) Pivot

This crate uses the Julian Day Number (JDN) system as the central pivot for all calendar conversions. JDN provides a continuous count of days since noon Universal Time on January 1, 4713 BCE (Julian calendar), making it ideal for converting between different calendar systems.

The JDN system allows us to:

  • Convert any date to/from Gregorian calendar
  • Implement bidirectional conversions between calendar systems
  • Perform date arithmetic with consistent results
  • Handle historical dates across different calendar reforms

Algorithm Source

The Gregorian to JDN conversion algorithm implemented in this crate follows the standard formula from:

Meeus, Jean. Astronomical Algorithms, 2nd Edition. Willmann-Blohm, 1998. Chapter 7: "Julian Day".

This reference implementation provides accurate conversions for the full range of historical dates supported by the JDN system (approximately 262,000 BCE to 262,000 CE).

Core Components

Types

  • [JDN] - Julian Day Number type alias (i64)
  • [CycleYear] - Type for cycle-year fields (u32)
  • [SubYearPosition] - Type for sub-year positions (u8)

Traits

  • [CalendarDate] - Core interface for calendar implementations
  • [CalendarMetadata] - Access to calendar metadata and cultural context
  • [HasAuspiciousness] - Auspiciousness calculations for Indonesian calendars

Error Handling

  • [CalendarError] - Comprehensive error types with detailed context
  • [stub!] macro for marking unimplemented features

Cultural Features

  • [Activity] - Indonesian cultural activities for auspiciousness evaluation
  • [AuspiciousnessLevel] - Favorability levels for activities and dates

Platform Support

This crate supports multiple compilation targets:

  • std: Standard library with full functionality
  • no_std: Embedded systems with alloc support
  • WASM: WebAssembly targets for browser usage

Example Usage

use calendar_core::{gregorian_to_jdn, jdn_to_gregorian, CalendarDate};

// Convert Gregorian to JDN
let jdn = gregorian_to_jdn(2024, 3, 15);

// Convert back to Gregorian
let (year, month, day) = jdn_to_gregorian(jdn);

// Use with CalendarDate trait implementations
// let calendar_date = MyCalendar::from_gregorian(2024, 3, 15)?;

Indonesian Calendar Context

This crate is specifically designed to support the rich diversity of Indonesian calendar systems, including:

  • Javanese calendar (Saka and Islamic integration)
  • Balinese calendar (Pawukon cycle)
  • Hijri/Islamic calendar
  • Chinese calendar integration
  • Various regional ethnic calendars

Each calendar system can implement the core traits while maintaining cultural authenticity and computational accuracy.