views:

50

answers:

0

I have an incosistency in my js code that is driving me crazy. Here's the situation: I have events with a starting and ending time that I set into js variables as following, being 'event' the item from a forEach:

var hour = new Number('0${event.hourTimeStart}');
var minutes = new Number('0${event.minutesTimeStart}');
var hourEnd = new Number('0${event.hourTimeEnd}');
var minutesEnd = new Number('0${event.minutesTimeEnd}');

So, I have to represent the event in a timetable splitted in 30 min intervals. To know which intervals have events I do like this:

for (i = hour; i <= hourEnd; i++ ) {

   var id = '';

   if (i < 10) {
      id = '0'+i;
   } else {
      id = i;
   }

   if(i == hour && i == hourEnd) {
      if(minutes <= 30) {
         eventsByHour[id+':00']++;
      }
      if(minutesEnd > 30) {
         eventsByHour[id+':30']++;
      }
   }               

   else if(i == hour && i != hourEnd) {
      if(minutes < 30) {
         eventsByHour[id+':00']++;
      }
      eventsByHour[id+':30']++;
   }

   else if (i != hour && i == hourEnd) {
       if(minutesEnd != 0 && minutesEnd <= 30) {
          eventsByHour[id+':00']++;
       }
       if(minutesEnd > 30) {
           eventsByHour[id+':00']++;
           eventsByHour[id+':30']++;
       }
   }              

   else if(i != hour && i != hourEnd) {
        eventsByHour[id+':00']++;
        eventsByHour[id+':30']++;
   }               

}

All events fits their times perfectly execpt for the ones where hour and hourEnd it's the same, like 09:00 - 09:30 should only fill the cell 09:00 but it doesn't. It says that hour != hourEnd even being the same.

I tried to explain the problem the best I could but if you have any doubts ask please. Thanks

UPDATE: changed this, as suggested in the comments:

var hour = parseInt('0${event.hourTimeStart}', 10);
var minutes = parseInt('0${event.minutesTimeStart}', 10);
var hourEnd = parseInt('${event.hourTimeEnd}', 10);
var minutesEnd = parseInt('0${event.minutesTimeEnd}', 10);

Now it seems to work properly.