import * as assert from 'assert' ; export class Duration { private _milliseconds : number ; private constructor ( milliseconds ) { this . _milliseconds = milliseconds ; } public get totalMilliseconds ( ) : number { return this . _milliseconds ; } public get totalSeconds ( ) : number { return this . totalMilliseconds / 1000 ; } public plus ( rhs ) { return Duration . milliseconds ( this . _milliseconds + rhs . _milliseconds ) ; } public dividedBy ( divisor ) { assert . notEqual ( 0 , divisor , "divisor cannot be 0" ) ; return Duration . milliseconds ( this . _milliseconds / divisor ) ; } public lessThanOrEqualTo ( rhs ) { return this . totalMilliseconds <= rhs . totalMilliseconds ; } public toString ( ) { let ms = this . totalMilliseconds ; return `${ ms } millisecond${ ( ms !== 1 ? "s" : "" ) }` ; } public static zero : Duration = Duration . milliseconds ( 0 ) ; public static milliseconds ( milliseconds ) { return new Duration ( milliseconds ) ; } public static seconds ( seconds ) { return Duration . milliseconds ( seconds * 1000 ) ; } }