I am trying to find ranges between two given times, in Si what I want is to do the following:
I have h1 = 20:00:00 and h2= 20:30:00
What I want is for the end result to be equal to this:
20:00:00--20:10:00--20:20:00--20:30:00 That is, add 10 minutes to the given time
This is my code:
.controller('General', function($scope){
$scope.h1=moment("18:00:00",'HH,mm,ss').format('HH-mm-ss');
$scope.h2=moment("21:00:00",'HH,mm,ss').format('HH-mm-ss');
var rangoMinutos = function(h1, h2) {
var rango= [];
while (h1 <= h2) {
rango.push(h1);
h1.add(1,'hours');//NO SE SI ESTE BIEN ESTO
}
return rango;
};
var results1 = rangoMinutos($scope.h1, $scope.h2);
alert(results1)//ver resultado de los rangos
})
I don't know MomentJS, but the first thing you should do is convert the two times to a format that you can actually compare their different.
The main problem I see in your code is that when generating the array you are adding the same moment object n times, so when you read it you will get n equal elements with the same time.
If you are going to create an array of moment objects you should create a new object every time you add an element to the array.
Take a look at this example: