import Ember from 'ember';
import DS from 'ember-data';

const secondsInDay = 86400;
const days = [
  'monday',
  'tuesday',
  'wednesday',
  'thursday',
  'friday',
  'saturday',
  'sunday',
];

export default DS.Model.extend({
  temp: DS.attr('number'),

  // Seconds since 00:00 Monday.
  seconds: DS.attr('number'),

  day: Ember.computed('seconds', {
    get() {
      return Math.floor(this.get('seconds') / secondsInDay);
    },

    set(key, value) {
      value = value % days.length;

      if (value < 0) {
        value += days.length;
      }

      const newDayOffset     = value * secondsInDay;
      const oldDayOffset     = this.get('day') * secondsInDay;
      const secondsRemaining = this.get('seconds') - oldDayOffset;

      this.set('seconds', newDayOffset + secondsRemaining);

      return value;
    },
  }),

  dayLabel: Ember.computed('day', {
    get() {
      return days[this.get('day')];
    },

    set(key, value) {
      this.set('day', days.indexOf(value));

      return value;
    },
  }),

  time: Ember.computed('seconds', 'day', {
    get() {
      const dayOffset = this.get('day') * secondsInDay;
      const seconds   = this.get('seconds') - dayOffset;

      const time = moment({ hours: 0 }).seconds(seconds);

      return time.format('HH:mm');
    },

    set(key, value) {
      const time = moment.duration(value);

      this.set('seconds', time.asSeconds());

      return value;
    },
  }),
});

@@ -435,37 +435,35 @@
 ,%0A%0A    set(key, 
-value
+day
 ) %7B%0A      value 
@@ -460,21 +460,17 @@
     
-value = value
+day = day
  %25 d
@@ -492,21 +492,19 @@
     if (
-value
+day
  %3C 0) %7B%0A
@@ -511,21 +511,19 @@
         
-value
+day
  += days
@@ -571,21 +571,19 @@
 t     = 
-value
+day
  * secon
@@ -788,37 +788,35 @@
 ;%0A%0A      return 
-value
+day
 ;%0A    %7D,%0A  %7D),%0A%0A
@@ -912,37 +912,40 @@
 ,%0A%0A    set(key, 
-value
+dayLabel
 ) %7B%0A      this.s
@@ -967,21 +967,24 @@
 indexOf(
-value
+dayLabel
 ));%0A%0A   
@@ -985,37 +985,40 @@
 ;%0A%0A      return 
-value
+dayLabel
 ;%0A    %7D,%0A  %7D),%0A%0A
@@ -1301,20 +1301,19 @@
 et(key, 
-valu
+tim
 e) %7B%0A   
@@ -1313,36 +1313,40 @@
 ) %7B%0A      const 
-time
+duration
  = moment.durati
@@ -1348,20 +1348,19 @@
 uration(
-valu
+tim
 e);%0A%0A   
@@ -1382,20 +1382,24 @@
 conds', 
-time
+duration
 .asSecon
@@ -1423,12 +1423,11 @@
 urn 
-valu
+tim
 e;%0A 

Use better argument manes than 'value'.