import { Injectable } from '@angular/core' ; import { Observable } from 'rxjs/Rx' ; /**
 * TickTockService class.
 */ @ Injectable ( ) export class TickTockService { param value returns { string } private static formatTimeNumber ( value ) { const stringValue = value . toString ( ) ; return ( '0' + stringValue ) . slice ( - 2 ) ; } returns { string } private static getNowString ( ) { const date = new Date ( ) ; const hours = TickTockService . formatTimeNumber ( date . getHours ( ) ) ; const minutes = TickTockService . formatTimeNumber ( date . getMinutes ( ) ) ; const seconds = TickTockService . formatTimeNumber ( date . getSeconds ( ) ) ; return `${ hours }:${ minutes }:${ seconds }` ; } type { number } private readonly TIMEOUT : number = 1000 ; returns public getTick ( ) { return Observable . timer ( 0 , this . TIMEOUT ) . map ( ( tick ) => TickTockService . getNowString ( ) ) ; } }