If you’re working with Ilias LMS you might run into this issue as well, so I’ll share this here.
We’re using SCORM 2004 with it’s cmi.comments_from_learner
but it turned out that it wasn’t possible to read a previously set timestamp
value during the next SCO visit. Did nobody ever read a timestamp
again? Anyway, since we strongly needed this functionality I had to figure out where the problem was. After making definitely sure it wasn’t our mistake I downloaded a fresh copy of the latest stable Ilias version (4.1.7) and tried to investigate how this system works.
A timestamp
value yyyy-mm-ddThh:mm:ss.msZ
was stored using MySQL datetime
and therefore read back as yyyy-mm-dd hh:mm:ss
. Time zone designator and 2 digits accuracy are SCORM 2004 optional, but the missing ‘T’ separator killed the data conversion.
So let’s have a look at the related original JavaScript function:
function setItemValue (key, dest, source, destkey) { if (source && source.hasOwnProperty(key)) { var d = source[key]; var temp=d; if (!isNaN(parseFloat(d)) && !(/[A-Za-z]/.test(d))) { d = Number(d); } else if (d==="true") { d = true; } else if (d==="false") { d = false; } //special handling for titles - no conversion if (key == "title") { d=temp; } dest[destkey ? destkey : key] = d; } }
And here is my temporary fix:
function setItemValue (key, dest, source, destkey) { if (source && source.hasOwnProperty(key)) { var d = String( source[key] ); if ( destkey === "timestamp" ) { // Fixed timestamp casting to NaN! // 26.09.2011 - derRaab - http://blog.derRaab.com // // a) No conversion // b) Ilias delivers date string without 'T': yyyy-mm-dd hh:mm:ss -> yyyy-mm-ddThh:mm:ss if ( d.length > 10 && d.charAt( 10 ) === " ") { d = d.split( " " ).join( "T" ); } } else if ( key === "title" ) { //special handling for titles - no conversion } else { // 26.09.2011 - derRaab - http://blog.derRaab.com // Use Number() instead of parseFloat() if (!isNaN(Number(d)) && !(/[A-Za-z]/.test(d))) { d = Number(d); } else if (d==="true") { d = true; } else if (d==="false") { d = false; } } dest[destkey ? destkey : key] = d; } }
Please note that I replaced the use of parseFloat()
with Number()
– I’m investigating another problem with the cmi.location characterstring
– but that’s fixed for now.
I reported these issues to the Ilias development team and they fixed at least the ‘T’ separator problem for Ilias 4.2.0:
http://www.ilias.de/mantis/view.php?id=7846
http://www.ilias.de/mantis/view.php?id=7847