Install a moduli(5) manual page.
[dragonfly.git] / contrib / bsdinstaller-1.1.6 / src / backend / lua / configure / menu / 350_set_datetime.lua
1 -- $Id: 350_set_datetime.lua,v 1.2 2005/02/24 23:08:03 cpressey Exp $
2
3 require "gettext"
4
5 local set_datetime = function()
6         local cmds, date_tab, form, response
7
8         date_tab = os.date("*t")
9
10         form = {
11             id = "set_datetime",
12             name = _("Set Time and Date"),
13             short_desc = _(
14                 "Enter the current date and time of day to set " ..
15                 "this computer's internal timekeeping clock."
16             ),
17
18             fields = {
19                 {
20                     id = "year",
21                     name = _("Year"),
22                     short_desc = _("Enter the current year (e.g. `2004')")
23                 },
24                 {
25                     id = "month",
26                     name = _("Month"),
27                     short_desc = _("Enter the current month (e.g. `07')")
28                 },
29                 {
30                     id = "day",
31                     name = _("Day"),
32                     short_desc = _("Enter the current day of month (e.g. `30')")
33                 },
34                 {
35                     id = "hour",
36                     name = _("Hour"),
37                     short_desc = _("Enter the current hour (e.g. `07')")
38                 },
39                 {
40                     id = "min",
41                     name = _("Minute"),
42                     short_desc = _("Enter the current minute (e.g. `59')")
43                 }
44             },
45
46             datasets = {
47                 {
48                     year = tostring(date_tab.year),
49                     month = tostring(date_tab.month),
50                     day = tostring(date_tab.day),
51                     hour = tostring(date_tab.hour),
52                     min = tostring(date_tab.min)
53                 }
54             },
55
56             actions = {
57                 {
58                     id = "ok",
59                     name = _("OK")
60                 },
61                 {
62                     id = "cancel",
63                     name = _("Cancel")
64                 }
65             }
66         }
67
68         while not done do
69                 response = App.ui:present(form)
70                 if response.action_id ~= "ok" then
71                         return false
72                 end
73
74                 date_tab = {
75                     year = tonumber(response.datasets[1].year),
76                     month = tonumber(response.datasets[1].month),
77                     day = tonumber(response.datasets[1].day),
78                     hour = tonumber(response.datasets[1].hour),
79                     min = tonumber(response.datasets[1].min)
80                 }
81
82                 --
83                 -- Validate the given date and time.
84                 --
85
86                 if date_tab.year > 0 and 
87                    date_tab.month >= 1 and date_tab.month <= 12 and 
88                    date_tab.day >= 1 and date_tab.day <= 31 and 
89                    date_tab.hour >= 0 and date_tab.hour <= 23 and 
90                    date_tab.min >= 0 and date_tab.min <= 59 then
91
92                         cmds = CmdChain.new()
93                         cmds:add("${root}${DATE} -n " .. string.format(
94                             "%04d%02d%02d%02d%02d",
95                             date_tab.year,
96                             date_tab.month,
97                             date_tab.day,
98                             date_tab.hour,
99                             date_tab.min
100                         ))
101                         if cmds:execute() then
102                                 App.ui:inform(_(
103                                     "The time and date have successfully been set."
104                                 ))
105                                 done = true
106                         else
107                                 App.ui:inform(_(
108                                     "An error occurred while attempting to set " ..
109                                     "time and date."
110                                 ))
111                         end
112                 else
113                         App.ui:inform(_(
114                             "Please enter numbers within acceptable ranges " ..
115                             "for year, month, day of month, hour, and minute."
116                         ))
117                 end
118         end
119
120         return true
121 end
122
123 return {
124     name = _("Set Time and Date"),
125     effect = function()
126         set_datetime()
127         return Menu.CONTINUE
128     end
129 }