Skip to content

Commit ef71874

Browse files
Lyor Goldsteindblock
Lyor Goldstein
authored andcommitted
Added Kernel32#SetSystemTime.
1 parent 554d7a2 commit ef71874

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

CHANGES.md

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Features
1919
* [#350](https://github.com/twall/jna/pull/350): Added `jnacontrib.x11.api.X.Window.getSubwindows` - [@rm5248](https://github.com/rm5248).
2020
* Improved `contrib/msoffice` sample - [@wolftobias](https://github.com/wolftobias).
2121
* [#352](https://github.com/twall/jna/pull/352): Performance improvements due to reduced locking in `com.sun.jna.Library$Handler` and fewer vararg checks in `com.sun.jna.Function` - [@Boereck](https://github.com/Boereck).
22+
* [#357](https://github.com/twall/jna/pull/357): Added `com.sun.jna.platform.win32.Kernel32.SetSystemTime` - [@lgoldstein](https://github.com/lgoldstein), [@thomasjoulin](https://github.com/thomasjoulin).
2223

2324
Bug Fixes
2425
---------

contrib/platform/src/com/sun/jna/platform/win32/Kernel32.java

+14
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,20 @@ boolean ReadFile(HANDLE hFile, Buffer lpBuffer, int nNumberOfBytesToRead,
159159
*/
160160
void GetSystemTime(WinBase.SYSTEMTIME lpSystemTime);
161161

162+
/**
163+
* The SetSystemTime function modifies the current system date and time.
164+
* The system time is expressed in Coordinated Universal Time (UTC).
165+
*
166+
* @param lpSystemTime
167+
* Pointer to a SYSTEMTIME structure holding the new
168+
* system date and time. <B>Note:</B> The {@code wDayOfWeek}
169+
* member of the SYSTEMTIME structure is ignored.
170+
* @return {@code true} if the function succeeds, {@code false} otherwise.
171+
* If the function fails, call GetLastError to get extended error
172+
* information.
173+
*/
174+
boolean SetSystemTime(WinBase.SYSTEMTIME lpSystemTime);
175+
162176
/**
163177
* Retrieves the current local date and time.
164178
*

contrib/platform/test/com/sun/jna/platform/win32/Kernel32Test.java

+34
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,40 @@ public void testStructureOutArgument() {
7878
cal.get(Calendar.YEAR), time.wYear);
7979
}
8080

81+
public void testSetSystemTime() {
82+
Kernel32 kernel = Kernel32.INSTANCE;
83+
WinBase.SYSTEMTIME time = new WinBase.SYSTEMTIME();
84+
kernel.GetSystemTime(time);
85+
try {
86+
WinBase.SYSTEMTIME expected = new WinBase.SYSTEMTIME();
87+
expected.wYear = time.wYear;
88+
expected.wMonth = time.wMonth;
89+
expected.wDay = time.wDay;
90+
expected.wHour = time.wHour;
91+
expected.wMinute = time.wMinute;
92+
expected.wSecond = time.wSecond;
93+
expected.wMilliseconds = time.wMilliseconds;
94+
95+
if (expected.wHour > 0) {
96+
expected.wHour--;
97+
} else {
98+
expected.wHour++;
99+
}
100+
101+
if (!kernel.SetSystemTime(expected)) {
102+
fail("Failed to modify time: error=" + kernel.GetLastError());
103+
}
104+
105+
WinBase.SYSTEMTIME actual = new WinBase.SYSTEMTIME();
106+
kernel.GetSystemTime(actual);
107+
assertEquals("Mismatched hour value", expected.wHour, actual.wHour);
108+
} finally {
109+
if (!kernel.SetSystemTime(time)) {
110+
fail("Failed to restore original time: error=" + kernel.GetLastError());
111+
}
112+
}
113+
}
114+
81115
public void testGetLastError() {
82116
Kernel32 kernel = Kernel32.INSTANCE;
83117
int ERRCODE = 8;

0 commit comments

Comments
 (0)