Skip to content

Commit

Permalink
Replace winapi with windows-sys
Browse files Browse the repository at this point in the history
  • Loading branch information
hotate29 authored and djc committed Nov 28, 2022
1 parent 95532db commit 74ca661
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ jobs:
toolchain: 1.48.0
- uses: Swatinem/rust-cache@v1
# run --lib and --doc to avoid the long running integration tests which are run elsewhere
- run: cargo test --lib --features unstable-locales,wasmbind,clock,serde,winapi --color=always -- --color=always
- run: cargo test --doc --features unstable-locales,wasmbind,clock,serde,winapi --color=always -- --color=always
- run: cargo test --lib --features unstable-locales,wasmbind,clock,serde,windows-sys --color=always -- --color=always
- run: cargo test --doc --features unstable-locales,wasmbind,clock,serde,windows-sys --color=always -- --color=always

rust_versions:
strategy:
Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ default = ["clock", "std", "wasmbind"]
alloc = []
libc = []
std = []
clock = ["std", "winapi", "iana-time-zone"]
clock = ["std", "windows-sys", "iana-time-zone"]
wasmbind = ["wasm-bindgen", "js-sys"]
unstable-locales = ["pure-rust-locales", "alloc"]
__internal_bench = ["criterion"]
Expand All @@ -40,7 +40,7 @@ wasm-bindgen = { version = "0.2", optional = true }
js-sys = { version = "0.3", optional = true } # contains FFI bindings for the JS Date API

[target.'cfg(windows)'.dependencies]
winapi = { version = "0.3.0", features = ["std", "minwinbase", "minwindef", "timezoneapi"], optional = true }
windows-sys = { version = "0.42.0", features = ["Win32_System_Time", "Win32_Foundation"], optional = true }

[dev-dependencies]
serde_json = { version = "1" }
Expand Down
26 changes: 15 additions & 11 deletions src/offset/local/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@ use std::mem;
use std::ptr;
use std::time::{SystemTime, UNIX_EPOCH};

use winapi::shared::minwindef::*;
use winapi::um::minwinbase::SYSTEMTIME;
use winapi::um::timezoneapi::*;
use windows_sys::Win32::Foundation::FILETIME;
use windows_sys::Win32::Foundation::SYSTEMTIME;
use windows_sys::Win32::System::Time::FileTimeToSystemTime;
use windows_sys::Win32::System::Time::GetTimeZoneInformation;
use windows_sys::Win32::System::Time::SystemTimeToFileTime;
use windows_sys::Win32::System::Time::SystemTimeToTzSpecificLocalTime;
use windows_sys::Win32::System::Time::TzSpecificLocalTimeToSystemTime;

use super::{FixedOffset, Local};
use crate::{DateTime, Datelike, LocalResult, NaiveDate, NaiveDateTime, NaiveTime, Timelike};
Expand Down Expand Up @@ -177,7 +181,7 @@ const HECTONANOSEC_TO_UNIX_EPOCH: i64 = 11_644_473_600 * HECTONANOSECS_IN_SEC;

fn time_to_file_time(sec: i64) -> FILETIME {
let t = ((sec * HECTONANOSECS_IN_SEC) + HECTONANOSEC_TO_UNIX_EPOCH) as u64;
FILETIME { dwLowDateTime: t as DWORD, dwHighDateTime: (t >> 32) as DWORD }
FILETIME { dwLowDateTime: t as u32, dwHighDateTime: (t >> 32) as u32 }
}

fn file_time_as_u64(ft: &FILETIME) -> u64 {
Expand All @@ -199,13 +203,13 @@ fn system_time_to_file_time(sys: &SYSTEMTIME) -> FILETIME {

fn tm_to_system_time(tm: &Tm) -> SYSTEMTIME {
let mut sys: SYSTEMTIME = unsafe { mem::zeroed() };
sys.wSecond = tm.tm_sec as WORD;
sys.wMinute = tm.tm_min as WORD;
sys.wHour = tm.tm_hour as WORD;
sys.wDay = tm.tm_mday as WORD;
sys.wDayOfWeek = tm.tm_wday as WORD;
sys.wMonth = (tm.tm_mon + 1) as WORD;
sys.wYear = (tm.tm_year + 1900) as WORD;
sys.wSecond = tm.tm_sec as u16;
sys.wMinute = tm.tm_min as u16;
sys.wHour = tm.tm_hour as u16;
sys.wDay = tm.tm_mday as u16;
sys.wDayOfWeek = tm.tm_wday as u16;
sys.wMonth = (tm.tm_mon + 1) as u16;
sys.wYear = (tm.tm_year + 1900) as u16;
sys
}

Expand Down

0 comments on commit 74ca661

Please sign in to comment.