I'm trying to create an array of times with RxJS operators using Moment.js objects. I think the generate()
operator would be well suited, but it's returning the same time over and over, instead of the incremented time. What am I doing wrong?
According to the docs,
https://rxjs-dev.firebaseapp.com/api/index/function/generate
I should be able to use generate(startingValue, condition, increment)
to create an observable which I can then pipe or subscribe to, but I can't get this to work.
times(): void {
const startTime: Moment = START.clone(); //2019-01-01T16:00:00.000
const endTime: Moment = END; //2019-01-01T21:00:00.000
generate(startTime, time => time <= endTime, time => time.add(15, 'minutes')).pipe(
toArray()
).subscribe(console.log);
}
// returns: [2019-01-01T16:00:00.000, 2019-01-01T16:00:00.000...] 20 times
// desired: [2019-01-01T16:00:00.000, 2019-01-01T16:15:00.000, 2019-01-01T16:30:00.000... ]
I'm just getting an array of 20 moment objects, all with the same time value.