Q: When passed a string with seconds, for example "12:23:34", StringToDateFrame
and StringToTime
don't seem to work. StringToDateFrame
returns a frame with NIL for all the time & day slots, and StringToTime
returns NIL.
A: To correctly handle strings with seconds, seconds must be stripped from the string. If the application might be used outside the US, check for the Locale time delimiter. Here is a function which prepares a string for StringToDateFrame
and StringToTime
:
PrepareStringForDateTime := func (str)
begin // str is just a time string, nothing else belongs
local newStr := clone (str);
local tf:= GetLocale().timeFormat;
local startMin := StrPos (str, tf.timeSepStr1, 0);
local startSec := StrPos (str, tf.timeSepStr2, startMin+1);
// If a time seperator for seconds, then strip out seconds
if startSec then
begin
local skipSecSep := startSec + StrLen (tf.timeSepStr2);
local remainderStr := SubStr (
str, skipSecSep, StrLen (str) - skipSecSep);
local appendStr := StringFilter (
remainderStr, "1234567890", 'rejectBeginning);
newStr := SubStr (str, 0, startSec) & appendStr;
end;
return newStr;
end;