I've been trying to create a count-up timer like days hours minutes seconds I got a countdown timer that
Here is the code:
import {Component, OnInit, ElementRef, Input} from '@angular/core'
import {Observable} from 'rxjs/Rx';
@Component({
selector: 'countdown',
template: `Time to vote {{message}} {{countDown}}`,
styles: [`h1 { font-family: Lato; }`]
})
export class HelloComponent {
@Input() name: string;
message :string;
private future:Date;
private futureString:string;
private diff: any;
@Input() inputDate: Date;
constructor(elm: ElementRef) {
this.futureString = elm.nativeElement.getAttribute('inputDate');
}
dhms(t){
var days, hours, minutes, seconds;
days = Math.floor(t / 86400);
t -= days * 86400;
hours = Math.floor(t / 3600) % 24;
t -= hours * 3600;
minutes = Math.floor(t / 60) % 60;
t -= minutes * 60;
seconds = t % 60;
return [
days + 'd',
hours + 'h',
minutes + 'm',
seconds + 's'
].join(' ');
}
ngOnInit() {
Observable.interval(1000).map((x) => {
this.future = new Date(this.inputDate.toString().replace( /(\d{2})-(\d{2})-(\d{4})/, "$2/$1/$3"));
this.diff = Math.floor((this.future.getTime() - new Date().getTime()) / 1000);
}).subscribe((x) => {
this.message = this.dhms(this.diff);
});
}
}
Is there a way to modify this to make it count up instead of count down? I've been trying for a while now so any help would be appreciated. thanks in advance