6 releases (breaking)

0.11.0 Oct 19, 2023
0.5.1 Dec 4, 2023
0.4.0 Oct 20, 2023
0.3.0 Oct 20, 2023
0.1.0 Oct 19, 2023

#139 in Date and time

Download history 1884/week @ 2024-09-16 1325/week @ 2024-09-23 1597/week @ 2024-09-30 2450/week @ 2024-10-07 1892/week @ 2024-10-14 1644/week @ 2024-10-21 2215/week @ 2024-10-28 1720/week @ 2024-11-04 431/week @ 2024-11-11 616/week @ 2024-11-18 423/week @ 2024-11-25 393/week @ 2024-12-02 106294/week @ 2024-12-09 112118/week @ 2024-12-16 21713/week @ 2024-12-23 60477/week @ 2024-12-30

300,621 downloads per month
Used in 3 crates (via readable)

MIT license

135KB
1.5K SLoC

nichi

CI crates.io docs.rs

Date library.

PartialEq

use nichi::*;

// PartialEq.
let date1 = Date::new(2000, 12, 25);
let date2 = Date::new_typed(
	Year(2000),
	Month::December,
	Day::TwentyFifth,
);

assert_eq!(date1, date2);

Weekday calculation

use nichi::*;

// Christmas in 2000 was on a Monday.
assert_eq!(Date::new(2000, 12, 25).weekday(), Weekday::Monday);

Unix calculation

# use nichi::*;
let date = Date::new(2023, 10, 20);
assert_eq!(date.as_unix(), 1697760000);
assert_eq!(date, Date::from_unix(date.as_unix()));

String parsing

use nichi::*;

assert_eq!(Day::from_str("1st").unwrap(),   Day::First);
assert_eq!(Day::from_str("first").unwrap(), Day::First);
assert_eq!(Day::from_str("FIRST").unwrap(), Day::First);
assert_eq!(Day::from_str("10TH").unwrap(),  Day::Tenth);
assert_eq!(Day::from_str("tenth").unwrap(), Day::Tenth);
assert_eq!(Day::from_str("Tenth").unwrap(), Day::Tenth);

assert_eq!(Weekday::from_str("Tuesday").unwrap(),   Weekday::Tuesday);
assert_eq!(Weekday::from_str("wed").unwrap(),       Weekday::Wednesday);
assert_eq!(Weekday::from_str("WEDNESDAY").unwrap(), Weekday::Wednesday);
assert_eq!(Weekday::from_str("Wednesday").unwrap(), Weekday::Wednesday);
assert_eq!(Weekday::from_str("THURS").unwrap(),     Weekday::Thursday);
assert_eq!(Weekday::from_str("thurs").unwrap(),     Weekday::Thursday);
assert_eq!(Weekday::from_str("THUR").unwrap(),      Weekday::Thursday);
assert_eq!(Weekday::from_str("thursday").unwrap(),  Weekday::Thursday);

assert_eq!(Month::from_str("January").unwrap(),   Month::January);
assert_eq!(Month::from_str("February").unwrap(),  Month::February);
assert_eq!(Month::from_str("FEBRUARY").unwrap(),  Month::February);
assert_eq!(Month::from_str("JUN").unwrap(),       Month::June);
assert_eq!(Month::from_str("July").unwrap(),      Month::July);
assert_eq!(Month::from_str("Jul").unwrap(),       Month::July);
assert_eq!(Month::from_str("NOVEMBER").unwrap(),  Month::November);
assert_eq!(Month::from_str("nov").unwrap(),       Month::November);
assert_eq!(Month::from_str("DEC").unwrap(),       Month::December);

Dependencies

~2.9–4.5MB
~83K SLoC