Author: bklaas
Date: Mon Feb 25 07:42:08 2008
New Revision: 2020
URL: http://svn.slimdevices.com?rev=2020&root=Jive&view=rev
Log:
Bug: 5795
Description: Support for entering time values when SBC is set to 12h time format
Modified:
trunk/jive/src/pkg/jive/share/applets/SlimBrowser/SlimBrowserApplet.lua
trunk/jive/src/pkg/jive/share/jive/ui/Textinput.lua
trunk/jive/src/pkg/jive/share/jive/utils/datetime.lua
Modified:
trunk/jive/src/pkg/jive/share/applets/SlimBrowser/SlimBrowserApplet.lua
URL:
http://svn.slimdevices.com/trunk/jive/src/pkg/jive/share/applets/SlimBrowser/SlimBrowserApplet.lua?rev=2020&root=Jive&r1=2019&r2=2020&view=diff
==============================================================================
--- trunk/jive/src/pkg/jive/share/applets/SlimBrowser/SlimBrowserApplet.lua
(original)
+++ trunk/jive/src/pkg/jive/share/applets/SlimBrowser/SlimBrowserApplet.lua Mon
Feb 25 07:42:08 2008
@@ -346,6 +346,17 @@
end
end
+-- _getTimeFormat
+-- loads SetupDateTime and returns current setting for date time format
+local function _getTimeFormat()
+ local SetupDateTime = AppletManager:loadApplet("SetupDateTime")
+ local format = '12'
+ if SetupDateTime and SetupDateTime:getSettings()['hours'] then
+ format = SetupDateTime:getSettings()['hours']
+ end
+ AppletManager:freeApplet("SetupDateTime")
+ return format
+end
-- _checkboxItem
-- returns a checkbox button for use on a given item
@@ -1580,16 +1591,19 @@
local v = ""
local initialText = _safeDeref(item, 'input', 'initialText')
local inputStyle = _safeDeref(item, 'input', '_inputStyle')
+
if initialText then
v = tostring(initialText)
- if inputStyle == 'time' then
- local _v = DateTime:timeFromSFM(v)
- v = Textinput.timeValue(_v)
- end
- else
- if inputStyle == 'time' then
- v = Textinput.timeValue("00:00")
- end
+ end
+
+ if inputStyle == 'time' then
+ if not initialText then
+ initialText = '0'
+ end
+ local timeFormat = _getTimeFormat()
+ log:warn('DATETIME FORMAT RETURNED AS ', timeFormat)
+ local _v = DateTime:timeFromSFM(v, timeFormat)
+ v = Textinput.timeValue(_v, timeFormat)
end
-- create a text input
Modified: trunk/jive/src/pkg/jive/share/jive/ui/Textinput.lua
URL:
http://svn.slimdevices.com/trunk/jive/src/pkg/jive/share/jive/ui/Textinput.lua?rev=2020&root=Jive&r1=2019&r2=2020&view=diff
==============================================================================
--- trunk/jive/src/pkg/jive/share/jive/ui/Textinput.lua (original)
+++ trunk/jive/src/pkg/jive/share/jive/ui/Textinput.lua Mon Feb 25 07:42:08 2008
@@ -12,6 +12,7 @@
local table = require("jive.utils.table")
local log = require("jive.utils.log").logger("ui")
local locale = require("jive.utils.locale")
+local debug = require("jive.utils.debug")
local EVENT_ALL = jive.ui.EVENT_ALL
local EVENT_UNUSED = jive.ui.EVENT_UNUSED
@@ -416,9 +417,96 @@
=cut
--]]
-function timeValue(default)
+function timeValue(default, format)
local obj = {}
- setmetatable(obj, {
+ if not format then
+ format = '24'
+ end
+ if tostring(format) == '12' then
+ setmetatable(obj, {
+ __tostring =
+ function(e)
+ if type(e) == 'table' and e[3] then
+ return e[1] .. ":" .. e[2] .. e[3]
+ else
+ return table.concat(e, ":")
+ end
+ end,
+
+ __index = {
+ setValue =
+ function(value, str)
+ local i = 1
+ for dd in string.gmatch(str,
"(%d+)") do
+ local n = tonumber(dd)
+ if n > 12 and i == 1
then
+ n = 0
+ end
+ value[i] =
string.format("%02d", n)
+ i = i + 1
+ if i > 2 then
+ break
+ end
+ end
+ local ampm = string.match(str,
"[ap]", i)
+ value[i] = ampm
+ end,
+ getValue =
+ function(value)
+ -- remove leading zeros
+ local norm = {}
+ for i,v in ipairs(value) do
+ if type(v) == 'number'
then
+ norm[i] =
tostring(tonumber(v))
+ elseif type(v) ==
'string' then
+ norm[i] = v
+ end
+ end
+ return norm[1] .. ":" ..
norm[2] .. norm[3]
+ end,
+
+ getChars =
+ function(value, cursor)
+ if cursor == 7 then
+ return ""
+ end
+ local v =
tonumber(value[math.floor(cursor/3)+1])
+ if cursor == 1 then
+ -- first char can only
be 1 if hour is 10
+ if v == 10 then
+ return "1"
+ -- first char can be 0
or 1 if hour is 1,2,11,or 12
+ elseif v < 3 or v > 10
then
+ return "01"
+ -- hour 3-9 only allows
first num in hour to be 0
+ else
+ return "0"
+ end
+ elseif cursor == 2 then
+ if v > 9 then
+ return "012"
+ else
+ return
"123456789"
+ end
+ elseif cursor == 3 then
+ return ""
+ elseif cursor == 4 then
+ return "012345"
+ elseif cursor == 5 then
+ return "0123456789"
+ elseif cursor == 6 then
+ return "ap"
+ end
+ end,
+
+ isValid =
+ function(value, cursor)
+ return #value == 3
+ end
+ }
+ })
+ else
+ setmetatable(obj, {
__tostring =
function(e)
return table.concat(e, ":")
@@ -474,6 +562,7 @@
end
}
})
+ end
if default then
obj:setValue(default)
Modified: trunk/jive/src/pkg/jive/share/jive/utils/datetime.lua
URL:
http://svn.slimdevices.com/trunk/jive/src/pkg/jive/share/jive/utils/datetime.lua?rev=2020&root=Jive&r1=2019&r2=2020&view=diff
==============================================================================
--- trunk/jive/src/pkg/jive/share/jive/utils/datetime.lua (original)
+++ trunk/jive/src/pkg/jive/share/jive/utils/datetime.lua Mon Feb 25 07:42:08
2008
@@ -292,18 +292,49 @@
=cut
--]]
-function timeFromSFM(self, secondsFromMidnight)
+function timeFromSFM(self, secondsFromMidnight, format)
+
+ if not format then
+ format = '24'
+ end
local sfm = tonumber(secondsFromMidnight)
- if (sfm >= 86400 or sfm < 0) then
- return "00:00"
- end
-
- local hours = tonumber(math.floor(sfm/3600))
- local minutes = tonumber(math.floor((sfm % 3600) / 60 ))
-
- local formattedTime = string.format("%02d:%02d", hours, minutes)
- return formattedTime
+ -- 24h format
+ if format == '24' then
+ if (sfm >= 86400 or sfm < 0) then
+ return "00:00"
+ end
+
+ local hours = tonumber(math.floor(sfm/3600))
+ local minutes = tonumber(math.floor((sfm % 3600) / 60 ))
+
+ local formattedTime = string.format("%02d:%02d", hours, minutes)
+ return formattedTime
+ -- 12h format
+ else
+ local ampm
+ if (sfm >= 86400 or sfm < 0) then
+ return "12:00a"
+ end
+
+ if (sfm < 43200) then
+ ampm = 'a'
+ else
+ ampm = 'p'
+ end
+
+ local hours = tonumber(math.floor(sfm/3600))
+ local minutes = tonumber(math.floor((sfm % 3600) / 60 ))
+
+ if hours < 1 then
+ hours = 12
+ elseif hours > 12 then
+ hours = hours - 12
+ end
+
+ local formattedTime = string.format("%02d:%02d%s", hours,
minutes, ampm)
+ return formattedTime
+ end
end
--[[
_______________________________________________
Jive-checkins mailing list
[email protected]
http://lists.slimdevices.com/cgi-bin/mailman/listinfo/jive-checkins