Skip to content

Commit

Permalink
Changed ember models to use moment for dates
Browse files Browse the repository at this point in the history
Closes #2888

-Added moment-date `DS.Transform`
-`models/post` and `models/user` both use `DS.attr('moment-date')` in
place of `date` now.
  • Loading branch information
novaugust committed Jun 5, 2014
1 parent afec0bc commit d3d6265
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
6 changes: 3 additions & 3 deletions core/client/models/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ var Post = DS.Model.extend({
meta_title: DS.attr('string'),
meta_description: DS.attr('string'),
author: DS.belongsTo('user', { async: true }),
created_at: DS.attr('date'),
created_at: DS.attr('moment-date'),
created_by: DS.belongsTo('user', { async: true }),
updated_at: DS.attr('date'),
updated_at: DS.attr('moment-date'),
updated_by: DS.belongsTo('user', { async: true }),
published_at: DS.attr('date'),
published_at: DS.attr('moment-date'),
published_by: DS.belongsTo('user', { async: true }),
tags: DS.hasMany('tag', { async: true }),

Expand Down
6 changes: 3 additions & 3 deletions core/client/models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ var User = DS.Model.extend({
language: DS.attr('string'),
meta_title: DS.attr('string'),
meta_description: DS.attr('string'),
last_login: DS.attr('date'),
created_at: DS.attr('date'),
last_login: DS.attr('moment-date'),
created_at: DS.attr('moment-date'),
created_by: DS.attr('number'),
updated_at: DS.attr('date'),
updated_at: DS.attr('moment-date'),
updated_by: DS.attr('number'),

isSignedIn: Ember.computed.bool('id'),
Expand Down
16 changes: 16 additions & 0 deletions core/client/transforms/moment-date.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/* global moment */
var MomentDate = DS.Transform.extend({
deserialize: function (serialized) {
if (serialized) {
return moment(serialized);
}
return serialized;
},
serialize: function (deserialized) {
if (deserialized) {
return moment(deserialized).toDate();
}
return deserialized;
}
});
export default MomentDate;

0 comments on commit d3d6265

Please sign in to comment.