[open-ils-commits] r17492 - in branches/rel_2_0/Open-ILS/web/js/dojo/openils: . widget (senator)

svn at svn.open-ils.org svn at svn.open-ils.org
Fri Sep 3 17:48:19 EDT 2010


Author: senator
Date: 2010-09-03 17:48:13 -0400 (Fri, 03 Sep 2010)
New Revision: 17492

Modified:
   branches/rel_2_0/Open-ILS/web/js/dojo/openils/Util.js
   branches/rel_2_0/Open-ILS/web/js/dojo/openils/widget/AutoFieldWidget.js
Log:
Backport r17491 from trunk: fix timestamps in AutoFieldWidget


Modified: branches/rel_2_0/Open-ILS/web/js/dojo/openils/Util.js
===================================================================
--- branches/rel_2_0/Open-ILS/web/js/dojo/openils/Util.js	2010-09-03 21:47:13 UTC (rev 17491)
+++ branches/rel_2_0/Open-ILS/web/js/dojo/openils/Util.js	2010-09-03 21:48:13 UTC (rev 17492)
@@ -28,6 +28,16 @@
     dojo.declare('openils.Util', null, {});
 
 
+    openils.Util.timeStampRegexp =
+        /^(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}[\+-]\d{2})(\d{2})$/;
+
+    openils.Util.timeStampAsDateObj = function(s) {
+        if (s.constructor.name == "Date") return s;
+        return dojo.date.stamp.fromISOString(
+            s.replace(openils.Util.timeStampRegexp, "$1:$2")
+        );
+    }
+
     /**
      * Returns a locale-appropriate representation of a timestamp when the
      * timestamp (first argument) is actually a string as provided by
@@ -39,12 +49,7 @@
         if (typeof(opts) == "undefined") opts = {};
 
         return dojo.date.locale.format(
-            dojo.date.stamp.fromISOString(
-                s.replace(
-                    /^(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}[\+-]\d{2})(\d{2})$/,
-                    "$1:$2"
-                )
-            ), opts
+            openils.Util.timeStampAsDateObj(s), opts
         );
     };
 

Modified: branches/rel_2_0/Open-ILS/web/js/dojo/openils/widget/AutoFieldWidget.js
===================================================================
--- branches/rel_2_0/Open-ILS/web/js/dojo/openils/widget/AutoFieldWidget.js	2010-09-03 21:47:13 UTC (rev 17491)
+++ branches/rel_2_0/Open-ILS/web/js/dojo/openils/widget/AutoFieldWidget.js	2010-09-03 21:48:13 UTC (rev 17492)
@@ -151,10 +151,9 @@
                     }
                 case 'timestamp':
                     if (!value) return '';
-                    dojo.require('dojo.date.locale');
-                    dojo.require('dojo.date.stamp');
-                    var date = dojo.date.stamp.fromISOString(value);
-                    return dojo.date.locale.format(date, {formatLength:'short'});
+                    return openils.Util.timeStamp(
+                        value, {"formatLength": "short"}
+                    );
                 case 'org_unit':
                     if(value === null || value === undefined) return '';
                     return fieldmapper.aou.findOrgUnit(value).shortname();
@@ -230,12 +229,11 @@
                         dojo.require('dijit.form.DateTextBox');
                         dojo.require('dojo.date.stamp');
                         this.widget = new dijit.form.DateTextBox(this.dijitArgs, this.parentNode);
-                        if(this.widgetValue != null) 
-                            this.widgetValue = dojo.date.stamp.fromISOString(
-                                // Kludge until the ML returning ISO timestamps with a colon in the timezone offset,
-                                // which dojo.date.stamp.fromISOString requires
-                                this.widgetValue.replace( /^(\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\d-\d\d)(\d\d)$/, '$1:$2') 
+                        if (this.widgetValue != null) {
+                            this.widgetValue = openils.Util.timeStampAsDateObj(
+                                this.widgetValue
                             );
+                        }
                         break;
 
                     case 'bool':



More information about the open-ils-commits mailing list