[Xsltforms-support] correction to previous datetime change suggestions
Brought to you by:
alain-couthures
From: Stephen C. <Ste...@ut...> - 2009-09-27 12:54:08
|
My previous changes (see below) broke the datetime validation. The following single change seem to do the trick though. "dateTime" : { "patterns" : [ "^([12][0-9]{3})-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])T([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9](\\.[0-9]+)?(Z|[+-]([01][0-9]|2[0-3]):[0-5][0-9])?$" ], "class" : "datetime", "displayLength" : 20, "format" : function(value) { //SC return I8N.format(I8N.parse(value, "yyyy-MM-ddThh:mm:ss")); return I8N.format(I8N.parse(value, "yyyy-MM-ddThh:mm:ss"),null,true); }, "parse" : function(value) { return I8N.format(I8N.parse(value), "yyyy-MM-ddThh:mm:ss"); } }, -------- Original Message -------- Subject: datetime change suggestions Date: Wed, 23 Sep 2009 20:39:46 +1000 From: Stephen Cameron <ste...@ut...> To: COUTHURES Alain <ala...@ag...>, xsl...@li... Hello Alain, I am back after a couple of weeks holiday. I have been looking at my datetime format problems today and have some change suggestions to make. It seems to be working now for me at least, but I am not sure of the implications of the changes. The changes are in two places but both relate to the use of the I8N.format function. This is as follows unchanged: format : function(date, pattern, loc) { if (!date) { return ""; } if (!pattern) { pattern = I8N.get("format.datetime"); } var str = I8N._format(pattern, date.getDate(), "dd"); str = I8N._format(str, (loc ? date.getMonth() : date.getUTCMonth()) + 1, "MM"); y = (loc ? date.getFullYear() : date.getUTCFullYear()); str = I8N._format(str, y < 1000? 1900 + y : y, "yyyy"); str = I8N._format(str, (loc ? date.getSeconds() : date.getUTCSeconds()), "ss"); str = I8N._format(str, (loc ? date.getMinutes() : date.getUTCMinutes()), "mm"); str = I8N._format(str, (loc ? date.getHours() : date.getUTCHours()), "hh"); o = date.getTimezoneOffset(); str = I8N._format(str, (loc ? (o < 0 ? "+" : "-")+zeros(Math.floor(Math.abs(o)/60),2)+":"+zeros(Math.abs(o) % 60,2) : "Z"), "zz"); return str; }, The "loc" parameter should by rights be boolean and determines if the time is local or not, if it is false or null then as you can see the UTC functions get called. In my case this subtracts 10 hours from the date that I entered. There is no adjustment for timezone made, probably as I don't have a timezone (zz) in my date format string. In general I want to the date entered to be considered a local time. Changes are as follows with my initials SC: 1. In the TypeDefs.Default object on about line 4731: "dateTime" : { "patterns" : [ "^([12][0-9]{3})-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])T([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9](\\.[0-9]+)?(Z|[+-]([01][0-9]|2[0-3]):[0-5][0-9])?$" ], "class" : "datetime", "displayLength" : 20, "format" : function(value) { //SC return I8N.format(I8N.parse(value, "yyyy-MM-ddThh:mm:ss")); return I8N.format(value, null, true); }, "parse" : function(value) { //SC return I8N.format(I8N.parse(value), "yyyy-MM-ddThh:mm:ss"); return I8N.parse(value); } }, These force the datetime pattern to be taken from the messages.properties file and for the time to be considered local. 2. In the Calendar 'handler' function starting on about line 4042: if (cal.isTimestamp) { //SC added next line, not sure why it should be missing?? date.setSeconds(cal.inputSec.value); date.setMinutes(cal.inputMin.value); date.setHours(cal.inputHour.value); //SC cal.input.value = I8N.format(date); cal.input.value = I8N.format(date,null,true); } else { cal.input.value = I8N.formatDate(date); } I've not checked changed any of the date parse/format functions but these need checking as well. Maybe I have missed some essential point and these changes aren't needed (but probably not). Cheers Steve Cameron -- Regards Stephen Cameron Data Programmer Integrated Marine Observing System (IMOS) eMarine Information Infrastructure Project University of Tasmania, Private Bag 21, Hobart, TAS 7001, Australia Tel: +61 3 6226 8507 Fax: +61 3 6226 2997 Email: ste...@ut... URL: http://www.imos.org.au/eMII.html -- Regards Stephen Cameron Data Programmer Integrated Marine Observing System (IMOS) eMarine Information Infrastructure Project University of Tasmania, Private Bag 21, Hobart, TAS 7001, Australia Tel: +61 3 6226 8507 Fax: +61 3 6226 2997 Email: ste...@ut... URL: http://www.imos.org.au/eMII.html |