import { ChangeDetectionStrategy , Component } from '@angular/core' ; import { CountdownConfig } from 'ngx-countdown' ; const CountdownTimeUnits = [ [ 'Y' , 1000 * 60 * 60 * 24 * 365 ] , [ 'M' , 1000 * 60 * 60 * 24 * 30 ] , [ 'D' , 1000 * 60 * 60 * 24 ] , [ 'H' , 1000 * 60 * 60 ] , [ 'm' , 1000 * 60 ] , [ 's' , 1000 ] , [ 'S' , 1 ] , ] ; @ Component ( { selector : 'more-than-24-hours' , template : `
    <div class="card-header">
      More than 24 hours
      <view-code name="more-than-24-hours"></view-code>
    </div>
    <div class="card-body">
      <countdown [config]="config"></countdown>
    </div>
  ` , host : { '[class.card]' : `true` , '[class.text-center]' : `true` , } , changeDetection : ChangeDetectionStrategy . OnPush , } ) export class MoreThan24HoursComponent { config : CountdownConfig = { leftTime : 60 * 60 * 25 , formatDate : ( { date , formatStr } ) => { let duration = Number ( date || 0 ) ; return CountdownTimeUnits . reduce ( ( current , [ name , unit ] ) => { if ( current . indexOf ( name ) !== - 1 ) { const v = Math . floor ( duration / unit ) ; duration -= v * unit ; return current . replace ( new RegExp ( `${ name }+` , 'g' ) , ( match ) => { return v . toString ( ) . padStart ( match . length , '0' ) ; } ) ; } return current ; } , formatStr ) ; } , } ; }