| Crates.io | rs-klc |
| lib.rs | rs-klc |
| version | 0.2.0 |
| created_at | 2025-03-28 18:45:33.536863+00 |
| updated_at | 2025-12-19 20:51:21.05168+00 |
| description | A library for converting between Korean Solar and Lunar dates, calculating Gapja (간지), and day of the week. |
| homepage | |
| repository | https://github.com/chunghha/rs-klc.git |
| max_upload_size | |
| id | 1609980 |
| size | 80,071 |
A Rust library for converting between Korean Lunar dates and Gregorian Solar dates. It also calculates the traditional Korean and Chinese Gapja (sexagenary cycle) names for the year, month, and day.
This library is based on the data and algorithms originally implemented in JavaScript by usingsky and adapted for Rust.
갑자) and Chinese (干支) sexagenary cycle names for the year, month, and day of a given date.YYYY-MM-DD) for both Lunar and Solar dates.See the Examples section for code demonstrating these features.
(Note: Dates are based on the Korean time zone (KST) implicitly via the underlying data/algorithm design.)
Add this to your Cargo.toml:
[dependencies]
rs-klc = "0.1" # Check crates.io for the latest version
Then use the library like this:
use rs_klc::{LunarSolarConverter, DayOfWeek};
let mut converter = LunarSolarConverter::new();
// Set a Solar date and get Lunar info
if converter.set_solar_date(2022, 7, 10) {
println!("Solar: {}", converter.get_solar_iso_format()); // Output: 2022-07-10
println!("Lunar: {}", converter.get_lunar_iso_format()); // Output: 2022-06-12
println!("Gapja: {}", converter.get_gapja_string()); // Output: 임인년 정미월 갑자일
// Get day of week for the solar date
if let Some(dow) = LunarSolarConverter::get_day_of_week(2022, 7, 10) {
println!("Day of Week: {:?}", dow); // Output: Sunday
}
} else {
println!("Invalid solar date");
}
println!("--- Check other features ---");
// Check solar leap year
let solar_year = 2024;
let is_solar_leap = LunarSolarConverter::is_solar_leap_year(solar_year);
println!("Solar Year {} Leap: {}", solar_year, is_solar_leap); // Output: true
// Check lunar intercalary month
let lunar_year = 2023;
if let Some(intercalary_month) = LunarSolarConverter::get_lunar_intercalary_month(lunar_year) {
println!("Lunar Year {} has intercalary month: {}", lunar_year, intercalary_month); // Output: 2 (윤2월)
} else {
println!("Lunar Year {} has no intercalary month.", lunar_year);
}
// Calculate JDN
if let Some(jdn) = LunarSolarConverter::get_julian_day_number(2022, 7, 10) {
println!("JDN for 2022-07-10: {}", jdn); // Output: 2459771
}
The examples/ directory contains several examples demonstrating different features of the library. You can run them using cargo or task:
01_basic_conversion: Basic Solar <-> Lunar conversion02_lunar_to_solar: Lunar to Solar conversion03_intercalary_month: Intercalary month handling04_gapja_sexagenary: Korean/Chinese Gapja calculation05_julian_day_number: Julian Day Number calculation06_leap_year: Solar leap year check07_day_of_week: Day of week calculation08_comprehensive: Comprehensive feature demoRun all examples:
task run-examples
This project uses cargo for building and testing, and task (Taskfile) for convenience.
cargo build
# or
task build
cargo test
# or
task test
cargo run --example 01_basic_conversion
# or
task example1
cargo clippy
# or
task lint
This project is licensed under the MIT License. See the LICENSE file for details.