I'm having trouble creating an array of times using RxJS operators in conjunction with Moment.js objects. I initially thought the generate()
operator would be a good fit for this task, but it seems to be returning the same time repeatedly instead of incrementing it. Any ideas on what might be going wrong?
After referring to the documentation at
https://rxjs-dev.firebaseapp.com/api/index/function/generate
I learned that I should be able to utilize
generate(startingValue, condition, increment)
to generate an observable that can be piped or subscribed to. However, despite following these instructions, I have not been successful.
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... ]
Currently, the result is an array containing 20 moment objects, all displaying the same time value.