#julian-day #calendar-date #calendar #gregorian-calendar #julian-calendar

no-std julian

Convert between Julian day numbers and Julian & Gregorian calendars

8 releases (breaking)

0.7.0 Dec 19, 2024
0.6.0 Dec 19, 2024
0.5.0 Dec 22, 2023
0.4.0 Nov 22, 2023
0.1.0 May 2, 2023

#84 in Date and time

Download history 41/week @ 2024-11-29 74/week @ 2024-12-06 219/week @ 2024-12-13 86/week @ 2024-12-20 3/week @ 2024-12-27 46/week @ 2025-01-03 55/week @ 2025-01-10 74/week @ 2025-01-17 85/week @ 2025-01-24 93/week @ 2025-01-31 97/week @ 2025-02-07 70/week @ 2025-02-14 60/week @ 2025-02-21 78/week @ 2025-02-28 30/week @ 2025-03-07 58/week @ 2025-03-14

237 downloads per month
Used in 2 crates

MIT license

1MB
21K SLoC

Project Status: Active – The project has reached a stable, usable state and is being actively developed. CI Status codecov.io Minimum Supported Rust Version MIT License

GitHub | crates.io | Documentation | Issues | Changelog

julian is a Rust library for converting between Julian day numbers and dates in the Gregorian calendar (either proleptic or with the Reformation occurring at a given date) and/or the proleptic Julian calendar. There are also features for querying details about years & months in a "reforming" Gregorian calendar and how they are affected by the calendar reformation date of your choice.

Examples

Before you construct a date, you must first choose a calendar in which to reckon dates. Calendar::GREGORIAN is the proleptic Gregorian calendar, which should be both simple and useful enough for most basic purposes.

To convert a Julian day number to a date in a calendar, use the Calendar::at_jdn() method, like so:

use julian::{Calendar, Month};

let cal = Calendar::GREGORIAN;
let date = cal.at_jdn(2460065);
assert_eq!(date.year(), 2023);
assert_eq!(date.month(), Month::April);
assert_eq!(date.day(), 30);

So JDN 2460065 is April 30, 2023, in the proleptic Gregorian calendar.

To convert a date to a Julian day number, use Calendar::at_ymd() to construct the date, and then call its julian_day_number() method:

use julian::{Calendar, Month};

let cal = Calendar::GREGORIAN;
let date = cal.at_ymd(2023, Month::April, 30).unwrap();
assert_eq!(date.julian_day_number(), 2460065);

See the documentation for more things you can do!

Command

There is also an accompanying binary package julian-cli that provides a CLI command named julian for converting between Julian day numbers and dates in Julian-style calendars. Feel free to install it if you're interested!

Dependencies

~0.2–1.1MB
~23K SLoC