Skip to content

Commit

Permalink
Merge pull request #98 from Kijewski/v0.4.x
Browse files Browse the repository at this point in the history
* Increase MSRV to 1.60
* Upgrade `phf` and `phf_shared` to 0.11.0
* Ensure that spinoso-time still works
* Update tz-rs dependency declaration to use no default features
* Temporary fix for testing shadow-rs
* Fix doctest to only run if "std" is enabled
* Add `now` feature and module (#82)
* Upgrade to iana-time-zone 0.1.41

Co-authored-by: Ryan Lopopolo <rjl@hyperbo.la>
  • Loading branch information
Kijewski and lopopolo authored Aug 2, 2022
2 parents 4301cc3 + 7d435a5 commit ba88957
Show file tree
Hide file tree
Showing 11 changed files with 434 additions and 50 deletions.
27 changes: 21 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ on:
push:
branches:
- main
- v0.4.x
pull_request:
branches:
- main
- v0.4.x
schedule:
- cron: "58 7 * * 3"

Expand All @@ -31,7 +33,7 @@ jobs:
fail-fast: false
matrix:
toolchain:
- "1.55"
- "1.60"
- stable
- nightly
platform:
Expand Down Expand Up @@ -82,12 +84,25 @@ jobs:

- run: cd test-shadow && cargo run

test-artichoke:
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Rust
uses: ./.github/actions/setup-rust
with:
key: artichoke

- run: cd test-artichoke && cargo run

minimum-versions:
strategy:
fail-fast: false
matrix:
toolchain:
- "1.55"
- "1.60"
- stable
- nightly
platform:
Expand Down Expand Up @@ -201,7 +216,7 @@ jobs:
fail-fast: false
matrix:
toolchain:
- "1.55"
- "1.60"
- stable
- nightly
platform:
Expand All @@ -224,14 +239,14 @@ jobs:
run: cargo hack --version || cargo +stable install cargo-hack --force

- name: Powerset
run: cargo hack test --feature-powerset --ignore-private --doc
run: cargo hack test --feature-powerset --exclude-features default --ignore-private --doc

powerset-tests:
strategy:
fail-fast: false
matrix:
toolchain:
- "1.55"
- "1.60"
- stable
- nightly
platform:
Expand All @@ -254,7 +269,7 @@ jobs:
run: cargo hack --version || cargo +stable install cargo-hack --force

- name: Powerset
run: cargo hack test --feature-powerset --ignore-private --tests --lib
run: cargo hack test --feature-powerset --exclude-features default --ignore-private --tests --lib

build-cross:
strategy:
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
## Changes between the versions

### 0.4.0 (????-??-??)

* Increase msrv to 1.60
* Add `now` module, which uses [`utcnow()`](https://crates.io/crates/utcnow),
and works in `#[no_std]`

### 0.3.4 (2022-08-02)

* Fix endianess issues for PowerPCs
Expand Down
38 changes: 20 additions & 18 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,54 +1,56 @@
[package]
name = "tzdb"
version = "0.3.4"
edition = "2018"
edition = "2021"
authors = ["René Kijewski <crates.io@k6i.de>"]
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"]
categories = ["date-and-time", "no-std"]
readme = "README.md"
#rust-version = "1.55"
rust-version = "1.60"

[dependencies]
# FIXME: using "default-features = false" is a breaking change
tz-rs = { version = "^0.6.12", features = ["const"] }
tz-rs = { version = "^0.6.12", default-features = false, features = ["const"] }

# optional dependencies
iana-time-zone = { version = "^0.1.40", optional = true }
phf = { version = "^0.10.0", default-features = false, optional = true }
phf_shared = { version = "^0.10.0", default-features = false, optional = true }
iana-time-zone = { version = "^0.1.41", default-features = false, optional = true }
phf = { version = "^0.11.0", default-features = false, optional = true }
phf_shared = { version = "^0.11.0", default-features = false, optional = true }
utcnow = { version = "^0.1.3", default-features = false, optional = true }

[dev-dependencies]
tz-rs = { version = "^0.6.12", default-features = false, features = ["const"] }
proptest = "=1"
test-strategy = "=0.1.2"
structmeta = "=0.1.4"
test-strategy = "^0.2.0"
structmeta = "^0.1.5"

[features]
default = ["by-name", "list", "local", "std", "fallback"]
default = ["by-name", "list", "local", "std", "fallback", "now"]

# Enables [tz_by_name()] to get a time zone at runtime by name:
# Enables [`tz_by_name()`] to get a time zone at runtime by name:
by-name = ["phf", "phf_shared"]

# Enables [TZ_NAMES] to get a list of all shipped time zones:
# Enables [`TZ_NAMES`] to get a list of all shipped time zones:
list = []

# Enables [local_tz()] to get the system time zone:
# Enables [`local_tz()`] to get the system time zone:
local = ["by-name", "iana-time-zone"]

# Make the unparsed, binary tzdata of a time zone available:
binary = []

# Enable features that need the standard library `std`:
std = ["alloc", "tz-rs/std"]
std = ["alloc", "tz-rs/std", "utcnow?/std"]

# Enable features that need the standard library `alloc`:
alloc = ["tz-rs/alloc"]

# Compile for unknown target platforms, too:
fallback = []
# Do not fail to compile for unknown target platforms:
fallback = ["iana-time-zone?/fallback", "utcnow?/fallback"]

# Enables the module [`now`] to get the current time:
now = ["utcnow"]

[package.metadata.docs.rs]
all-features = true
Expand Down
34 changes: 22 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![GitHub Workflow Status](https://img.shields.io/github/workflow/status/Kijewski/tzdb/CI?logo=github)](https://github.com/Kijewski/tzdb/actions/workflows/ci.yml)
[![Crates.io](https://img.shields.io/crates/v/tzdb?logo=rust)](https://crates.io/crates/tzdb)
![Minimum supported Rust version](https://img.shields.io/badge/rustc-1.55+-important?logo=rust "Minimum Supported Rust Version")
![Minimum supported Rust version](https://img.shields.io/badge/rustc-1.60+-important?logo=rust "Minimum Supported Rust Version")
[![License](https://img.shields.io/crates/l/tzdb?color=informational&logo=apache)](/LICENSES)

Static time zone information for [tz-rs](https://crates.io/crates/tz-rs).
Expand All @@ -16,26 +16,36 @@ See the documentation for a full list the the contained time zones:
## Usage examples

```rust
use tz::{DateTime, TimeZone};
use tzdb::{time_zone, tz_by_name};
let time_zone = tzdb::local_tz()?; // tz::TimeZoneRef<'_>
let current_time = tzdb::now::local()?; // tz::DateTime

// access by identifier
DateTime::now(time_zone::europe::KIEV);
let time_zone = tzdb::time_zone::europe::KIEV;
let current_time = tzdb::now::in_tz(tzdb::time_zone::europe::KIEV)?;

// access by name
DateTime::now(tz_by_name("Europe/Berlin").unwrap());
let time_zone = tzdb::tz_by_name("Europe/Berlin")?;
let current_time = tzdb::now::in_named("Europe/Berlin")?;

// names are case insensitive
DateTime::now(tz_by_name("ArCtIc/LongYeArByEn").unwrap());
let time_zone = tzdb::tz_by_name("ArCtIc/LongYeArByEn")?;
let current_time = tzdb::now::in_named("ArCtIc/LongYeArByEn")?;

// provide a default time zone
let current_time = tzdb::now::local_or(tzdb::time_zone::GMT)?;
let current_time = tzdb::now::in_named_or(tzdb::time_zone::GMT, "Some/City")?;
```

## Feature flags

* `by-name` <sup>*(enabled by default, enabled by* `local`*)*</sup> — enables tz_by_name() to get a time zone at runtime by name
* `list` <sup>*(enabled by default)*</sup> — enables TZ_NAMES to get a list of all shipped time zones
* `local` <sup>*(enabled by default)*</sup> — enables local_tz() to get the system time zone
* `by-name` <sup>(enabled by default, enabled by `local`)</sup> — enables `tz_by_name()` to get a time zone at runtime by name
* `list` <sup>(enabled by default)</sup> — enables `TZ_NAMES` to get a list of all shipped time zones
* `local` <sup>(enabled by default)</sup> — enables `local_tz()` to get the system time zone
* `now` <sup>(enabled by default)</sup> — enables the module `now` to get the current time
* `binary` – make the unparsed, binary tzdata of a time zone available
* `std` <sup>*(enabled by default)*</sup> – enable features that need the standard library `std`
* `alloc` <sup>*(enabled by default, enabled by* `std`*)*</sup> – enable features that need the standard library `alloc`
* `fallback` <sup>*(enabled by default)*</sup> — compile for unknown target platforms, too
* `std` <sup>(enabled by default)</sup> – enable features that need the standard library `std`
* `alloc` <sup>(enabled by default, enabled by `std`)</sup> – enable features that need the standard library `alloc`
* `fallback` <sup>(enabled by default)</sup> — compile for unknown target platforms, too

## Git cloning

Expand Down
1 change: 1 addition & 0 deletions clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
msrv = "1.60.0"
10 changes: 4 additions & 6 deletions examples/current-time.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
use std::env::args;
use std::process::exit;

use tz::{DateTime, Result};
use tzdb::time_zone::UTC;
use tzdb::{local_tz, tz_by_name, TZ_NAMES};
use tzdb::{local_tz, now, time_zone, tz_by_name, TZ_NAMES};

pub fn main() -> Result<()> {
pub fn main() -> Result<(), now::NowError> {
let mut args = args().into_iter().fuse();
let exe = args.next();
let exe = exe.as_deref().unwrap_or("current-time");
Expand Down Expand Up @@ -42,10 +40,10 @@ pub fn main() -> Result<()> {
eprintln!("No time zone selected, defaulting to the system time zone.");
eprintln!("To see a list of all known time zones run: {} --list", exe);
eprintln!();
local_tz().unwrap_or(UTC)
local_tz().unwrap_or(time_zone::UTC)
};

let dt = DateTime::now(timezone)?;
let dt = now::in_tz(timezone)?;
let dow = match DOW.get(dt.week_day() as usize) {
Some(dow) => *dow,
None => unreachable!("Impossible week_day: {}", dt.week_day()),
Expand Down
31 changes: 23 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
//!
//! [![GitHub Workflow Status](https://img.shields.io/github/workflow/status/Kijewski/tzdb/CI?logo=github)](https://github.com/Kijewski/tzdb/actions/workflows/ci.yml)
//! [![Crates.io](https://img.shields.io/crates/v/tzdb?logo=rust)](https://crates.io/crates/tzdb)
//! ![Minimum supported Rust version](https://img.shields.io/badge/rustc-1.55+-important?logo=rust "Minimum Supported Rust Version")
//! ![Minimum supported Rust version](https://img.shields.io/badge/rustc-1.60+-important?logo=rust "Minimum Supported Rust Version")
//! [![License](https://img.shields.io/crates/l/tzdb?color=informational&logo=apache)](/LICENSES)
//!
//! Static time zone information for [tz-rs](https://crates.io/crates/tz-rs).
Expand All @@ -50,17 +50,27 @@
//!
//! ## Usage examples
//!
//! ```
//! # #[cfg(feature = "by-name")] let _: () = {
//! use tz::{DateTime, TimeZone};
//! use tzdb::{time_zone, tz_by_name};
//! ```rust
//! # #[cfg(all(feature = "local", feature = "now"))] let _: () = {
//! // get the system time zone
//! let time_zone = tzdb::local_tz().unwrap(); // tz::TimeZoneRef<'_>
//! let current_time = tzdb::now::local().unwrap(); // tz::DateTime
//!
//! // access by identifier
//! DateTime::now(time_zone::europe::KIEV);
//! let time_zone = tzdb::time_zone::europe::KIEV;
//! let current_time = tzdb::now::in_tz(tzdb::time_zone::europe::KIEV).unwrap();
//!
//! // access by name
//! DateTime::now(tz_by_name("Europe/Berlin").unwrap());
//! let time_zone = tzdb::tz_by_name("Europe/Berlin").unwrap();
//! let current_time = tzdb::now::in_named("Europe/Berlin").unwrap();
//!
//! // names are case insensitive
//! DateTime::now(tz_by_name("ArCtIc/LongYeArByEn").unwrap());
//! let time_zone = tzdb::tz_by_name("ArCtIc/LongYeArByEn").unwrap();
//! let current_time = tzdb::now::in_named("ArCtIc/LongYeArByEn").unwrap();
//!
//! // provide a default time zone
//! 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();
//! # };
//! ```
//!
Expand All @@ -72,6 +82,8 @@
//!
//! * `local` <sup>*(enabled by default)*</sup> — enables [`local_tz()`] to get the system time zone
//!
//! * `now` <sup>*(enabled by default)*</sup> — enables the module [`now`] to get the current time
//!
//! * `binary` — make the unparsed, binary tzdata of a time zone available
//!
//! * `std` <sup>*(enabled by default)*</sup> — enable features that need the standard library [`std`]
Expand All @@ -89,6 +101,9 @@ extern crate std;
mod generated;
#[cfg(feature = "by-name")]
mod lower;
#[cfg(feature = "now")]
#[cfg_attr(docsrs, doc(cfg(feature = "now")))]
pub mod now;
#[cfg(all(test, feature = "by-name"))]
mod test_by_name;
#[cfg(all(test, not(miri), feature = "by-name"))]
Expand Down
Loading

0 comments on commit ba88957

Please sign in to comment.