import { Component, EventEmitter, Input, OnInit } from '@angular/core'; import { FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms'; @Component({ selector: 'ics-time-picker', templateUrl: './time-picker.component.html', styleUrls: ['./time-picker.component.scss'] }) export class TimePickerComponent implements OnInit { @Input() public hourControl: FormControl; @Input() public minuteControl: FormControl; constructor(private formBuilder: FormBuilder) { } ngOnInit() { } dirtyCheckForHour() { try { let value = this.hourControl.value; value = parseInt(value, 0); if (value < 0) { value = 23; } else { value %= 24; } this.hourControl.patchValue(this.makeSureTwoUnits(value)); } catch (e) { } } dirtyCheckForMinute() { try { let value = this.minuteControl.value; value = parseInt(value, 0); if (value < 0) { value = 59; this.decrementHour(); } else { value %= 60; if (value === 0) { this.incrementHour(); } } this.minuteControl.patchValue(this.makeSureTwoUnits(value)); } catch (e) { } } incrementHour() { this.adjustHourBy(1); } decrementHour() { this.adjustHourBy(-1); } adjustHourBy(val: number) { const currentValue = this.hourControl.value; const newValue = parseInt(currentValue, 0) + val; this.hourControl.patchValue(newValue); this.dirtyCheckForHour(); } adjustMinuteBy(val: number) { const currentValue = this.minuteControl.value; const newValue = parseInt(currentValue, 0) + val; this.minuteControl.patchValue(newValue); this.dirtyCheckForMinute(); } makeSureTwoUnits(val) { return val > 9 ? val + '' : '0' + val; } }