Get rank between two hours given

1

I am currently working with momentjs and moment-range to show the range between two dates in an array, this is my code:

var start = moment("2017-01-03", 'YYYY-MM-DD').format('YYYY-MM-DD');
var end   = moment("2017-01-13", 'YYYY-MM-DD').format('YYYY-MM-DD');
var rangoFechas = moment().range(start,end);
var resultado =rangoFechas.toArray('days'); 
for(var i = 0; i < resultado.length; i++){
    var dia=resultado[i].format('dddd, D/MMMM/YYYY');
    console.log(dia)
}

Now I have to implement the same logic but instead of dates I have to put hours, I tried the following:

var start = moment("15:00:00", 'HH:mm:ss').format('HH:mm:ss');
var end   = moment("19:00:00", 'HH:mm:ss').format('HH:mm:ss');
var rangoHoras = moment().range(start,end);
var resultado =rangoHoras.toArray('hours'); //será hours?
for(var i = 0; i < resultado.length; i++){
    var hora=resultado[i].format('HH:mm');
    console.log(hora)
}

And the truth is that I could not get anything. How can I solve it?. Thank you in advance

    
asked by Dimoreno 07.09.2017 в 00:56
source

1 answer

1

I give you an example to subtract hours and thus obtain the interval, as in your loop you use the format 'HH: mm' I use that mask to declare the types.

var start = moment.duration("13:45", "HH:mm"),
    end = moment.duration("14:30", "HH:mm"),
    diff = end.subtract(start);
diff.hours();
diff.minutes();

You also have the .diff method in the objects that you could be worth, in the documentation of momentjs specified

    
answered by 07.09.2017 в 01:26