Changed ember models to use moment for dates

Closes #2888

-Added moment-date `DS.Transform`
-`models/post` and `models/user` both use `DS.attr('moment-date')` in
place of `date` now.
This commit is contained in:
Matt Enlow 2014-06-05 10:04:59 -06:00
parent fd48a12b42
commit fc28cddb8d
3 changed files with 22 additions and 6 deletions

View File

@ -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 }),

View File

@ -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'),

View File

@ -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;