Skip to content

Commit

Permalink
sys/unix: cache time zone info
Browse files Browse the repository at this point in the history
Bump MSRV to 1.36 for once_cell.
  • Loading branch information
djc committed Apr 12, 2022
1 parent 16d50c1 commit 7ff77d0
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 17 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/test-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ jobs:
- os: ubuntu-latest
rust_version: nightly
- os: ubuntu-18.04
rust_version: 1.32.0
rust_version: 1.36.0
- os: macos-latest
rust_version: 1.32.0
rust_version: 1.36.0
- os: windows-latest
rust_version: 1.32.0
rust_version: 1.36.0

runs-on: ${{ matrix.os }}

Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ jobs:
- os: ubuntu-latest
rust_version: nightly
- os: ubuntu-18.04
rust_version: 1.32.0
rust_version: 1.36.0
- os: macos-latest
rust_version: 1.32.0
rust_version: 1.36.0
- os: windows-latest
rust_version: 1.32.0
rust_version: 1.36.0

runs-on: ${{ matrix.os }}

Expand Down
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ js-sys = { version = "0.3", optional = true } # contains FFI bindings for the JS
[target.'cfg(windows)'.dependencies]
winapi = { version = "0.3.0", features = ["std", "minwinbase", "minwindef", "timezoneapi"], optional = true }

[target.'cfg(unix)'.dependencies]
once_cell = { version = "1.10", default-features = false, features = ["std"] }

[dev-dependencies]
serde_json = { version = "1" }
serde_derive = { version = "1", default-features = false }
Expand Down
12 changes: 6 additions & 6 deletions ci/github.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ source "${BASH_SOURCE[0]%/*}/_shlib.sh"
TEST_TZS=(ACST-9:30 EST4 UTC0 Asia/Katmandu)
FEATURES=(std serde clock "alloc serde" unstable-locales)
CHECK_FEATURES=(alloc "std unstable-locales" "serde clock" "clock unstable-locales")
RUST_132_FEATURES=(rustc-serialize serde)
RUST_136_FEATURES=(rustc-serialize serde)

main() {
if [[ "$*" =~ "-h" ]]; then
Expand All @@ -29,7 +29,7 @@ meaningful in the github actions feature matrix UI.

runv cargo --version

if [[ ${RUST_VERSION:-} != 1.32.0 ]]; then
if [[ ${RUST_VERSION:-} != 1.36.0 ]]; then
if [[ ${WASM:-} == yes_wasm ]]; then
test_wasm
elif [[ ${WASM:-} == wasm_simple ]]; then
Expand All @@ -45,8 +45,8 @@ meaningful in the github actions feature matrix UI.
else
test_regular UTC0
fi
elif [[ ${RUST_VERSION:-} == 1.32.0 ]]; then
test_132
elif [[ ${RUST_VERSION:-} == 1.36.0 ]]; then
test_136
else
echo "ERROR: didn't run any tests"
exit 1
Expand Down Expand Up @@ -76,9 +76,9 @@ check_combinatoric() {
done
}

test_132() {
test_136() {
runv cargo build --color=always
for feature in "${RUST_132_FEATURES[@]}"; do
for feature in "${RUST_136_FEATURES[@]}"; do
runt cargo build --features "$feature" --color=always
done
}
Expand Down
11 changes: 6 additions & 5 deletions src/offset/sys/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use once_cell::sync::Lazy;

use super::{DateTime, FixedOffset, Local, NaiveDateTime};
use crate::offset::tz_info::TimeZone;
use crate::Utc;
Expand All @@ -28,10 +30,9 @@ pub(super) fn naive_to_local(d: &NaiveDateTime, local: bool) -> DateTime<Local>

fn offset(unix: i64) -> FixedOffset {
FixedOffset::east(
TimeZone::local()
.expect("unable to parse localtime info")
.find_local_time_type(unix)
.expect("unable to select local time type")
.offset(),
INFO.find_local_time_type(unix).expect("unable to select local time type").offset(),
)
}

static INFO: Lazy<TimeZone> =
Lazy::new(|| TimeZone::local().expect("unable to parse localtime info"));

0 comments on commit 7ff77d0

Please sign in to comment.