-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdatetime.lua
91 lines (76 loc) · 1.78 KB
/
datetime.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
local ui = require'lui'
local dtboth, dtdate, dttime
local function timeFormat(d)
local fmt
if (d == dtboth) then
fmt = "%c"
elseif (d == dtdate) then
fmt = "%x"
elseif (d == dttime) then
fmt = "%X"
else
fmt = "%c"
end
return fmt
end
local function onChanged(d, l)
local tm = d:Time()
local s = os.time(tm)
s = os.date(timeFormat(d), s)
l:Text(s)
end
local function onClicked(b, data)
if (data) then data = os.time() end
local tm = os.date(data)
dtdate:SetTime(tm)
dttime:SetTime(tm)
end
function onClosing(w, data)
ui.Quit()
return 1
end
function main()
local err, w, g, l, b
ui.Init()
w = ui.NewWindow("Date / Time", 320, 240, false):Margined(true)
g = ui:NewGrid():Padded(true)
w:SetChild(g)
--[[
dtboth = ui.NewDateTimePicker()
dtdate = ui.NewDatePicker()
dttime = ui.NewTimePicker()
g:Append(dtboth, 0, 0, 2, 0, true, ui.AlignFill, false, ui.AlignFill)
g:Append(dtdate, 0, 1, 1, 1, true, ui.AlignFill, false, ui.AlignFill)
g:Append(dttime, 1, 1, 1, 1, true, ui.AlignFill, false, ui.AlignFill)
l = ui.NewLabel("")
g:Append(l,
0, 2, 2, 1,
true, ui.AlignFill, false, ui.AlignFill)
dtboth:OnChanged(onChanged, l)
l = ui.NewLabel("")
g:Append(l,
0, 3, 1, 1,
true, ui.AlignCenter, false, ui.AlignFill)
dtdate:OnChanged(onChanged, l)
l = ui.NewLabel("")
g:Append(l,
1, 3, 1, 1,
true, ui.AlignCenter, false, ui.AlignFill)
dttime:OnChanged(onChanged, l)
b = ui.NewButton("Now")
b:OnClicked(onClicked, 1)
g:Append(b,
0, 4, 1, 1,
true, ui.AlignFill, true, ui.AlignEnd)
b = ui.NewButton("Unix epoch")
b:OnClicked(onClicked, 0)
g:Append(b,
1, 4, 1, 1,
true, ui.AlignFill, true, ui.AlignEnd)
--]]
w:OnClosing(onClosing):Show()
ui.Main()
ui.Uninit()
return 0
end
main()