Make DATE_FORMAT macro check inputs
authorThomas Berezansky <tsbere@mvlc.org>
Thu, 19 May 2011 12:51:47 +0000 (08:51 -0400)
committerJason Etheridge <jason@esilibrary.com>
Thu, 19 May 2011 14:05:02 +0000 (10:05 -0400)
Specifically, if no date and no format (empty replaces?) replace with empty string.

Signed-off-by: Thomas Berezansky <tsbere@mvlc.org>
Signed-off-by: Jason Etheridge <jason@esilibrary.com>
Open-ILS/xul/staff_client/chrome/content/util/print.js

index 8c571c5..28d78f9 100644 (file)
@@ -305,9 +305,13 @@ util.print.prototype = {
             // Date Format
             try {
                 var match;
-                var date_format_patt=/%DATE_FORMAT\(([^,]*),([^)]*)\)%/
-                while(match = date_format_patt.exec(s))
-                    s = s.replace(match[0], util.date.formatted_date(match[1], match[2]));
+                var date_format_patt=/%DATE_FORMAT\(\s*([^,]*?)\s*,\s*([^)]*?)\s*\)%/
+                while(match = date_format_patt.exec(s)) {
+                    if(match[1] == '' || match[2] == '')
+                        s = s.replace(match[0], '');
+                    else
+                        s = s.replace(match[0], util.date.formatted_date(match[1], match[2]));
+                }
             } catch(E) { dump(E+'\n'); }
 
             // Substrings