Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Date parsing workaround #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions lib/date.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// 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 (rfc3399) {
var temp = Date.parse(rfc3399);
if (isNaN(temp)) {
// this technique is borrowed from jquery.couch.app.util's $.prettyDate
temp = rfc3399.replace(/-/g,"/").replace("T", " ").replace("Z", " +0000").replace(/(\d*\:\d*:\d*)\.\d*/g,"$1");
}
return new Date(temp);
}
5 changes: 3 additions & 2 deletions lists/comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ function(head, req) {
var List = require("vendor/couchapp/lib/list");
var path = require("vendor/couchapp/lib/path").init(req);
var Atom = require("vendor/couchapp/lib/atom");
var newDate = require("lib/date").newDate;

var indexPath = path.list('index','recent-posts',{descending:true, limit:10});
var feedPath = path.list('index','recent-posts',{descending:true, limit:10, format:"atom"});
Expand All @@ -21,7 +22,7 @@ function(head, req) {

// generate the feed header
var feedHeader = Atom.header({
updated : (row ? new Date(row.value.created_at) : new Date()),
updated : (row ? newDate(row.value.created_at) : new Date()),
title : ddoc.blog.title + " comments",
feed_id : path.absolute(indexPath),
feed_link : path.absolute(commentsFeed)
Expand All @@ -40,7 +41,7 @@ function(head, req) {
entry_id : path.absolute('/'+encodeURIComponent(req.info.db_name)+'/'+encodeURIComponent(row.id)),
title : "comment on "+v.post_id,
content : markdown.encode(Mustache.escape(v.comment)),
updated : new Date(v.created_at),
updated : newDate(v.created_at),
author : v.commenter.nickname || v.commenter.name,
alternate : path.absolute(path.list('post','post-page', {startkey:[v.post_id]}))
});
Expand Down
7 changes: 4 additions & 3 deletions lists/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ function(head, req) {
var List = require("vendor/couchapp/lib/list");
var path = require("vendor/couchapp/lib/path").init(req);
var Atom = require("vendor/couchapp/lib/atom");

var newDate = require("lib/date").newDate;

var indexPath = path.list('index','recent-posts',{descending:true, limit:10});
var feedPath = path.list('index','recent-posts',{descending:true, limit:10, format:"atom"});
var commentsFeed = path.list('comments','comments',{descending:true, limit:10, format:"atom"});
Expand Down Expand Up @@ -74,7 +75,7 @@ function(head, req) {

// generate the feed header
var feedHeader = Atom.header({
updated : (row ? new Date(row.value.created_at) : new Date()),
updated : (row ? newDate(row.value.created_at) : new Date()),
title : ddoc.blog.title,
feed_id : path.absolute(indexPath),
feed_link : path.absolute(feedPath),
Expand All @@ -98,7 +99,7 @@ function(head, req) {
entry_id : path.absolute('/'+encodeURIComponent(req.info.db_name)+'/'+encodeURIComponent(row.id)),
title : row.value.title,
content : html,
updated : new Date(row.value.created_at),
updated : newDate(row.value.created_at),
author : row.value.author,
alternate : path.absolute(path.show('post', row.id))
});
Expand Down
2 changes: 1 addition & 1 deletion views/comments/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ function(doc) {
// todo normalize this schema-ness
doc.commenter.gravatar = hex_md5(doc.commenter.email);
}
emit(new Date(doc.created_at), doc);
emit(doc.created_at, doc);
}
};
2 changes: 1 addition & 1 deletion views/recent-posts/map.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function(doc) {
if (doc.type == "post") {
emit(new Date(doc.created_at), doc);
emit(doc.created_at, doc);
}
};