mirror of
https://github.com/richard-loafle/fuse-angular.git
synced 2025-01-11 13:05:08 +00:00
54 lines
1.4 KiB
TypeScript
54 lines
1.4 KiB
TypeScript
import { Component, Input, OnInit } from '@angular/core';
|
|
import * as moment from 'moment';
|
|
import { Observable } from 'rxjs/Observable';
|
|
|
|
@Component({
|
|
selector : 'fuse-countdown',
|
|
templateUrl: './countdown.component.html',
|
|
styleUrls : ['./countdown.component.scss']
|
|
})
|
|
export class FuseCountdownComponent implements OnInit
|
|
{
|
|
@Input('eventDate') eventDate;
|
|
countdown: any;
|
|
|
|
constructor()
|
|
{
|
|
this.countdown = {
|
|
days : '',
|
|
hours : '',
|
|
minutes: '',
|
|
seconds: ''
|
|
};
|
|
}
|
|
|
|
ngOnInit()
|
|
{
|
|
const currDate = moment();
|
|
const eventDate = moment(this.eventDate);
|
|
|
|
let diff = eventDate.diff(currDate, 'seconds');
|
|
|
|
const countDown =
|
|
Observable
|
|
.interval(1000)
|
|
.map(value => {
|
|
return diff = diff - 1;
|
|
})
|
|
.map(value => {
|
|
const timeLeft = moment.duration(value, 'seconds');
|
|
|
|
return {
|
|
days : timeLeft.asDays().toFixed(0),
|
|
hours : timeLeft.hours(),
|
|
minutes: timeLeft.minutes(),
|
|
seconds: timeLeft.seconds()
|
|
};
|
|
});
|
|
|
|
countDown.subscribe(value => {
|
|
this.countdown = value;
|
|
});
|
|
}
|
|
}
|