From aa4a3d0d67ce3f44b2674b549500d83ba422ce25 Mon Sep 17 00:00:00 2001 From: senator Date: Wed, 4 Aug 2010 21:22:40 +0000 Subject: [PATCH] Provide a handy method for dojo-based interfaces to correctly show timestamps from fieldmapper object fields. git-svn-id: svn://svn.open-ils.org/ILS/trunk@17082 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/web/js/dojo/openils/Util.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Open-ILS/web/js/dojo/openils/Util.js b/Open-ILS/web/js/dojo/openils/Util.js index fd3a2d137..3e2547ae8 100644 --- a/Open-ILS/web/js/dojo/openils/Util.js +++ b/Open-ILS/web/js/dojo/openils/Util.js @@ -22,11 +22,33 @@ if(!dojo._hasResource["openils.Util"]) { dojo._hasResource["openils.Util"] = true; dojo.provide("openils.Util"); + dojo.require("dojo.date.locale"); + dojo.require("dojo.date.stamp"); dojo.require('openils.Event'); dojo.declare('openils.Util', null, {}); /** + * Returns a locale-appropriate representation of a timestamp when the + * timestamp (first argument) is actually a string as provided by + * fieldmapper objects. + * The second argument is an optional argument that will be provided + * as the second argument to dojo.date.locale.format() + */ + openils.Util.timeStamp = function(s, opts) { + 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 + ); + }; + + /** * Wrapper for dojo.addOnLoad that verifies a valid login session is active * before adding the function to the onload set */ -- 2.11.0