0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-03-11 02:12:21 -05:00

issue #234 - date bug

- updated fixtures so that even short-term we have valid data
- added methods to the base model that marshall the data in and out of the db so it is always an RFC 2822 date never ISO 8601
- turned off SQL debugging now the bug is resolved
- minor change to the date listing template, as we don't need to check for updated_at now that the data is correct - but should use published date anyway
This commit is contained in:
Hannah Wolfe 2013-07-08 12:39:11 +01:00
parent 85535ae000
commit 221345ff99
4 changed files with 44 additions and 9 deletions

View file

@ -86,7 +86,7 @@ config.env = {
connection: { connection: {
filename: path.join(__dirname, '/core/shared/data/ghost-dev.db') filename: path.join(__dirname, '/core/shared/data/ghost-dev.db')
}, },
debug: true debug: false
}, },
url: { url: {
host: '127.0.0.1', host: '127.0.0.1',

View file

@ -2,10 +2,11 @@
<h3 class="entry-title">{{title}}</h3> <h3 class="entry-title">{{title}}</h3>
<section class="entry-meta"> <section class="entry-meta">
<time datetime="2013-01-04" class="date"> <time datetime="2013-01-04" class="date">
{{#if published}}Published {{#if published}}
{{#if updated_at}}{{dateFormat updated_at timeago="True"}} Published {{dateFormat published_at timeago="True"}}
{{else}}{{dateFormat published_at timeago="True"}}{{/if}} {{else}}
{{else}}<span class="status-draft">Draft</span>{{/if}} <span class="status-draft">Draft</span>
{{/if}}
</time> </time>
{{!<span class="views">1,934</span>}} {{!<span class="views">1,934</span>}}
</section> </section>

View file

@ -17,9 +17,11 @@ module.exports = {
"status": "published", "status": "published",
"featured": true, "featured": true,
"author_id": 1, "author_id": 1,
"created_at": '2012-11-09T15:40:46.776Z', "created_at": '1352475600601',
"created_by": 1, "created_by": 1,
"published_at": '2012-11-09T15:40:46.776Z', "updated_at": '1352475600601',
"updated_by": 1,
"published_at": '1352475600601',
"published_by": 1 "published_by": 1
}, },
{ {
@ -36,9 +38,11 @@ module.exports = {
"status": "published", "status": "published",
"featured": true, "featured": true,
"author_id": 1, "author_id": 1,
"created_at": '2012-06-25T01:00:23.776Z', "created_at": '1340582400102',
"created_by": 1, "created_by": 1,
"published_at": '2012-06-25T01:00:23.776Z', "updated_at": '1340582400102',
"updated_by": 1,
"published_at": '1340582400102',
"published_by": 1 "published_by": 1
} }
], ],

View file

@ -1,5 +1,6 @@
var GhostBookshelf, var GhostBookshelf,
Bookshelf = require('bookshelf'), Bookshelf = require('bookshelf'),
_ = require('underscore'),
config = require('../../../config'); config = require('../../../config');
// Initializes Bookshelf as its own instance, so we can modify the Models and not mess up // Initializes Bookshelf as its own instance, so we can modify the Models and not mess up
@ -11,6 +12,35 @@ GhostBookshelf = Bookshelf.Initialize('ghost', config.env[process.env.NODE_ENV |
GhostBookshelf.Model = GhostBookshelf.Model.extend({ GhostBookshelf.Model = GhostBookshelf.Model.extend({
// Base prototype properties will go here // Base prototype properties will go here
// Fix problems with dates
fixDates: function (attrs) {
_.each(attrs, function (value, key) {
if (key.substr(-3) === '_at' && value !== null) {
attrs[key] = new Date(attrs[key]);
}
});
return attrs;
},
format: function (attrs) {
return this.fixDates(attrs);
},
toJSON: function (options) {
var attrs = this.fixDates(_.extend({}, this.attributes)),
relations = this.relations;
if (options && options.shallow) {
return attrs;
}
_.each(relations, function (key) {
attrs[key] = relations[key].toJSON();
});
return attrs;
}
}, { }, {