From 70d267c3d0fee62b85924fbd26972df0ad899c96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Kijewski?= Date: Sun, 15 Sep 2024 03:13:25 +0200 Subject: [PATCH] Update to tz-rs v0.7.0 --- .github/actions/setup-rust/action.yaml | 43 ----------- .github/workflows/ci.yml | 101 +++++++++++++++---------- CHANGELOG.md | 4 + Cargo.toml | 30 +------- README.md | 9 ++- SECURITY.md | 1 + _typos.toml | 14 ++++ benchmarks/Cargo.toml | 16 ++-- clippy.toml | 2 +- deny.toml | 18 +---- examples/current-time/Cargo.toml | 4 +- fuzz/Cargo.toml | 21 +---- fuzz/bin/afl.rs | 5 -- fuzz/bin/honggfuzz.rs | 7 -- make-tzdb/Cargo.toml | 20 ++--- make-tzdb/src/main.rs | 2 +- src/changelog.rs | 1 - testing/Cargo.toml | 12 +-- testing/tests/by_name.rs | 2 +- testing/tests/proptest.rs | 2 +- tzdb/Cargo.toml | 33 ++++++++ tzdb/src/changelog.rs | 2 + {src => tzdb/src}/lib.rs | 34 ++++++--- {src => tzdb/src}/now.rs | 20 ++--- tzdb_data/Cargo.toml | 10 +-- tzdb_data/README.md | 8 +- tzdb_data/src/lib.rs | 39 +++------- 27 files changed, 210 insertions(+), 250 deletions(-) delete mode 100644 .github/actions/setup-rust/action.yaml create mode 100644 _typos.toml delete mode 100644 fuzz/bin/afl.rs delete mode 100644 fuzz/bin/honggfuzz.rs delete mode 100644 src/changelog.rs create mode 100644 tzdb/Cargo.toml create mode 100644 tzdb/src/changelog.rs rename {src => tzdb/src}/lib.rs (78%) rename {src => tzdb/src}/now.rs (94%) diff --git a/.github/actions/setup-rust/action.yaml b/.github/actions/setup-rust/action.yaml deleted file mode 100644 index e8c7f3c..0000000 --- a/.github/actions/setup-rust/action.yaml +++ /dev/null @@ -1,43 +0,0 @@ -name: Setup Rust Environment - -inputs: - key: - description: Cache key - required: true - toolchain: - description: Pass-through to toolchain on actions-rs - default: stable - required: false - components: - description: Pass-through to components on actions-rs - required: false - target: - description: Pass-through to target on actions-rs - required: false - -runs: - using: composite - steps: - - name: Remove rustfmt - run: rm -f ~/.cargo/bin/rustfmt ~/.cargo/bin/cargo-fmt - shell: bash - - - name: Install Toolchain - uses: dtolnay/rust-toolchain@v1 - id: toolchain-install - with: - toolchain: ${{ inputs.toolchain }} - components: ${{ inputs.components }} - target: ${{ inputs.target }} - - - name: Set default toolchain - run: rustup default ${{ inputs.toolchain }} || true - shell: bash - - - name: Update self - run: rustup self update || true - shell: bash - - - name: Update - run: rustup update || true - shell: bash diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 921d95f..74e1650 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,28 +3,20 @@ name: CI on: push: branches: - - main - - v0.1.x - - v0.2.x - - v0.3.x - - v0.4.x - - v0.5.x - - v0.6.x + - v0.7.x pull_request: branches: - - main - - v0.1.x - - v0.2.x - - v0.3.x - - v0.4.x - - v0.5.x - - v0.6.x + - v0.7.x schedule: - cron: "58 7 * * 3" +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + jobs: fmt: - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v4 @@ -32,7 +24,7 @@ jobs: submodules: recursive - name: Setup Rust - uses: ./.github/actions/setup-rust + uses: dtolnay/rust-toolchain@master with: toolchain: nightly components: rustfmt @@ -40,18 +32,17 @@ jobs: - run: cargo fmt --all -- --check lint: + runs-on: ubuntu-latest strategy: fail-fast: false matrix: toolchain: - - "1.56" + - "1.81" - stable - nightly versions: - "" - "-Zminimal-versions" - - runs-on: ubuntu-20.04 steps: - name: Checkout uses: actions/checkout@v4 @@ -59,7 +50,7 @@ jobs: submodules: recursive - name: Setup Rust - uses: ./.github/actions/setup-rust + uses: dtolnay/rust-toolchain@master with: toolchain: ${{ matrix.toolchain }} components: clippy @@ -73,7 +64,12 @@ jobs: - run: cargo clippy --workspace --all-targets -- -D warnings clippy-pedantic: - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest + strategy: + matrix: + package: + - tzdb + - tzdb_data steps: - name: Checkout uses: actions/checkout@v4 @@ -81,14 +77,15 @@ jobs: submodules: recursive - name: Setup Rust - uses: ./.github/actions/setup-rust + uses: dtolnay/rust-toolchain@master with: + toolchain: stable components: clippy - - run: cargo clippy --workspace --all-targets -- -D clippy::pedantic + - run: cargo clippy --package ${{ matrix.package }} --all-targets -- -D clippy::pedantic test: - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v4 @@ -96,8 +93,9 @@ jobs: submodules: recursive - name: Setup Rust - uses: ./.github/actions/setup-rust + uses: dtolnay/rust-toolchain@master with: + toolchain: stable components: clippy - run: cargo check --workspace --all-targets @@ -108,7 +106,7 @@ jobs: miri: name: "Miri" - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v4 @@ -116,7 +114,7 @@ jobs: submodules: recursive - name: Setup Rust - uses: ./.github/actions/setup-rust + uses: dtolnay/rust-toolchain@master with: toolchain: nightly components: miri @@ -128,6 +126,7 @@ jobs: run: cd testing && cargo miri test --workspace --all-targets cross-miri: + runs-on: ubuntu-latest strategy: fail-fast: false matrix: @@ -137,8 +136,6 @@ jobs: - powerpc-unknown-linux-gnu - powerpc64-unknown-linux-gnu - powerpc64le-unknown-linux-gnu - - runs-on: ubuntu-20.04 steps: - name: Checkout uses: actions/checkout@v4 @@ -146,7 +143,7 @@ jobs: submodules: recursive - name: Setup Rust - uses: ./.github/actions/setup-rust + uses: dtolnay/rust-toolchain@master with: toolchain: nightly components: miri @@ -156,7 +153,7 @@ jobs: run: cargo miri test --workspace --target ${{ matrix.target }} doc: - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v4 @@ -164,34 +161,29 @@ jobs: submodules: recursive - name: Setup Rust - uses: ./.github/actions/setup-rust + uses: dtolnay/rust-toolchain@master with: toolchain: nightly - components: rust-docs + components: miri - run: cargo doc --workspace --all-features --no-deps env: - RUSTDOCFLAGS: -D warnings --cfg docsrs + RUSTDOCFLAGS: -Z unstable-options --generate-link-to-definition --cfg=docsrs -D warnings audit: - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v4 with: submodules: recursive - - name: Setup Rust - uses: ./.github/actions/setup-rust - - name: Audit - uses: actions-rs/audit-check@v1 - with: - token: ${{ secrets.GITHUB_TOKEN }} + uses: EmbarkStudios/cargo-deny-action@v2 devskim: name: DevSkim - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest permissions: actions: read contents: read @@ -209,3 +201,28 @@ jobs: uses: github/codeql-action/upload-sarif@v3 with: sarif_file: devskim-results.sarif + + typos: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: crate-ci/typos@master + + feature-powerset: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + submodules: recursive + + - name: Setup Rust + uses: dtolnay/rust-toolchain@master + with: + toolchain: nightly + + - name: Install cargo-hack + uses: taiki-e/install-action@cargo-hack + + - name: Check feature-powerset + run: cargo hack --workspace --feature-powerset check diff --git a/CHANGELOG.md b/CHANGELOG.md index 93c2a00..4705830 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## Changes between the versions +### 0.7.0 (2024-09-15) + +* Update to tz-rs v0.7.0 + ### 0.6.1 (2023-12-30) * Split into `tzdb` and `tzdb_data` diff --git a/Cargo.toml b/Cargo.toml index 04f575b..a54a52d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,33 +1,7 @@ -[package] -name = "tzdb" -version = "0.6.1" -edition = "2018" -authors = ["René Kijewski "] -repository = "https://github.com/Kijewski/tzdb" -description = "Static time zone information for tz-rs" -license = "Apache-2.0" -keywords = ["date", "time", "timezone", "zone", "calendar"] -categories = ["date-and-time"] -readme = "README.md" -# rust-version = "1.56" - -[dependencies] -iana-time-zone = { version = "^0.1.50", default-features = false, features = ["fallback"], optional = true } -tzdb_data = { version = "^0.1.0", default-features = false, path = "tzdb_data" } -tz-rs = { version = "^0.6.14", default-features = false, features = ["const", "std"] } - -[features] -default = ["local"] -# Enable functions to query the current system time: -local = ["iana-time-zone"] - -[package.metadata.docs.rs] -all-features = true -rustdoc-args = ["--cfg", "docsrs"] - [workspace] members = [ - ".", "examples/current-time", + "tzdb", "tzdb_data", ] +resolver = "2" diff --git a/README.md b/README.md index 5c52870..eb636df 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,10 @@ # tzdb — Time Zone Database -[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/Kijewski/tzdb/ci.yml?branch=v0.6.x&style=for-the-badge)](https://github.com/Kijewski/tzdb/actions/workflows/ci.yml) -[![Crates.io](https://img.shields.io/crates/v/tzdb?logo=rust&style=for-the-badge)](https://crates.io/crates/tzdb) -![Minimum supported Rust version](https://img.shields.io/badge/rustc-1.56+-important?logo=rust&style=for-the-badge "Minimum Supported Rust Version: 1.56") -[![License: Apache-2.0](https://img.shields.io/badge/license-Apache--2.0-informational?logo=apache&style=for-the-badge)](https://github.com/Kijewski/tzdb/blob/v0.6.1/LICENSE.md "License: Apache-2.0") +[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/Kijewski/tzdb/ci.yml?branch=v0.7.x&style=flat-square&logo=github&logoColor=white "GitHub Workflow Status")](https://github.com/Kijewski/tzdb/actions/workflows/ci.yml) +[![Crates.io](https://img.shields.io/crates/v/tzdb?logo=rust&style=flat-square "Crates.io")](https://crates.io/crates/tzdb) +[![docs.rs](https://img.shields.io/docsrs/tzdb?logo=docsdotrs&style=flat-square&logoColor=white "docs.rs")](https://docs.rs/tzdb/) +![Minimum supported Rust version](https://img.shields.io/badge/rustc-1.81+-important?logo=rust&style=flat-square "Minimum Supported Rust Version: 1.81") +[![License: Apache-2.0](https://img.shields.io/badge/license-Apache--2.0-informational?logo=apache&style=flat-square)](https://github.com/Kijewski/tzdb/blob/v0.6.1/LICENSE.md "License: Apache-2.0") Static time zone information for [tz-rs](https://crates.io/crates/tz-rs). diff --git a/SECURITY.md b/SECURITY.md index 6b9ccad..03801a2 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -4,6 +4,7 @@ | Version | Supported | | :-----: | :----------------: | +| 0.7.x | :white_check_mark: | | 0.6.x | :white_check_mark: | | 0.5.x | :white_check_mark: | | 0.4.x | :white_check_mark: | diff --git a/_typos.toml b/_typos.toml new file mode 100644 index 0000000..6838302 --- /dev/null +++ b/_typos.toml @@ -0,0 +1,14 @@ +[default] +locale = "en-us" + +[files] +extend-exclude = [ + # hidden files + ".*", + # generated files + "tzdb_data/src/generated/*", +] + +[default.extend-words] +# a suffix, as in "2nd" +nd = "nd" diff --git a/benchmarks/Cargo.toml b/benchmarks/Cargo.toml index b3ae1eb..1dfdd3e 100644 --- a/benchmarks/Cargo.toml +++ b/benchmarks/Cargo.toml @@ -6,20 +6,20 @@ authors = ["René Kijewski "] repository = "https://github.com/Kijewski/tzdb" description = "… benchmarking …" license = "Apache-2.0" -# rust-version = "1.56" +rust-version = "1.81.0" publish = false [dependencies] -chrono-tz = { version = "0.8", features = ["case-insensitive"] } +chrono-tz = { version = "0.10.0", features = ["case-insensitive"] } tzdb_data = { path = "../tzdb_data" } [dev-dependencies] -criterion = { version = "0.5", default-features = false, features = ["html_reports"] } -minstant = "0.1" -rand = { version = "0.8", default-features = false, features = ["std"] } -rand_xoshiro = "0.6" -test-strategy = "0.3" -structmeta = "0.2" +criterion = { version = "0.5.1", default-features = false, features = ["html_reports"] } +minstant = "0.1.7" +rand = { version = "0.8.5", default-features = false, features = ["std"] } +rand_xoshiro = "0.6.0" +test-strategy = "0.4.0" +structmeta = "0.3.0" [[bench]] name = "by-name" diff --git a/clippy.toml b/clippy.toml index 6c9ad39..5e90250 100644 --- a/clippy.toml +++ b/clippy.toml @@ -1 +1 @@ -msrv = "1.55.0" +msrv = "1.81.0" diff --git a/deny.toml b/deny.toml index f5361bd..25ebabb 100644 --- a/deny.toml +++ b/deny.toml @@ -1,15 +1,5 @@ [licenses] -allow = [ - "MIT", - "Apache-2.0", - "Apache-2.0 WITH LLVM-exception", - "Unicode-DFS-2016", - "BSD-3-Clause", -] -confidence-threshold = 1 - -[[licenses.clarify]] -name = "fnv" -version = "1.0.0" -expression = "Apache-2.0 OR MIT" -license-files = [] +version = 2 +allow = ["Apache-2.0", "MIT", "MIT-0", "Unicode-DFS-2016"] +private = { ignore = true } +confidence-threshold = 1.0 diff --git a/examples/current-time/Cargo.toml b/examples/current-time/Cargo.toml index e28926a..cf6667d 100644 --- a/examples/current-time/Cargo.toml +++ b/examples/current-time/Cargo.toml @@ -1,11 +1,11 @@ [package] name = "current-time" version = "0.0.0" -edition = "2018" +edition = "2021" authors = ["René Kijewski "] repository = "https://github.com/Kijewski/tzdb" license = "MIT OR Apache-2.0" publish = false [dependencies] -tzdb = { path = "../.." } +tzdb = { path = "../../tzdb" } diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml index d97d0e5..d2ad1a3 100644 --- a/fuzz/Cargo.toml +++ b/fuzz/Cargo.toml @@ -6,7 +6,7 @@ repository = "https://github.com/Kijewski/tzdb" description = "… fuzz …" license = "Apache-2.0" publish = false -edition = "2018" +edition = "2021" [package.metadata] cargo-fuzz = true @@ -14,30 +14,13 @@ cargo-fuzz = true [dependencies] tzdb_data = { path = "../tzdb_data" } -afl = { version = "0.15", optional = true } -honggfuzz = { version = "0.5", optional = true } -libfuzzer-sys = { version = "0.4", optional = true } - -[[bin]] -name = "tzdb-fuzz-afl" -path = "bin/afl.rs" -test = false -doc = false -required-features = ["afl"] - -[[bin]] -name = "tzdb-fuzz-honggfuzz" -path = "bin/honggfuzz.rs" -test = false -doc = false -required-features = ["honggfuzz"] +libfuzzer-sys = "0.4" [[bin]] name = "tzdb-fuzz-libfuzzer" path = "bin/libfuzzer.rs" test = false doc = false -required-features = ["libfuzzer-sys"] [workspace] members = ["."] diff --git a/fuzz/bin/afl.rs b/fuzz/bin/afl.rs deleted file mode 100644 index c7d612a..0000000 --- a/fuzz/bin/afl.rs +++ /dev/null @@ -1,5 +0,0 @@ -fn main() { - afl::fuzz!(|name: &[u8]| { - let _ = tzdb_data::find_tz(name); - }); -} diff --git a/fuzz/bin/honggfuzz.rs b/fuzz/bin/honggfuzz.rs deleted file mode 100644 index c7edce1..0000000 --- a/fuzz/bin/honggfuzz.rs +++ /dev/null @@ -1,7 +0,0 @@ -fn main() { - loop { - honggfuzz::fuzz!(|name: &[u8]| { - let _ = tzdb_data::find_tz(name); - }); - } -} diff --git a/make-tzdb/Cargo.toml b/make-tzdb/Cargo.toml index 00a3a68..804f870 100644 --- a/make-tzdb/Cargo.toml +++ b/make-tzdb/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "make-tzdb" version = "0.0.0" -edition = "2018" +edition = "2021" authors = ["René Kijewski "] repository = "https://github.com/Kijewski/tzdb" description = "Tool to generate `tzdb/src/generated.rs`" @@ -9,15 +9,15 @@ license = "MIT OR Apache-2.0" publish = false [dependencies] -anyhow = "1" -convert_case = "0.6" -indexmap = "2" -itertools = "0.12" -ron = "0.8" -serde = { version = "1", features = ["derive"] } -subprocess = "0.2" -tz-rs = "0.6" -walkdir = "2" +anyhow = "1.0.88" +convert_case = "0.6.0" +indexmap = "2.5.0" +itertools = "0.13.0" +ron = "0.8.1" +serde = { version = "1.0.210", features = ["derive"] } +subprocess = "0.2.9" +tz-rs = "0.7.0" +walkdir = "2.5.0" [workspace] members = ["."] diff --git a/make-tzdb/src/main.rs b/make-tzdb/src/main.rs index 9d1c219..b50cde3 100644 --- a/make-tzdb/src/main.rs +++ b/make-tzdb/src/main.rs @@ -203,7 +203,7 @@ fn collect_entries_by_major(entries_by_bytes: &IndexMap, Vec>) - (Some(_), None) => Ordering::Less, (Some(l), Some(r)) => l.cmp(r), }) - .group_by(|(k, _)| k.map(|s| s.to_owned())) + .chunk_by(|(k, _)| k.map(|s| s.to_owned())) .into_iter() .map(|(major, entries)| { let mut entries = entries.map(|(_, e)| e).collect_vec(); diff --git a/src/changelog.rs b/src/changelog.rs deleted file mode 100644 index a03f30b..0000000 --- a/src/changelog.rs +++ /dev/null @@ -1 +0,0 @@ -#![doc = include_str!("../CHANGELOG.md")] diff --git a/testing/Cargo.toml b/testing/Cargo.toml index 8cdf27f..a1437a9 100644 --- a/testing/Cargo.toml +++ b/testing/Cargo.toml @@ -6,16 +6,16 @@ authors = ["René Kijewski "] repository = "https://github.com/Kijewski/tzdb" description = "… benchmarking …" license = "Apache-2.0" -# rust-version = "1.56" +rust-version = "1.81.0" publish = false [dependencies] -tzdb = { path = ".." } +tzdb = { path = "../tzdb" } -proptest = "1.2.0" -structmeta = "0.2.0" -test-strategy = "0.3.1" -tz-rs = { version = "^0.6.14", default-features = false, features = ["const", "std"] } +proptest = "1.5.0" +structmeta = "0.3.0" +test-strategy = "0.4.0" +tz-rs = { version = "0.7.0", default-features = false, features = ["std"] } [workspace] members = ["."] diff --git a/testing/tests/by_name.rs b/testing/tests/by_name.rs index e156aa0..61a432a 100644 --- a/testing/tests/by_name.rs +++ b/testing/tests/by_name.rs @@ -1,6 +1,6 @@ #![cfg(test)] -use tzdb::{time_zone, tz_by_name, raw_tz_by_name}; +use tzdb::{raw_tz_by_name, time_zone, tz_by_name}; #[test] fn test_by_name() { diff --git a/testing/tests/proptest.rs b/testing/tests/proptest.rs index 8d60df4..c562634 100644 --- a/testing/tests/proptest.rs +++ b/testing/tests/proptest.rs @@ -4,7 +4,7 @@ use proptest::collection::{vec, SizeRange}; use proptest::prelude::*; use test_strategy::proptest; use tz::TimeZoneRef; -use tzdb::{tz_by_name, raw_tz_by_name}; +use tzdb::{raw_tz_by_name, tz_by_name}; fn ascii_string(size: impl Into) -> impl Strategy { vec(proptest::char::range('\0', '\x7f'), size).prop_map(|v| v.into_iter().collect()) diff --git a/tzdb/Cargo.toml b/tzdb/Cargo.toml new file mode 100644 index 0000000..ba6d5d0 --- /dev/null +++ b/tzdb/Cargo.toml @@ -0,0 +1,33 @@ +[package] +name = "tzdb" +version = "0.7.0-pre.0" +edition = "2021" +authors = ["René Kijewski "] +repository = "https://github.com/Kijewski/tzdb" +description = "Static time zone information for tz-rs" +license = "Apache-2.0" +keywords = ["date", "time", "timezone", "zone", "calendar"] +categories = ["date-and-time"] +readme = "README.md" +rust-version = "1.81.0" + +[dependencies] +tzdb_data = { version = "^0.2.0-pre.0", default-features = false, path = "../tzdb_data" } + +iana-time-zone = { version = "^0.1.60", default-features = false, features = ["fallback"], optional = true } +tz-rs = { version = "^0.7.0", default-features = false, features = ["std"] } + +[features] +default = ["local", "now", "std"] +# Enables querying the current time in a given time zone: +now = ["std"] +# Enable functions to query the current system time: +local = ["std", "dep:iana-time-zone"] +# Enable the use of features in the `std` crate: +std = ["alloc"] +# Enable the use of features in the `alloc` crate: +alloc = [] + +[package.metadata.docs.rs] +all-features = true +rustdoc-args = ["--generate-link-to-definition", "--cfg=docsrs"] diff --git a/tzdb/src/changelog.rs b/tzdb/src/changelog.rs new file mode 100644 index 0000000..bb0d95c --- /dev/null +++ b/tzdb/src/changelog.rs @@ -0,0 +1,2 @@ +#![doc(cfg(any()))] +#![doc = include_str!("../../CHANGELOG.md")] diff --git a/src/lib.rs b/tzdb/src/lib.rs similarity index 78% rename from src/lib.rs rename to tzdb/src/lib.rs index bb0c1c9..bb20766 100644 --- a/src/lib.rs +++ b/tzdb/src/lib.rs @@ -14,7 +14,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#![cfg_attr(docsrs, feature(doc_cfg))] +#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] #![allow(unknown_lints)] #![forbid(unsafe_code)] #![warn(absolute_paths_not_starting_with_crate)] @@ -32,13 +32,15 @@ #![warn(unused_extern_crates)] #![warn(unused_lifetimes)] #![warn(unused_results)] +#![no_std] //! # `tzdb` — Time Zone Database //! -//! [![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/Kijewski/tzdb/ci.yml?branch=v0.6.x&style=for-the-badge)](https://github.com/Kijewski/tzdb/actions/workflows/ci.yml) -//! [![Crates.io](https://img.shields.io/crates/v/tzdb?logo=rust&style=for-the-badge)](https://crates.io/crates/tzdb) -//! ![Minimum supported Rust version](https://img.shields.io/badge/rustc-1.56+-important?logo=rust&style=for-the-badge "Minimum Supported Rust Version: 1.56") -//! [![License: Apache-2.0](https://img.shields.io/badge/license-Apache--2.0-informational?logo=apache&style=for-the-badge)](https://github.com/Kijewski/tzdb/blob/v0.6.1/LICENSE.md "License: Apache-2.0") +//! [![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/Kijewski/tzdb/ci.yml?branch=v0.7.x&style=flat-square&logo=github&logoColor=white "GitHub Workflow Status")](https://github.com/Kijewski/tzdb/actions/workflows/ci.yml) +//! [![Crates.io](https://img.shields.io/crates/v/tzdb?logo=rust&style=flat-square "Crates.io")](https://crates.io/crates/tzdb) +//! [![docs.rs](https://img.shields.io/docsrs/tzdb?logo=docsdotrs&style=flat-square&logoColor=white "docs.rs")](https://docs.rs/tzdb/) +//! ![Minimum supported Rust version](https://img.shields.io/badge/rustc-1.81+-important?logo=rust&style=flat-square "Minimum Supported Rust Version: 1.81") +//! [![License: Apache-2.0](https://img.shields.io/badge/license-Apache--2.0-informational?logo=apache&style=flat-square)](https://github.com/Kijewski/tzdb/blob/v0.6.1/LICENSE.md "License: Apache-2.0") //! //! Static time zone information for [tz-rs](https://crates.io/crates/tz-rs). //! @@ -55,33 +57,47 @@ //! //! // access by identifier //! let time_zone = tzdb::time_zone::europe::KYIV; +//! # #[cfg(feature = "now")] { //! let current_time = tzdb::now::in_tz(tzdb::time_zone::europe::KYIV).unwrap(); +//! # } //! //! // access by name //! let time_zone = tzdb::tz_by_name("Europe/Berlin").unwrap(); +//! # #[cfg(feature = "now")] { //! let current_time = tzdb::now::in_named("Europe/Berlin").unwrap(); +//! # } //! //! // names are case insensitive //! let time_zone = tzdb::tz_by_name("ArCtIc/LoNgYeArByEn").unwrap(); +//! # #[cfg(feature = "now")] { //! let current_time = tzdb::now::in_named("ArCtIc/LoNgYeArByEn").unwrap(); +//! # } //! //! // provide a default time zone -//! # #[cfg(feature = "local")] { +//! # #[cfg(feature = "now")] { //! let current_time = tzdb::now::local_or(tzdb::time_zone::GMT).unwrap(); -//! # } //! let current_time = tzdb::now::in_named_or(tzdb::time_zone::GMT, "Some/City").unwrap(); +//! # } //! ``` //! //! ## Feature flags //! //! * `local` (enabled by default) — enable functions to query the current system time -//! +//! * `now` (enabled by default) — enable functions to query the current system time +//! * `std` (enabled by default, `now` and `local`) — enable the use of features in the [`std`] crate +//! * `alloc` (enabled by `std`) — enable the use of features in the [`alloc`] crate + +#[cfg(docsrs)] +extern crate alloc; +#[cfg(docsrs)] +extern crate std; #[cfg(docsrs)] pub mod changelog; +#[cfg(feature = "now")] pub mod now; -#[cfg_attr(docsrs, doc(no_inline))] +#[doc(no_inline)] pub use tzdb_data::{time_zone, TZ_NAMES, VERSION, VERSION_HASH}; /// Find a time zone by name, e.g. `"Europe/Berlin"` (case-insensitive) diff --git a/src/now.rs b/tzdb/src/now.rs similarity index 94% rename from src/now.rs rename to tzdb/src/now.rs index dd266f2..62fbcda 100644 --- a/src/now.rs +++ b/tzdb/src/now.rs @@ -1,11 +1,12 @@ //! Get the current time in some time zone -use std::convert::TryFrom; -use std::fmt; +extern crate std; + +use core::convert::TryFrom; +use core::fmt; use std::time::{SystemTime, SystemTimeError}; -use tz::error::ProjectDateTimeError; -use tz::{DateTime, TimeZoneRef}; +use tz::{DateTime, TimeZoneRef, TzError}; #[cfg(not(feature = "local"))] mod iana_time_zone { @@ -33,7 +34,7 @@ pub enum NowError { /// Unknown system time zone. Only returned by [`local()`], and [`in_named()`]. UnknownTimezone, /// Could not project timestamp. - ProjectDateTime(ProjectDateTimeError), + ProjectDateTime(TzError), /// Could not get current system time. Utcnow(SystemTimeError), } @@ -49,8 +50,8 @@ impl fmt::Display for NowError { } } -impl std::error::Error for NowError { - fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { +impl core::error::Error for NowError { + fn source(&self) -> Option<&(dyn core::error::Error + 'static)> { match self { #[cfg(feature = "local")] Self::TimeZone(err) => Some(err), @@ -169,9 +170,8 @@ pub fn in_tz(time_zone_ref: TimeZoneRef<'_>) -> Result { let now = SystemTime::now() .duration_since(SystemTime::UNIX_EPOCH) .map_err(NowError::Utcnow)?; - let secs = i64::try_from(now.as_secs()).map_err(|_| { - NowError::ProjectDateTime(ProjectDateTimeError("now is too far in the future")) - })?; + let secs = + i64::try_from(now.as_secs()).map_err(|_| NowError::ProjectDateTime(TzError::OutOfRange))?; let nanos = now.subsec_nanos(); DateTime::from_timespec(secs, nanos, time_zone_ref).map_err(NowError::ProjectDateTime) } diff --git a/tzdb_data/Cargo.toml b/tzdb_data/Cargo.toml index 79f3ccb..2c06b30 100644 --- a/tzdb_data/Cargo.toml +++ b/tzdb_data/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "tzdb_data" -version = "0.1.3" -edition = "2018" +version = "0.2.0-pre.0" +edition = "2021" authors = ["René Kijewski "] repository = "https://github.com/Kijewski/tzdb" description = "Static, #![no_std] time zone information for tz-rs" @@ -9,11 +9,11 @@ license = "MIT-0" keywords = ["timezone", "no_std"] categories = ["date-and-time", "no-std"] readme = "README.md" -# rust-version = "1.56" +rust-version = "1.81.0" [dependencies] -tz-rs = { version = "^0.6.14", default-features = false, features = ["const"] } +tz-rs = { version = "^0.7.0", default-features = false } [package.metadata.docs.rs] all-features = true -rustdoc-args = ["--cfg", "docsrs"] +rustdoc-args = ["--generate-link-to-definition", "--cfg=docsrs"] diff --git a/tzdb_data/README.md b/tzdb_data/README.md index fea4d61..d5c31bd 100644 --- a/tzdb_data/README.md +++ b/tzdb_data/README.md @@ -1,9 +1,9 @@ # tzdb_data — Time Zone Database -[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/Kijewski/tzdb/ci.yml?branch=v0.6.x&style=for-the-badge)](https://github.com/Kijewski/tzdb/actions/workflows/ci.yml) -[![Crates.io](https://img.shields.io/crates/v/tzdb_data?logo=rust&style=for-the-badge)](https://crates.io/crates/tzdb_data) -![Minimum supported Rust version](https://img.shields.io/badge/rustc-1.56+-important?logo=rust&style=for-the-badge "Minimum Supported Rust Version: 1.56") -[![License: MIT-0](https://img.shields.io/badge/license-MIT--0-informational?logo=apache&style=for-the-badge)](https://github.com/Kijewski/tzdb/blob/v0.6.1/tzdb_data/LICENSE.md "License: MIT-0") +[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/Kijewski/tzdb/ci.yml?branch=v0.7.x&style=flat-square&logo=github&logoColor=white "GitHub Workflow Status")](https://github.com/Kijewski/tzdb/actions/workflows/ci.yml) +[![Crates.io](https://img.shields.io/crates/v/tzdb_data?logo=rust&style=flat-square "Crates.io")](https://crates.io/crates/tzdb_data) +![Minimum supported Rust version](https://img.shields.io/badge/rustc-1.81+-important?logo=rust&style=flat-square "Minimum Supported Rust Version: 1.81") +[![License: MIT-0](https://img.shields.io/badge/license-MIT--0-informational?logo=apache&style=flat-square)](https://github.com/Kijewski/tzdb/blob/v0.6.1/tzdb_data/LICENSE.md "License: MIT-0") Static, `#![no_std]` time zone information for tz-rs diff --git a/tzdb_data/src/lib.rs b/tzdb_data/src/lib.rs index d442447..2c9ef79 100644 --- a/tzdb_data/src/lib.rs +++ b/tzdb_data/src/lib.rs @@ -26,10 +26,11 @@ //! # `tzdb_data` — Time Zone Database //! -//! [![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/Kijewski/tzdb/ci.yml?branch=v0.6.x&style=for-the-badge)](https://github.com/Kijewski/tzdb/actions/workflows/ci.yml) -//! [![Crates.io](https://img.shields.io/crates/v/tzdb_data?logo=rust&style=for-the-badge)](https://crates.io/crates/tzdb_data) -//! ![Minimum supported Rust version](https://img.shields.io/badge/rustc-1.56+-important?logo=rust&style=for-the-badge "Minimum Supported Rust Version: 1.56") -//! [![License: MIT-0](https://img.shields.io/badge/license-MIT--0-informational?logo=apache&style=for-the-badge)](https://github.com/Kijewski/tzdb/blob/v0.6.1/tzdb_data/LICENSE.md "License: MIT-0") +//! [![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/Kijewski/tzdb/ci.yml?branch=v0.7.x&style=flat-square&logo=github&logoColor=white "GitHub Workflow Status")](https://github.com/Kijewski/tzdb/actions/workflows/ci.yml) +//! [![Crates.io](https://img.shields.io/crates/v/tzdb_data?logo=rust&style=flat-square "Crates.io")](https://crates.io/crates/tzdb_data) +//! [![docs.rs](https://img.shields.io/docsrs/tzdb_data?logo=docsdotrs&style=flat-square&logoColor=white "docs.rs")](https://docs.rs/tzdb_data/) +//! ![Minimum supported Rust version](https://img.shields.io/badge/rustc-1.81+-important?logo=rust&style=flat-square "Minimum Supported Rust Version: 1.81") +//! [![License: MIT-0](https://img.shields.io/badge/license-MIT--0-informational?logo=apache&style=flat-square)](https://github.com/Kijewski/tzdb/blob/v0.6.1/tzdb_data/LICENSE.md "License: MIT-0") //! //! Static, `#![no_std]` time zone information for tz-rs //! @@ -49,7 +50,7 @@ mod generated; -#[cfg_attr(docsrs, doc(inline))] +#[doc(inline)] pub use crate::generated::{time_zone, TZ_NAMES, VERSION, VERSION_HASH}; /// Find a time zone by name, e.g. `b"Europe/Berlin"` (case-insensitive) @@ -90,7 +91,6 @@ pub const fn find_raw(s: &[u8]) -> Option<&'static [u8]> { } } -#[allow(clippy::out_of_bounds_indexing)] #[must_use] const fn new_time_zone_ref( transitions: &'static [tz::timezone::Transition], @@ -100,15 +100,10 @@ const fn new_time_zone_ref( ) -> tz::timezone::TimeZoneRef<'static> { match tz::timezone::TimeZoneRef::new(transitions, local_time_types, leap_seconds, extra_rule) { Ok(value) => value, - Err(_) => { - #[allow(unconditional_panic)] - let err = [][0]; - err - }, + Err(_) => panic!(), } } -#[allow(clippy::out_of_bounds_indexing)] #[must_use] const fn new_local_time_type( ut_offset: i32, @@ -117,11 +112,7 @@ const fn new_local_time_type( ) -> tz::LocalTimeType { match tz::LocalTimeType::new(ut_offset, is_dst, time_zone_designation) { Ok(value) => value, - Err(_) => { - #[allow(unconditional_panic)] - let err = [][0]; - err - }, + Err(_) => panic!(), } } @@ -133,7 +124,6 @@ const fn new_transition( tz::timezone::Transition::new(unix_leap_time, local_time_type_index) } -#[allow(clippy::out_of_bounds_indexing)] #[must_use] const fn new_alternate_time( std: tz::LocalTimeType, @@ -152,24 +142,15 @@ const fn new_alternate_time( dst_end_time, ) { Ok(value) => value, - Err(_) => { - #[allow(unconditional_panic)] - let err = [][0]; - err - }, + Err(_) => panic!(), } } -#[allow(clippy::out_of_bounds_indexing)] #[must_use] const fn new_month_week_day(month: u8, week: u8, week_day: u8) -> tz::timezone::MonthWeekDay { match tz::timezone::MonthWeekDay::new(month, week, week_day) { Ok(value) => value, - Err(_) => { - #[allow(unconditional_panic)] - let err = [][0]; - err - }, + Err(_) => panic!(), } }