diff --git a/Cargo.toml b/Cargo.toml index c59118d..74e7054 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,7 @@ resolver = "2" [workspace.package] edition = "2021" -rust-version = "1.67" +rust-version = "1.81" authors = ["John Thorvald Wodder II "] repository = "https://github.com/jwodder/julian-rs" license = "MIT" diff --git a/README.md b/README.md index ec0030e..904acc5 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ [![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active) [![CI Status](https://github.com/jwodder/julian-rs/actions/workflows/test.yml/badge.svg)](https://github.com/jwodder/julian-rs/actions/workflows/test.yml) [![codecov.io](https://codecov.io/gh/jwodder/julian-rs/branch/master/graph/badge.svg)](https://codecov.io/gh/jwodder/julian-rs) -[![Minimum Supported Rust Version](https://img.shields.io/badge/MSRV-1.67-orange)](https://www.rust-lang.org) +[![Minimum Supported Rust Version](https://img.shields.io/badge/MSRV-1.81-orange)](https://www.rust-lang.org) [![MIT License](https://img.shields.io/github/license/jwodder/julian-rs.svg)](https://opensource.org/licenses/MIT) This is a Rust [workspace][] containing various packages for converting between diff --git a/crates/julian-cli/CHANGELOG.md b/crates/julian-cli/CHANGELOG.md index a341f05..bfbc218 100644 --- a/crates/julian-cli/CHANGELOG.md +++ b/crates/julian-cli/CHANGELOG.md @@ -1,3 +1,7 @@ +v0.7.0 (in development) +----------------------- +- Increased MSRV to 1.81 + v0.6.0 (2024-12-18) ------------------- - Split off CLI from `julian` crate diff --git a/crates/julian-cli/README.md b/crates/julian-cli/README.md index c81495c..04d83d2 100644 --- a/crates/julian-cli/README.md +++ b/crates/julian-cli/README.md @@ -1,7 +1,7 @@ [![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active) [![CI Status](https://github.com/jwodder/julian-rs/actions/workflows/test.yml/badge.svg)](https://github.com/jwodder/julian-rs/actions/workflows/test.yml) [![codecov.io](https://codecov.io/gh/jwodder/julian-rs/branch/master/graph/badge.svg)](https://codecov.io/gh/jwodder/julian-rs) -[![Minimum Supported Rust Version](https://img.shields.io/badge/MSRV-1.67-orange)](https://www.rust-lang.org) +[![Minimum Supported Rust Version](https://img.shields.io/badge/MSRV-1.81-orange)](https://www.rust-lang.org) [![MIT License](https://img.shields.io/github/license/jwodder/julian-rs.svg)](https://opensource.org/licenses/MIT) [GitHub](https://github.com/jwodder/julian-rs) | [crates.io](https://crates.io/crates/julian-cli) | [Issues](https://github.com/jwodder/julian-rs/issues) | [Changelog](https://github.com/jwodder/julian-rs/blob/master/crates/julian-cli/CHANGELOG.md) diff --git a/crates/julian/CHANGELOG.md b/crates/julian/CHANGELOG.md index 4066061..5024e9f 100644 --- a/crates/julian/CHANGELOG.md +++ b/crates/julian/CHANGELOG.md @@ -1,3 +1,8 @@ +v0.7.0 (in development) +----------------------- +- Increased MSRV to 1.81 +- Added `std` feature for toggling `no_std` support + v0.6.0 (2024-12-18) ------------------- - Increased MSRV to 1.67 diff --git a/crates/julian/Cargo.toml b/crates/julian/Cargo.toml index 22f91c1..2643520 100644 --- a/crates/julian/Cargo.toml +++ b/crates/julian/Cargo.toml @@ -12,7 +12,7 @@ categories = ["date-and-time"] [dependencies] chrono = { version = "0.4.38", optional = true, default-features = false } -thiserror = "2.0.0" +thiserror = { version = "2.0.0", default-features = false } [dev-dependencies] assert_matches = "1.5.0" @@ -20,7 +20,9 @@ rstest = { version = "0.23.0", default-features = false } rstest_reuse = "0.7.0" [features] +default = ["std"] chrono = ["dep:chrono"] +std = [] [lints] workspace = true diff --git a/crates/julian/README.md b/crates/julian/README.md index 0a50212..56e410e 100644 --- a/crates/julian/README.md +++ b/crates/julian/README.md @@ -1,7 +1,7 @@ [![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active) [![CI Status](https://github.com/jwodder/julian-rs/actions/workflows/test.yml/badge.svg)](https://github.com/jwodder/julian-rs/actions/workflows/test.yml) [![codecov.io](https://codecov.io/gh/jwodder/julian-rs/branch/master/graph/badge.svg)](https://codecov.io/gh/jwodder/julian-rs) -[![Minimum Supported Rust Version](https://img.shields.io/badge/MSRV-1.67-orange)](https://www.rust-lang.org) +[![Minimum Supported Rust Version](https://img.shields.io/badge/MSRV-1.81-orange)](https://www.rust-lang.org) [![MIT License](https://img.shields.io/github/license/jwodder/julian-rs.svg)](https://opensource.org/licenses/MIT) [GitHub](https://github.com/jwodder/julian-rs) | [crates.io](https://crates.io/crates/julian) | [Documentation](https://docs.rs/julian) | [Issues](https://github.com/jwodder/julian-rs/issues) | [Changelog](https://github.com/jwodder/julian-rs/blob/master/crates/julian/CHANGELOG.md) diff --git a/crates/julian/src/errors.rs b/crates/julian/src/errors.rs index 21a68ef..c14c0c7 100644 --- a/crates/julian/src/errors.rs +++ b/crates/julian/src/errors.rs @@ -1,6 +1,6 @@ //! Error types use crate::Month; -use std::num::ParseIntError; +use core::num::ParseIntError; use thiserror::Error; #[cfg(feature = "chrono")] diff --git a/crates/julian/src/inner.rs b/crates/julian/src/inner.rs index 9fd8ee9..d2833b5 100644 --- a/crates/julian/src/inner.rs +++ b/crates/julian/src/inner.rs @@ -1,6 +1,6 @@ use super::{errors::ParseDateError, Jdnum, Month, COMMON_YEAR_LENGTH, LEAP_YEAR_LENGTH}; -use std::cmp::Ordering; -use std::hash::{Hash, Hasher}; +use core::cmp::Ordering; +use core::hash::{Hash, Hasher}; // Julian-calendar year in which Julian day number 0 occurs const JDN0_YEAR: i32 = -4712; @@ -192,7 +192,7 @@ impl<'a> DateParser<'a> { pub(crate) fn parse_int(&mut self) -> Result { let mut first = true; match scan(self.data, |c| { - (std::mem::replace(&mut first, false) && (c == '-' || c == '+')) || c.is_ascii_digit() + (core::mem::replace(&mut first, false) && (c == '-' || c == '+')) || c.is_ascii_digit() }) { ("", _) => match self.data.chars().next() { Some(got) => Err(ParseDateError::InvalidIntStart { got }), diff --git a/crates/julian/src/iter.rs b/crates/julian/src/iter.rs index 9c131fb..b7a968e 100644 --- a/crates/julian/src/iter.rs +++ b/crates/julian/src/iter.rs @@ -1,7 +1,7 @@ //! Iterator types use crate::{Date, Month, MonthShape}; -use std::iter::FusedIterator; -use std::ops::RangeInclusive; +use core::iter::FusedIterator; +use core::ops::RangeInclusive; /// An iterator over the days of a month. /// diff --git a/crates/julian/src/lib.rs b/crates/julian/src/lib.rs index 45c3a8c..304af15 100644 --- a/crates/julian/src/lib.rs +++ b/crates/julian/src/lib.rs @@ -1,3 +1,4 @@ +#![cfg_attr(not(test), no_std)] #![cfg_attr(docsrs, feature(doc_cfg))] //! `julian` is a Rust library for converting between [Julian day numbers][jdn] //! and dates in the [Gregorian calendar][] (either proleptic or with the @@ -12,7 +13,11 @@ //! Features //! ======== //! -//! The `julian` crate has the following optional feature: +//! The `julian` crate has the following optional features: +//! +//! - `std` — This feature is enabled by default; disable it to build in no-std +//! mode. When this feature is disabled, functions that use +//! [`std::time::SystemTime`] are not available. //! //! - `chrono` — Enables converting values of certain `julian` types to the //! corresponding [`chrono`] types and *vice versa*. @@ -172,10 +177,15 @@ pub mod iter; pub mod ncal; use crate::errors::*; use crate::iter::*; -use std::cmp::Ordering; -use std::fmt; -use std::ops::RangeInclusive; -use std::str::FromStr; +use core::cmp::Ordering; +use core::fmt; +use core::ops::RangeInclusive; +use core::str::FromStr; + +#[cfg(feature = "std")] +extern crate std; + +#[cfg(feature = "std")] use std::time::{SystemTime, UNIX_EPOCH}; /// Type used for Julian day numbers in this crate @@ -396,6 +406,8 @@ impl Calendar { /// converting the time. This can only happen if the system time in UTC is /// before -5884323-05-15 (-5884202-03-16 O.S.) or after 5874898-06-03 /// (5874777-10-17 O.S.). + #[cfg(feature = "std")] + #[cfg_attr(docsrs, doc(cfg(feature = "std")))] pub fn now(&self) -> Result<(Date, u32), ArithmeticError> { self.at_system_time(SystemTime::now()) } @@ -409,6 +421,8 @@ impl Calendar { /// converting the time. This can only happen if the system time in UTC is /// before -5884323-05-15 (-5884202-03-16 O.S.) or after 5874898-06-03 /// (5874777-10-17 O.S.). + #[cfg(feature = "std")] + #[cfg_attr(docsrs, doc(cfg(feature = "std")))] pub fn at_system_time(&self, t: SystemTime) -> Result<(Date, u32), ArithmeticError> { let (jdn, secs) = system2jdn(t)?; Ok((self.at_jdn(jdn), secs)) @@ -2134,21 +2148,32 @@ impl FromStr for Month { /// Parses a month from either its English name or just the first three /// letters of the name. Input is treated case-insensitively. fn from_str(s: &str) -> Result { - use Month::*; - match s.to_ascii_lowercase().as_str() { - "january" | "jan" => Ok(January), - "february" | "feb" => Ok(February), - "march" | "mar" => Ok(March), - "april" | "apr" => Ok(April), - "may" => Ok(May), - "june" | "jun" => Ok(June), - "july" | "jul" => Ok(July), - "august" | "aug" => Ok(August), - "september" | "sep" => Ok(September), - "october" | "oct" => Ok(October), - "november" | "nov" => Ok(November), - "december" | "dec" => Ok(December), - _ => Err(ParseMonthError), + if s.eq_ignore_ascii_case("january") || s.eq_ignore_ascii_case("jan") { + Ok(Month::January) + } else if s.eq_ignore_ascii_case("february") || s.eq_ignore_ascii_case("feb") { + Ok(Month::February) + } else if s.eq_ignore_ascii_case("march") || s.eq_ignore_ascii_case("mar") { + Ok(Month::March) + } else if s.eq_ignore_ascii_case("april") || s.eq_ignore_ascii_case("apr") { + Ok(Month::April) + } else if s.eq_ignore_ascii_case("may") { + Ok(Month::May) + } else if s.eq_ignore_ascii_case("june") || s.eq_ignore_ascii_case("jun") { + Ok(Month::June) + } else if s.eq_ignore_ascii_case("july") || s.eq_ignore_ascii_case("jul") { + Ok(Month::July) + } else if s.eq_ignore_ascii_case("august") || s.eq_ignore_ascii_case("aug") { + Ok(Month::August) + } else if s.eq_ignore_ascii_case("september") || s.eq_ignore_ascii_case("sep") { + Ok(Month::September) + } else if s.eq_ignore_ascii_case("october") || s.eq_ignore_ascii_case("oct") { + Ok(Month::October) + } else if s.eq_ignore_ascii_case("november") || s.eq_ignore_ascii_case("nov") { + Ok(Month::November) + } else if s.eq_ignore_ascii_case("december") || s.eq_ignore_ascii_case("dec") { + Ok(Month::December) + } else { + Err(ParseMonthError) } } } @@ -2366,16 +2391,22 @@ impl FromStr for Weekday { /// Parses a weekday from either its English name or just the first three /// letters of the name. Input is treated case-insensitively. fn from_str(s: &str) -> Result { - use Weekday::*; - match s.to_ascii_lowercase().as_str() { - "sunday" | "sun" => Ok(Sunday), - "monday" | "mon" => Ok(Monday), - "tuesday" | "tue" => Ok(Tuesday), - "wednesday" | "wed" => Ok(Wednesday), - "thursday" | "thu" => Ok(Thursday), - "friday" | "fri" => Ok(Friday), - "saturday" | "sat" => Ok(Saturday), - _ => Err(ParseWeekdayError), + if s.eq_ignore_ascii_case("sunday") || s.eq_ignore_ascii_case("sun") { + Ok(Weekday::Sunday) + } else if s.eq_ignore_ascii_case("monday") || s.eq_ignore_ascii_case("mon") { + Ok(Weekday::Monday) + } else if s.eq_ignore_ascii_case("tuesday") || s.eq_ignore_ascii_case("tue") { + Ok(Weekday::Tuesday) + } else if s.eq_ignore_ascii_case("wednesday") || s.eq_ignore_ascii_case("wed") { + Ok(Weekday::Wednesday) + } else if s.eq_ignore_ascii_case("thursday") || s.eq_ignore_ascii_case("thu") { + Ok(Weekday::Thursday) + } else if s.eq_ignore_ascii_case("friday") || s.eq_ignore_ascii_case("fri") { + Ok(Weekday::Friday) + } else if s.eq_ignore_ascii_case("saturday") || s.eq_ignore_ascii_case("sat") { + Ok(Weekday::Saturday) + } else { + Err(ParseWeekdayError) } } } @@ -2446,6 +2477,8 @@ impl From for chrono::Weekday { /// conversion. This can only happen if the system time in UTC is before /// -5884323-05-15 (-5884202-03-16 O.S.) or after 5874898-06-03 (5874777-10-17 /// O.S.). +#[cfg(feature = "std")] +#[cfg_attr(docsrs, doc(cfg(feature = "std")))] pub fn system2jdn(t: SystemTime) -> Result<(Jdnum, u32), ArithmeticError> { let ts = match t.duration_since(UNIX_EPOCH) { Ok(d) => i64::try_from(d.as_secs()),