Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support filtering timezone names by regex #69

Merged
merged 4 commits into from
Oct 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 38 additions & 8 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,15 @@ jobs:
git submodule sync --recursive
git -c "http.extraheader=$auth_header" -c protocol.version=2 \
submodule update --init --force --recursive --depth=1

- name: clippy
if: ${{ matrix.run_lint }}
run: cargo clippy --color=always
- name: rustfmt
if: ${{ matrix.run_lint }}
run: cargo fmt -- --color=always --check

- name: Run tests
run: cargo test --color=always -- --color=always

- name: Run tests serde
run: cargo test --features serde --color=always -- --color=always

- name: Run regex tests
run: bin/test-regex-filtering.sh

- name: Check with no default features
run: cargo check --no-default-features --color=always

Expand All @@ -64,3 +61,36 @@ jobs:
run: |
cargo clean
cargo build --features serde1

lint:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Checkout submodules
shell: bash
run: |
auth_header="$(git config --local --get http.https://github.com/.extraheader)"
git submodule sync --recursive
git -c "http.extraheader=$auth_header" -c protocol.version=2 \
submodule update --init --force --recursive --depth=1

- name: clippy
run: cargo clippy --color=always

- name: rustfmt
run: cargo fmt -- --color=always --check

# chrono-tz-build

- name: clippy chrono-tz-build
working-directory: ./chrono-tz-build
run: cargo clippy --color=always

- name: clippy chrono-tz-build filter-by-regex
working-directory: ./chrono-tz-build
run: cargo clippy --features filter-by-regex --color=always

- name: rustfmt
working-directory: ./chrono-tz-build
run: cargo fmt -- --color=always --check
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Chrono-tz Changelog
===================

## 0.6.0

* **tzdb** [breaking change] Update tzdb to 2020b, which removes the `US/Pacific-New` timezone.
https://github.com/eggert/tz/commit/284e877d7511d964249ecfd2e75a9cab85e2741a

* **feature** Add support for filtering the set of timezones with a new `filter-by-regex` feature
which uses `CHRONO_TZ_TIMEZONE_FILTER` env var. It should be set to a regular expression of
timezones to include.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ serde = { version = "1", optional = true, default-features = false }
[features]
default = ["std"]
std = []
filter-by-regex = ["chrono-tz-build/filter-by-regex"]

[build-dependencies]
parse-zoneinfo = { version = "0.3" }
chrono-tz-build = { path = "./chrono-tz-build", version = "0.0.1" }

[dev-dependencies]
serde_test = "1"
Expand Down
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ assert_eq!(utc.to_string(), "2016-10-21 23:00:00 UTC");

To use this library without depending on the Rust standard library, put this
in your `Cargo.toml`:

```toml
[dependencies]
chrono = { version = "0.4", default-features = false }
Expand All @@ -160,6 +161,32 @@ lto = true
Otherwise, the additional binary size added by this library may overflow
available program space and trigger a linker error.

## Limiting the Timezone Table to Zones of Interest

`Chrono-tz` by default generates timezones for all entries in the [IANA database][]. If you are
interested in only a few timezones you can use enable the `filter-by-regex` feature and set an
environment variable to select them. The environment variable is called
`CHRONO_TZ_TIMEZONE_FILTER` and is a regular expression. It should be specified in your top-level
build:

```toml
[dependencies]
chrono-tz = { version = "0.6", features = [ "filter-by-regex" ] }
```

```sh
CHRONO_TZ_TIMEZONE_FILTER="(Europe/London|US/.*)" cargo build
```

This can significantly reduce the size of the generated database, depending on how many timezones
you are interested in. Wikipedia has an [article listing the timezone names][wiki-list].

The filtering applied is liberal; if you use a pattern such as "US/.*" then `chrono-tz` will
include all the zones that are linked, such as "America/Denver", not just "US/Mountain".

[IANA database]: http://www.iana.org/time-zones
[wiki-list]: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones

## Future Improvements

- Handle leap seconds
Expand Down
10 changes: 10 additions & 0 deletions bin/test-regex-filtering.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

set -euxo pipefail

export RUST_BACKTRACE=1
export CHRONO_TZ_TIMEZONE_FILTER='(Europe/London|GMT)'

cd tests/check-regex-filtering

cargo test --color=always -- --color=always
Loading