Matthew Schinckel avatar 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;
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.