Skip to content

Commit

Permalink
fix by_date view by symlinking in library to views
Browse files Browse the repository at this point in the history
  • Loading branch information
natevw committed Jun 20, 2017
1 parent 1c3f418 commit 9c8293d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
5 changes: 1 addition & 4 deletions views/by_date/map.js
Expand Up @@ -2,9 +2,6 @@ function(doc) {
if (doc.type != "http://stemstorage.net/glob/post") return;
if (!doc.published) return;

var exports = {};
// !code lib/date.js
var date = exports;

var date = require("views/lib/date");
emit(date.toUTCComponents(date.newDate(doc.published)));
}
33 changes: 33 additions & 0 deletions views/lib/date.js
@@ -0,0 +1,33 @@
/* Simple workaround for older JavaScript engines that
* do not understand the One True Date Format.
* This doesn't totally mimic new Date(), just string parsing.
*/
exports.newDate = function (rfc3339) {
var temp = Date.parse(rfc3339);
if (isNaN(temp)) {
// this technique is borrowed from jquery.couch.app.util's $.prettyDate
temp = rfc3339.replace(/-/g,"/").replace("T", " ").replace("Z", " +0000").replace(/(\d*\:\d*:\d*)\.\d*/g,"$1");
}
return new Date(temp);
};

exports.toUTCComponents = function (date) {
return [
date.getUTCFullYear(), // 0
date.getUTCMonth() + 1, // 1
date.getUTCDate(), // 2
date.getUTCHours(), // 3
date.getUTCMinutes(), // 4
date.getUTCSeconds() + (date.getUTCMilliseconds() / 1000)
];
};

exports.toRFC3339 = function (date) {
// after https://github.com/couchapp/couchapp/blob/master/vendor/lib/atom.js

function f(n) { // Format integers to have at least two digits.
return n < 10 ? '0' + n : '' + n;
}
var d = exports.toUTCComponents(date);
return d[0] + '-' + f(d[1]) + '-' + f(d[2]) + 'T' + f(d[3]) + ':' + f(d[4]) + ':' + f(d[5]) + 'Z'
};

0 comments on commit 9c8293d

Please sign in to comment.