mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-08-02 14:07:46 +00:00
date: migrate winapi
to windows-sys
crate
This commit is contained in:
parent
b0b7565ba9
commit
ff30cacbe1
3 changed files with 10 additions and 13 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -2308,7 +2308,7 @@ dependencies = [
|
||||||
"clap 4.0.17",
|
"clap 4.0.17",
|
||||||
"libc",
|
"libc",
|
||||||
"uucore",
|
"uucore",
|
||||||
"winapi",
|
"windows-sys 0.42.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
|
@ -23,7 +23,7 @@ uucore = { version=">=0.0.16", package="uucore", path="../../uucore" }
|
||||||
libc = "0.2"
|
libc = "0.2"
|
||||||
|
|
||||||
[target.'cfg(windows)'.dependencies]
|
[target.'cfg(windows)'.dependencies]
|
||||||
winapi = { version = "0.3", features = ["minwinbase", "sysinfoapi", "minwindef"] }
|
windows-sys = { version = "0.42.0", default-features = false, features = ["Win32_Foundation", "Win32_System_SystemInformation"] }
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "date"
|
name = "date"
|
||||||
|
|
|
@ -23,10 +23,7 @@ use uucore::error::FromIo;
|
||||||
use uucore::error::{UResult, USimpleError};
|
use uucore::error::{UResult, USimpleError};
|
||||||
use uucore::{format_usage, show_error};
|
use uucore::{format_usage, show_error};
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
use winapi::{
|
use windows_sys::Win32::{Foundation::SYSTEMTIME, System::SystemInformation::SetSystemTime};
|
||||||
shared::minwindef::WORD,
|
|
||||||
um::{minwinbase::SYSTEMTIME, sysinfoapi::SetSystemTime},
|
|
||||||
};
|
|
||||||
|
|
||||||
// Options
|
// Options
|
||||||
const DATE: &str = "date";
|
const DATE: &str = "date";
|
||||||
|
@ -409,16 +406,16 @@ fn set_system_datetime(date: DateTime<Utc>) -> UResult<()> {
|
||||||
/// https://docs.microsoft.com/en-us/windows/win32/api/minwinbase/ns-minwinbase-systemtime
|
/// https://docs.microsoft.com/en-us/windows/win32/api/minwinbase/ns-minwinbase-systemtime
|
||||||
fn set_system_datetime(date: DateTime<Utc>) -> UResult<()> {
|
fn set_system_datetime(date: DateTime<Utc>) -> UResult<()> {
|
||||||
let system_time = SYSTEMTIME {
|
let system_time = SYSTEMTIME {
|
||||||
wYear: date.year() as WORD,
|
wYear: date.year() as u16,
|
||||||
wMonth: date.month() as WORD,
|
wMonth: date.month() as u16,
|
||||||
// Ignored
|
// Ignored
|
||||||
wDayOfWeek: 0,
|
wDayOfWeek: 0,
|
||||||
wDay: date.day() as WORD,
|
wDay: date.day() as u16,
|
||||||
wHour: date.hour() as WORD,
|
wHour: date.hour() as u16,
|
||||||
wMinute: date.minute() as WORD,
|
wMinute: date.minute() as u16,
|
||||||
wSecond: date.second() as WORD,
|
wSecond: date.second() as u16,
|
||||||
// TODO: be careful of leap seconds - valid range is [0, 999] - how to handle?
|
// TODO: be careful of leap seconds - valid range is [0, 999] - how to handle?
|
||||||
wMilliseconds: ((date.nanosecond() / 1_000_000) % 1000) as WORD,
|
wMilliseconds: ((date.nanosecond() / 1_000_000) % 1000) as u16,
|
||||||
};
|
};
|
||||||
|
|
||||||
let result = unsafe { SetSystemTime(&system_time) };
|
let result = unsafe { SetSystemTime(&system_time) };
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue