Provide a handy method for dojo-based interfaces to correctly show timestamps
authorsenator <senator@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 4 Aug 2010 21:22:40 +0000 (21:22 +0000)
committersenator <senator@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 4 Aug 2010 21:22:40 +0000 (21:22 +0000)
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

index fd3a2d1..3e2547a 100644 (file)
 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
      */