Skip to content

Commit

Permalink
fix(time): Atomic clock speed stays constant when back and forthing a…
Browse files Browse the repository at this point in the history
…ccross pages

Clear the interval that was used to update the clock in when we leave the clock.

Fixes #101
  • Loading branch information
MathieuNls committed Mar 14, 2017
1 parent ba2acc3 commit bc533eb
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/pages/time/time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ export class TimePage extends ClockComponent{
//So I can use the math lib in the view
//for rounding milliseconds
Math:any = Math;
interval:number = 100;
intervalTime:number = 100;
offset:number;
user:User;
background:string = "time-background";
loading:Loading;
twelveHoursFormat:boolean = true;
interval:any;


constructor(
//own injection
Expand All @@ -49,22 +51,29 @@ export class TimePage extends ClockComponent{
this.user = this.navParams.get('user');

document.addEventListener('resume', () => {
console.log("resume")
this.ngAfterViewInit();
});
}

ionViewCanLeave():boolean {
clearInterval(this.interval);
return true;
}

ngAfterViewInit() {

this.loading.present();

this.twapi.accurateTime().then(
date => {

setInterval(()=>{
this.date = new Date(this.date.getTime() + this.interval);
this.interval = setInterval(()=>{
this.date = new Date(this.date.getTime() + this.intervalTime);
this.initLocalClocks();
console.log(this.date.getMilliseconds());
},
this.interval
this.intervalTime
);

setTimeout(()=>{
Expand Down

0 comments on commit bc533eb

Please sign in to comment.