From d40a6fbcad0f3d479e9edde8fccb3ce5b4548769 Mon Sep 17 00:00:00 2001 From: Josh Stoik Date: Wed, 30 Oct 2024 23:15:15 -0700 Subject: [PATCH 1/5] docs --- Cargo.toml | 5 +---- README.md | 22 ---------------------- 2 files changed, 1 insertion(+), 26 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ca5f85b..73b5c1c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "utc2k" version = "0.11.0" -authors = ["Blobfolio, LLC. "] +authors = ["Josh Stoik "] edition = "2021" rust-version = "1.81" description = "A fast and lean UTC date/time library concerned only with happenings in this century (2000-2099)." @@ -26,9 +26,6 @@ default-target = "x86_64-unknown-linux-gnu" [package.metadata.bashman] name = "UTC2K" -bash-dir = "./" -man-dir = "./" -credits-dir = "./" [dev-dependencies] brunch = "0.6.*" diff --git a/README.md b/README.md index 1075a34..da25491 100644 --- a/README.md +++ b/README.md @@ -96,25 +96,3 @@ Add `utc2k` to your `dependencies` in `Cargo.toml`, like: [dependencies] utc2k = "0.11.*" ``` - - - -## License - -Copyright © 2024 [Blobfolio, LLC](https://blobfolio.com) <hello@blobfolio.com> - -This work is free. You can redistribute it and/or modify it under the terms of the Do What The Fuck You Want To Public License, Version 2. - - DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE - Version 2, December 2004 - - Copyright (C) 2004 Sam Hocevar - - Everyone is permitted to copy and distribute verbatim or modified - copies of this license document, and changing it is allowed as long - as the name is changed. - - DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. You just DO WHAT THE FUCK YOU WANT TO. From a0ce934508cfe363362cbedf33c3b2c6b4b388d7 Mon Sep 17 00:00:00 2001 From: Josh Stoik Date: Thu, 21 Nov 2024 23:30:59 -0800 Subject: [PATCH 2/5] lints --- src/serde.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/serde.rs b/src/serde.rs index 591d276..e7b5175 100644 --- a/src/serde.rs +++ b/src/serde.rs @@ -61,7 +61,7 @@ impl<'de> Deserialize<'de> for Utc2k { ); } - impl<'de> de::Visitor<'de> for Visitor { + impl de::Visitor<'_> for Visitor { type Value = Utc2k; fn expecting(&self, f: &mut fmt::Formatter) -> fmt::Result { @@ -139,7 +139,7 @@ impl<'de> Deserialize<'de> for Month { /// # Visitor Instance. struct Visitor; - impl<'de> de::Visitor<'de> for Visitor { + impl de::Visitor<'_> for Visitor { type Value = Month; fn expecting(&self, f: &mut fmt::Formatter) -> fmt::Result { @@ -186,7 +186,7 @@ impl<'de> Deserialize<'de> for Weekday { /// # Visitor Instance. struct Visitor; - impl<'de> de::Visitor<'de> for Visitor { + impl de::Visitor<'_> for Visitor { type Value = Weekday; fn expecting(&self, f: &mut fmt::Formatter) -> fmt::Result { From 181e9411c9e3478f6758fcf39fd2871265c55d7c Mon Sep 17 00:00:00 2001 From: Josh Stoik Date: Mon, 25 Nov 2024 10:15:12 -0800 Subject: [PATCH 3/5] misc: make FmtUtc2k::date, time, and year const --- CHANGELOG.md | 10 ++++++++ src/date/mod.rs | 67 ++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 65 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1ec0800..2d0d9f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,16 @@ +## [0.11.1](https://github.com/Blobfolio/utc2k/releases/tag/v0.11.1) - TBD + +### Changed + +* `FmtUtf2k::date` is now const +* `FmtUtf2k::time` is now const +* `FmtUtf2k::year` is now const + + + ## [0.11.0](https://github.com/Blobfolio/utc2k/releases/tag/v0.11.0) - 2024-10-25 ### New diff --git a/src/date/mod.rs b/src/date/mod.rs index 7c61cff..b650b62 100644 --- a/src/date/mod.rs +++ b/src/date/mod.rs @@ -406,10 +406,27 @@ impl FmtUtc2k { /// assert_eq!(fmt.as_str(), "2099-12-31 23:59:59"); /// assert_eq!(fmt.date(), "2099-12-31"); /// ``` - pub fn date(&self) -> &str { - debug_assert!(self.0[..10].is_ascii(), "Bug: Date is not ASCII."); - // Safety: datetimes are valid ASCII. - unsafe { std::str::from_utf8_unchecked(&self.0[..10]) } + pub const fn date(&self) -> &str { + if let Some(v) = self.0.first_chunk::<10>() { + debug_assert!( + v[0].is_ascii_digit() && + v[1].is_ascii_digit() && + v[2].is_ascii_digit() && + v[3].is_ascii_digit() && + v[4] == b'-' && + v[5].is_ascii_digit() && + v[6].is_ascii_digit() && + v[7] == b'-' && + v[8].is_ascii_digit() && + v[9].is_ascii_digit(), + "Bug: Date is not ASCII.", + ); + + // Safety: datetimes are valid ASCII. + unsafe { std::str::from_utf8_unchecked(v.as_slice()) } + } + // Unreachable. + else { "2000-01-01" } } #[expect(unsafe_code, reason = "Content is ASCII.")] @@ -428,10 +445,21 @@ impl FmtUtc2k { /// assert_eq!(fmt.as_str(), "2099-12-31 23:59:59"); /// assert_eq!(fmt.year(), "2099"); /// ``` - pub fn year(&self) -> &str { - debug_assert!(self.0.iter().take(4).all(u8::is_ascii_digit), "Bug: Year is not numeric."); - // Safety: datetimes are valid ASCII. - unsafe { std::str::from_utf8_unchecked(&self.0[..4]) } + pub const fn year(&self) -> &str { + if let Some(v) = self.0.first_chunk::<4>() { + debug_assert!( + v[0].is_ascii_digit() && + v[1].is_ascii_digit() && + v[2].is_ascii_digit() && + v[3].is_ascii_digit(), + "Bug: Year is not ASCII.", + ); + + // Safety: datetimes are valid ASCII. + unsafe { std::str::from_utf8_unchecked(v.as_slice()) } + } + // Unreachable. + else { "2000" } } #[expect(unsafe_code, reason = "Content is ASCII.")] @@ -450,10 +478,25 @@ impl FmtUtc2k { /// assert_eq!(fmt.as_str(), "2099-12-31 23:59:59"); /// assert_eq!(fmt.time(), "23:59:59"); /// ``` - pub fn time(&self) -> &str { - debug_assert!(self.0[11..].is_ascii(), "Bug: Time is not ASCII."); - // Safety: datetimes are valid ASCII. - unsafe { std::str::from_utf8_unchecked(&self.0[11..]) } + pub const fn time(&self) -> &str { + if let Some(v) = self.0.last_chunk::<8>() { + debug_assert!( + v[0].is_ascii_digit() && + v[1].is_ascii_digit() && + v[2] == b':' && + v[3].is_ascii_digit() && + v[4].is_ascii_digit() && + v[5] == b':' && + v[6].is_ascii_digit() && + v[7].is_ascii_digit(), + "Bug: Time is not ASCII.", + ); + + // Safety: datetimes are valid ASCII. + unsafe { std::str::from_utf8_unchecked(v.as_slice()) } + } + // Unreachable. + else { "00:00:00" } } } From 05a1b3784524667d6b96c4eb9fae8bf37fc1fe44 Mon Sep 17 00:00:00 2001 From: Josh Stoik Date: Thu, 28 Nov 2024 11:06:22 -0800 Subject: [PATCH 4/5] bump: brunch 0.7 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 73b5c1c..c3399e6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,7 +28,7 @@ default-target = "x86_64-unknown-linux-gnu" name = "UTC2K" [dev-dependencies] -brunch = "0.6.*" +brunch = "0.7.*" fastrand = "2" serde = "1.0.*" serde_json = "1.0.*" From e98ab2c4c3bf51ffb99a4674e6f6318b535600f9 Mon Sep 17 00:00:00 2001 From: Josh Stoik Date: Thu, 28 Nov 2024 11:09:13 -0800 Subject: [PATCH 5/5] bump: 0.11.1 --- CHANGELOG.md | 4 +++- CREDITS.md | 21 ++++++++++++++++++--- Cargo.toml | 2 +- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d0d9f3..c11f1d3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,13 +2,15 @@ -## [0.11.1](https://github.com/Blobfolio/utc2k/releases/tag/v0.11.1) - TBD +## [0.11.1](https://github.com/Blobfolio/utc2k/releases/tag/v0.11.1) - 2024-11-28 ### Changed +* Bump `brunch` to `0.7` (dev) * `FmtUtf2k::date` is now const * `FmtUtf2k::time` is now const * `FmtUtf2k::year` is now const +* Miscellaneous code changes and lints diff --git a/CREDITS.md b/CREDITS.md index 873c88e..a00ec2d 100644 --- a/CREDITS.md +++ b/CREDITS.md @@ -1,6 +1,21 @@ # Project Dependencies Package: utc2k - Version: 0.11.0 - Generated: 2024-10-25 18:12:03 UTC + Version: 0.11.1 + Generated: 2024-11-28 19:08:01 UTC -This package has no dependencies. +| Package | Version | Author(s) | License | +| ---- | ---- | ---- | ---- | +| [_proc-macro2_](https://github.com/dtolnay/proc-macro2) ⚒️ | 1.0.92 | [David Tolnay](mailto:dtolnay@gmail.com) and [Alex Crichton](mailto:alex@alexcrichton.com) | MIT OR Apache-2.0 | +| [_quote_](https://github.com/dtolnay/quote) ⚒️ | 1.0.37 | [David Tolnay](mailto:dtolnay@gmail.com) | MIT OR Apache-2.0 | +| [**_serde_**](https://github.com/serde-rs/serde) | 1.0.215 | [Erick Tryzelaar](mailto:erick.tryzelaar@gmail.com) and [David Tolnay](mailto:dtolnay@gmail.com) | MIT OR Apache-2.0 | +| [_serde_derive_](https://github.com/serde-rs/serde) | 1.0.215 | [Erick Tryzelaar](mailto:erick.tryzelaar@gmail.com) and [David Tolnay](mailto:dtolnay@gmail.com) | MIT OR Apache-2.0 | +| [_syn_](https://github.com/dtolnay/syn) ⚒️ | 2.0.89 | [David Tolnay](mailto:dtolnay@gmail.com) | MIT OR Apache-2.0 | +| [**_tz-rs_**](https://github.com/x-hgg-x/tz-rs) | 0.7.0 | x-hgg-x | MIT OR Apache-2.0 | +| [_unicode-ident_](https://github.com/dtolnay/unicode-ident) ⚒️ | 1.0.14 | [David Tolnay](mailto:dtolnay@gmail.com) | (MIT OR Apache-2.0) AND Unicode-3.0 | + +### Legend + +* **Direct Dependency** +* Child Dependency +* _Optional Dependency_ +* ⚒️ Build-Only diff --git a/Cargo.toml b/Cargo.toml index c3399e6..57a6155 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "utc2k" -version = "0.11.0" +version = "0.11.1" authors = ["Josh Stoik "] edition = "2021" rust-version = "1.81"