Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Date munging #11

Merged
5 commits merged into from

1 participant

@isaacs

The first one is the fix we talked about. Pretty trivial.

The rest are so that your date format function can output ISO-compliant dates :)

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 15 additions and 5 deletions.
  1. +15 −5 lib/wheat/tools.js
View
20 lib/wheat/tools.js
@@ -6,8 +6,11 @@ var Sys = require('sys'),
Buffer = require('buffer').Buffer,
Git = require('git-fs');
-function pad(num) {
- return num < 10 ? "0" + num : num;
+function pad(num, count) {
+ count = count || 2;
+ num = "" + num;
+ for (i = num.length; i < count; i ++) num = "0" + num;
+ return num;
}
// accepts the client's time zone offset from GMT in minutes as a parameter.
@@ -59,7 +62,7 @@ var Helpers = {
formatDate: function formatDate(val, format) {
var date = new Date(val),
match, value;
- while (match = format.match(/(%[a-z])/i)) {
+ while (match = format.match(/(%[a-z%])/i)) {
switch (match[1]) {
case "%Y": // A full numeric representation of a year, 4 digits
value = date.getFullYear(); break;
@@ -68,9 +71,9 @@ var Helpers = {
case "%F": // A full textual representation of a month like March
value = monthsInYear[date.getMonth()]; break;
case "%d": // Day of the month, 2 digits with leading zeros
- value = pad(date.getDate() + 1); break;
+ value = pad(date.getDate()); break;
case "%j": // Day of the month without leading zeros
- value = pad(date.getDate() + 1); break;
+ value = date.getDate(); break;
case "%l": // A full textual representation of the day of the week
value = daysInWeek[date.getDay()]; break;
case "%H": // 24-hour format of an hour with leading zeros
@@ -79,11 +82,18 @@ var Helpers = {
value = pad(date.getMinutes()); break;
case "%s": // Seconds, with leading zeros
value = pad(date.getSeconds()); break;
+ case "%u": // milliseconds with leading zeroes
+ value = pad(date.getMilliseconds(), 3); break;
+ case "%z": // time zone offset
+ value = getTZOString(date.getTimezoneOffset()); break;
+ case "%%": // literal % sign
+ value = "\0%\0"; break;
default:
value = ""; break;
}
format = format.replace(match[1], value);
}
+ format = format.split("\0%\0").join("%");
return format;
},
formatRFC822Date: function formatRFC822Date(val)
Something went wrong with that request. Please try again.