-
Notifications
You must be signed in to change notification settings - Fork 0
/
OsTime.lua
59 lines (49 loc) · 1.42 KB
/
OsTime.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
-- OsTime.lua by Rouneq
-- Provides methods to obtain either the local time or UTC time from the base Os at millisecond resolution
local ffi = require('ffi')
---@class SYSTEMTIME
---@field Year integer
---@field Month integer
---@field DayOfWeek integer
---@field Day integer
---@field Hour integer
---@field Minute integer
---@field Second integer
---@field Milliseconds integer
ffi.cdef[[
typedef unsigned short WORD;
typedef struct _SYSTEMTIME {
WORD Year;
WORD Month;
WORD DayOfWeek;
WORD Day;
WORD Hour;
WORD Minute;
WORD Second;
WORD Milliseconds;
} SYSTEMTIME, *PSYSTEMTIME, *LPSYSTEMTIME;
void GetLocalTime(
LPSYSTEMTIME lpSystemTime
);
void GetSystemTime(
LPSYSTEMTIME lpSystemTime
);
]]
--- Provides methods to obtain the time at millisecond resolution
---@class OsTime
OsTime = {}
--- Gets the local time from the operating system in millisecond resolution
---@return SYSTEMTIME
OsTime.GetLocalTime = function ()
local timestruct = ffi.new('SYSTEMTIME') --[[@as SYSTEMTIME]]
ffi.C.GetLocalTime(timestruct)
return timestruct
end
--- Gets the UTC time from the operating system in millisecond resolution
---@return SYSTEMTIME
OsTime.GetSystemTime = function ()
local timestruct = ffi.new('SYSTEMTIME') --[[@as SYSTEMTIME]]
ffi.C.GetSystemTime(timestruct)
return timestruct
end
return OsTime