Commits

Matthew Schinckel committed 77949a0

Handle '%-d' style formatting codes (strip leading zeroes)

Comments (0)

Files changed (2)

examples/datepicker.html

                           weekStartDay: 'Sunday',
                           showWeekNumbers: true,
   												weekNumberTitle: 'Wk #',
-  												displayFormat: '%d %b, %Y',
+  												displayFormat: '%-d %b, %Y',
                           yearRange: 'c-5:c+5',
   												maxDate: '2015-01-01'
                         }">

src/js/dateExtras.js

     var result = "";
     
     for (var i=0, length=format.length; i < length; i++) {
+      var leading_zeros = true;
       if (format[i] !== "%") {
         result += format[i];
         continue;
       }
       
+      if (format[i+1] == '-') {
+        leading_zeros = false;
+        i++;
+      }
+      
       var pattern = codes[format[++i]];
       if (!pattern) {
         result += format[i];
       }
       
       var data = "" + pattern.apply(this);
-      if (data.length == 1) {
+      if (data.length == 1 && leading_zeros) {
         data = "0" + data;
       }
       result += data;