diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b32c9f47f4..708b6e50f4 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -149,6 +149,30 @@ jobs: RUST_VERSION: stable WASM: wasm_emscripten + wasm_unknown: + strategy: + matrix: + os: [ubuntu-latest] + + runs-on: ${{ matrix.os }} + + steps: + - uses: actions/checkout@v2 + + - name: Install rust + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + target: wasm32-unknown-unknown + override: true + default: true + + - name: Build and Test + run: bash ci/github.sh + env: + RUST_VERSION: stable + WASM: wasm_unknown + cross-targets: strategy: matrix: diff --git a/ci/github.sh b/ci/github.sh index 081a128b90..6512f9a7ee 100755 --- a/ci/github.sh +++ b/ci/github.sh @@ -36,6 +36,8 @@ meaningful in the github actions feature matrix UI. test_wasm_simple elif [[ ${WASM:-} == wasm_emscripten ]]; then test_wasm_emscripten + elif [[ ${WASM:-} == wasm_unknown ]]; then + test_wasm_unknown elif [[ ${CORE:-} == no_std ]]; then test_core elif [[ ${EXHAUSTIVE_TZ:-} == all_tzs ]]; then @@ -118,4 +120,8 @@ test_wasm_emscripten() { runt cargo build --target wasm32-unknown-emscripten } +test_wasm_unknown() { + runt cargo build --target wasm32-unknown-unknown +} + main "$@" diff --git a/src/offset/sys/stub.rs b/src/offset/sys/stub.rs new file mode 100644 index 0000000000..616b52fe5e --- /dev/null +++ b/src/offset/sys/stub.rs @@ -0,0 +1,80 @@ +// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +use super::Tm; + +fn time_to_tm(ts: i64, tm: &mut Tm) { + let leapyear = |year| -> bool { year % 4 == 0 && (year % 100 != 0 || year % 400 == 0) }; + + static YTAB: [[i64; 12]; 2] = [ + [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31], + [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31], + ]; + + let mut year = 1970; + + let dayclock = ts % 86400; + let mut dayno = ts / 86400; + + tm.tm_sec = (dayclock % 60) as i32; + tm.tm_min = ((dayclock % 3600) / 60) as i32; + tm.tm_hour = (dayclock / 3600) as i32; + tm.tm_wday = ((dayno + 4) % 7) as i32; + loop { + let yearsize = if leapyear(year) { 366 } else { 365 }; + if dayno >= yearsize { + dayno -= yearsize; + year += 1; + } else { + break; + } + } + tm.tm_year = (year - 1900) as i32; + tm.tm_yday = dayno as i32; + let mut mon = 0; + while dayno >= YTAB[if leapyear(year) { 1 } else { 0 }][mon] { + dayno -= YTAB[if leapyear(year) { 1 } else { 0 }][mon]; + mon += 1; + } + tm.tm_mon = mon as i32; + tm.tm_mday = dayno as i32 + 1; + tm.tm_isdst = 0; +} + +fn tm_to_time(tm: &Tm) -> i64 { + let mut y = tm.tm_year as i64 + 1900; + let mut m = tm.tm_mon as i64 + 1; + if m <= 2 { + y -= 1; + m += 12; + } + let d = tm.tm_mday as i64; + let h = tm.tm_hour as i64; + let mi = tm.tm_min as i64; + let s = tm.tm_sec as i64; + (365 * y + y / 4 - y / 100 + y / 400 + 3 * (m + 1) / 5 + 30 * m + d - 719561) * 86400 + + 3600 * h + + 60 * mi + + s +} + +pub(super) fn time_to_local_tm(sec: i64, tm: &mut Tm) { + // FIXME: Add timezone logic + time_to_tm(sec, tm); +} + +pub(super) fn utc_tm_to_time(tm: &Tm) -> i64 { + tm_to_time(tm) +} + +pub(super) fn local_tm_to_time(tm: &Tm) -> i64 { + // FIXME: Add timezone logic + tm_to_time(tm) +}