dimanche 10 avril 2016

Calculating Date Difference in Ember.js

I am trying to apply this solution to an Ember.js app. http://ift.tt/1XpffyH It obviously works in the jsfiddle, but I am not able to implement it correctly in Ember.

I am learning, and probably making an obvious mistake. I've placed the function inside the model and am getting an "NaN" error. A date is passed through an input value in the format of M/D/YYYY. Anyone have experience with dates and ember? Can you see why it would fail to parse the date?

//app/model/task.js
import DS from 'ember-data';

export default DS.Model.extend({
  taskname: DS.attr(),
  startdate: DS.attr(),
  enddate: DS.attr(),
  duration: Ember.computed('startdate', 'enddate', function() {
    var date1 = new Date('startdate');
    var date2 = new Date('enddate');
    var timeDiff = Math.abs(date2.getTime() - date1.getTime());
    var diffDays = Math.ceil(timeDiff / (1000 * 3600 * 24)); 
    return diffDays;
  }),
  banding: DS.attr()
});

Aucun commentaire:

Enregistrer un commentaire