]> git.decadent.org.uk Git - ion3.git/blob - mod_statusbar/ion-statusd/statusd_date.lua
[svn-inject] Installing original source of ion3
[ion3.git] / mod_statusbar / ion-statusd / statusd_date.lua
1 --
2 -- ion/mod_statusbar/ion-statusd/statusd_date.lua
3 -- 
4 -- Copyright (c) Tuomo Valkonen 2004-2006.
5 --
6 -- Ion is free software; you can redistribute it and/or modify it under
7 -- the terms of the GNU Lesser General Public License as published by
8 -- the Free Software Foundation; either version 2.1 of the License, or
9 -- (at your option) any later version.
10 --
11
12
13 local timer
14
15 local defaults={
16     date_format='%a %Y-%m-%d %H:%M',
17     formats={},
18 }
19
20 local settings=table.join(statusd.get_config('date'), defaults)
21
22 local function update()
23     local tm=os.time()
24     statusd.inform('date', os.date(settings.date_format, tm))
25     for k, f in pairs(settings.formats) do
26         statusd.inform('date_'..k, os.date(f, tm))
27     end
28     return tm
29 end
30
31 local function timer_handler(tmr)
32     local tm=update()
33     
34     local t=os.date('*t', tm)
35     local d=(60-t.sec)*1000
36     
37     timer:set(d, timer_handler)
38 end
39
40 timer=statusd.create_timer()
41 timer_handler(timer)