Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- export class TimerService {
- K = 1000;
- INTERVAL = this.K;
- MINUTES = 25;
- TIME = this.MINUTES * this.K * 60;
- current = 0;
- time = this.TIME;
- toggle$ = new BehaviorSubject(true);
- remainingSeconds$ = this.toggle$.pipe(
- switchMap((running: boolean) => {
- return running ? timer(0, this.INTERVAL) : NEVER;
- }),
- map(this.toRemainingSeconds),
- takeWhile(t => t >= 0)
- );
- constructor() {}
- toMinutes(ms: number): number {
- return Math.floor(ms / this.K / 60);
- }
- toSeconds(ms: number): number {
- return Math.floor(ms / this.K) % 60;
- }
- toSecondsString(ms: number): string {
- const seconds = this.toSeconds(ms);
- return seconds < 10 ? `0${seconds}` : seconds.toString();
- }
- toMs(t: number): number {
- return t * this.INTERVAL;
- }
- currentInterval(): number {
- return this.time / this.INTERVAL;
- }
- toRemainingSeconds(t: number): number {
- return this.currentInterval() - t;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement