From 15ed7a85706f13eaba9a47eda6ecb109ecd28b22 Mon Sep 17 00:00:00 2001 From: senator Date: Fri, 3 Sep 2010 21:47:13 +0000 Subject: [PATCH] AutoFieldWidget now shows timestamps correctly. Timestamps used to be a little bit off because of Dojo's limited parsing of ISO6801 stamps. git-svn-id: svn://svn.open-ils.org/ILS/trunk@17491 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/web/js/dojo/openils/Util.js | 17 +++++++++++------ Open-ILS/web/js/dojo/openils/widget/AutoFieldWidget.js | 16 +++++++--------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/Open-ILS/web/js/dojo/openils/Util.js b/Open-ILS/web/js/dojo/openils/Util.js index a9da87bea..ebe5cc36c 100644 --- a/Open-ILS/web/js/dojo/openils/Util.js +++ b/Open-ILS/web/js/dojo/openils/Util.js @@ -28,6 +28,16 @@ if(!dojo._hasResource["openils.Util"]) { 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(!dojo._hasResource["openils.Util"]) { 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 ); }; diff --git a/Open-ILS/web/js/dojo/openils/widget/AutoFieldWidget.js b/Open-ILS/web/js/dojo/openils/widget/AutoFieldWidget.js index aeaaf0153..8c3a3cf80 100644 --- a/Open-ILS/web/js/dojo/openils/widget/AutoFieldWidget.js +++ b/Open-ILS/web/js/dojo/openils/widget/AutoFieldWidget.js @@ -151,10 +151,9 @@ if(!dojo._hasResource['openils.widget.AutoFieldWidget']) { } 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 @@ if(!dojo._hasResource['openils.widget.AutoFieldWidget']) { 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': -- 2.11.0