diff --git a/API.txt b/API.txt index c4b557f..e7780ce 100644 --- a/API.txt +++ b/API.txt @@ -404,6 +404,10 @@ specifiers are supported %p: am/pm, additionally switches %h/%H to 12 hour instead of 24 %P: AM/PM (uppercase version of %p) +Inserting a zero like %0m or %0d means that the specifier will be +left-padded with a zero if it's only single-digit. So %y-%0m-%0d +results in unambigious ISO timestamps like 2007-05-10 (for May 10th). + You can customize the month names with the "monthNames" option. For instance, for Danish you might specify: diff --git a/NEWS.txt b/NEWS.txt index a2d560d..585b1f5 100644 --- a/NEWS.txt +++ b/NEWS.txt @@ -16,6 +16,8 @@ Changes: - Navigate plugin now redraws the plot while panning instead of only after the fact (can be disabled by setting the pan.frameRate option to null). Issue 235. +- Date formatter now accepts %0m and %0d to get a zero-padded month or + day (issue raised by Maximillian Dornseif). Bug fixes: diff --git a/jquery.flot.js b/jquery.flot.js index e0747f2..7942028 100644 --- a/jquery.flot.js +++ b/jquery.flot.js @@ -2090,7 +2090,7 @@ }; var r = []; - var escape = false; + var escape = false, padNext = false; var hours = d.getUTCHours(); var isAM = hours < 12; if (monthNames == null) @@ -2118,9 +2118,15 @@ case 'b': c = "" + monthNames[d.getUTCMonth()]; break; case 'p': c = (isAM) ? ("" + "am") : ("" + "pm"); break; case 'P': c = (isAM) ? ("" + "AM") : ("" + "PM"); break; + case '0': c = ""; padNext = true; break; + } + if (c && padNext) { + c = leftPad(c); + padNext = false; } r.push(c); - escape = false; + if (!padNext) + escape = false; } else { if (c == "%")