This patch against revision 234 of the http://code.google.com/p/flot/ library changes `$.plot.formatDate` to act more like the posix strftime() function. It is slightly incompatible to proevious versions of flot. strftime() is the behaviour most coders wit a Unix/C/Ruby/Python/Java Background expect. See http://is.gd/9SpHy for an example of the common strftime() implementation. Even PHP now generally like POSIX (http://is.gd/9Sqjf#) although the wildly incompatible date function (http://is.gd/9Sqpl#) seems to be more popular. I argue that flot should work like nearly all programming Languages with an C/Unix heritage work. Also without this Patch it is impossible to generate http://www.faqs.org/rfcs/rfc3339.html (ISO 8601) compliant timestamps. This patch changes flot so that: %d now works exactly like POSIX adding zero padding %m now works exactly like POSIX adding zero padding %e works like %d in previous versions of flot, but still differs from POSIX, since POSIX has space padding. %L workes like %m in previous versions of flot This results in a slight incompatibility ot older flot versions. I suspect that the impact is mininmal since, while now date formats without delimiters are possible. Formats like YYYYMMDD are simply impossible without padding. Impact on older code should be only of cosmetic nature. Check an axample rendering with `xaxis: { mode: "time", timeformat: "%y-%m-%d" }` at http://static.23.nu/md/Pictures/ZZ71BDC910.png#. In an unpatched version the first label would read 2007-1-1 instead of 2007-01-01 in the patched version. diff --git a/API.txt b/API.txt index 36d85d1..bd45391 100644 --- a/API.txt +++ b/API.txt @@ -397,8 +397,10 @@ specifiers are supported %H: hours (left-padded with a zero) %M: minutes (left-padded with a zero) %S: seconds (left-padded with a zero) - %d: day of month (1-31) - %m: month (1-12) + %d: day of month (01-31, left-padded with a zero) + %e: day of month (1-31) + %m: month (01-12, left-padded with a zero) + %L: month (1-12) %y: year (four digits) %b: month name (customizable) %p: am/pm, additionally switches %h/%H to 12 hour instead of 24 diff --git a/jquery.flot.js b/jquery.flot.js index e0747f2..fa3db14 100644 --- a/jquery.flot.js +++ b/jquery.flot.js @@ -931,10 +931,10 @@ if (span < 2 * timeUnitSize.day) fmt = "%h:%M" + suffix; else - fmt = "%b %d %h:%M" + suffix; + fmt = "%b %e %h:%M" + suffix; } else if (t < timeUnitSize.month) - fmt = "%b %d"; + fmt = "%b %e"; else if (t < timeUnitSize.year) { if (span < timeUnitSize.year) fmt = "%b"; @@ -2112,8 +2112,10 @@ case 'H': c = leftPad(hours); break; case 'M': c = leftPad(d.getUTCMinutes()); break; case 'S': c = leftPad(d.getUTCSeconds()); break; - case 'd': c = "" + d.getUTCDate(); break; - case 'm': c = "" + (d.getUTCMonth() + 1); break; + case 'e': c = "" + d.getUTCDate(); break; + case 'd': c = leftPad(d.getUTCDate()); break; + case 'L': c = "" + (d.getUTCMonth() + 1); break; + case 'm': c = leftPad(d.getUTCMonth() + 1); break; case 'y': c = "" + d.getUTCFullYear(); break; case 'b': c = "" + monthNames[d.getUTCMonth()]; break; case 'p': c = (isAM) ? ("" + "am") : ("" + "pm"); break;