import { Component, OnInit, OnDestroy } from '@angular/core'; import * as moment from 'moment'; @Component({ selector: 'cm-datepicker-doc-7', templateUrl: './datePicker-doc-7.component.html', styleUrls: ['./datePicker-doc-7.component.css'] }) export class DatePickerDoc7Component implements OnInit, OnDestroy { _startDate: any = null; _endDate: any = null; newArray = (len: any) => { const result = []; for (let i = 0; i < len; i++) { result.push(i); } return result; }; _startValueChange = () => { if (this._startDate > this._endDate) { this._endDate = null; } }; _endValueChange = () => { if (this._startDate > this._endDate) { this._startDate = null; } }; _disabledStartDate = (startValue: any) => { if (!startValue || !this._endDate) { return false; } return startValue.getTime() >= this._endDate.getTime(); }; _disabledEndDate = (endValue: any) => { if (!endValue || !this._startDate) { return false; } return endValue.getTime() <= this._startDate.getTime(); }; get _isSameDay() { return this._startDate && this._endDate && moment(this._startDate).isSame(this._endDate, 'day') } get _endTime() { return { nzHideDisabledOptions: true, nzDisabledHours: () => { return this._isSameDay ? this.newArray(this._startDate.getHours()) : []; }, nzDisabledMinutes: (h: any) => { if (this._isSameDay && h === this._startDate.getHours()) { return this.newArray(this._startDate.getMinutes()); } return []; }, nzDisabledSeconds: (h: any, m: any) => { if (this._isSameDay && h === this._startDate.getHours() && m === this._startDate.getMinutes()) { return this.newArray(this._startDate.getSeconds()); } return []; } } } constructor() { } ngOnInit(){ } ngOnDestroy(){ } }