import moment from 'moment' ; export class Interval { constructor ( private readonly from , private readonly to , private readonly interval ) { } rate ( rate ) { let now = this . from ; const args = this . interval . match ( /(.*)(s|m|h|d)/ ) ; if ( ! args ) { throw new Error ( 'Failed to parse interval' ) ; } const timestamps = [ ] ; while ( now < this . to ) { timestamps . push ( ... new Array < number > ( rate ) . fill ( now ) ) ; now = moment ( now ) . add ( Number ( args [ 1 ] ) , args [ 2 ] as any ) . valueOf ( ) ; } return timestamps ; } }