X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=auto_tests%2Ftests%2FUtil.js;h=207f23733d8e2b0d7ceac6d5c67bfe8536707094;hb=464b5f504e75c5d2b98eff12b3b8ad520a1729cb;hp=8a14e065507845089f803ca4f5f374576e04a9bb;hpb=70d47e7c9564e190f29f6a8bb1f4c547bef8781a;p=dygraphs.git diff --git a/auto_tests/tests/Util.js b/auto_tests/tests/Util.js index 8a14e06..207f237 100644 --- a/auto_tests/tests/Util.js +++ b/auto_tests/tests/Util.js @@ -131,3 +131,21 @@ Util.overrideXMLHttpRequest = function(data) { return FakeXMLHttpRequest; }; +/** + * Format a date as 2000/01/23 + * @param {number} date_ms Millis since epoch. + * @return {string} The date formatted as YYYY-MM-DD. + */ +Util.formatDate = function(date_ms) { + var zeropad = function(x) { if (x < 10) return "0" + x; else return "" + x; }; + var d = new Date(date_ms); + + // Get the year: + var year = "" + d.getFullYear(); + // Get a 0 padded month string + var month = zeropad(d.getMonth() + 1); //months are 0-offset, sigh + // Get a 0 padded day string + var day = zeropad(d.getDate()); + + return year + "/" + month + "/" + day; +};