role="alert"
class="alert alert-danger">
<span class="material-icons">error</span>
- {{firstError(controlDir.control.errors)}}
+ {{firstError(controlDir.control.errors)}}
</div>
<ngb-datepicker #datePicker
+ [minDate]="minDate"
+ [maxDate]="maxDate"
formControlName="date"
[footerTemplate]="time"
(touch)="onTouched()">
import {NgbDatepicker, NgbTimeStruct, NgbDateStruct} from '@ng-bootstrap/ng-bootstrap';
import {DatetimeValidator} from '@eg/share/validators/datetime_validator.directive';
import * as moment from 'moment-timezone';
+import {DateUtil} from '@eg/share/util/date';
@Component({
selector: 'eg-datetime-select',
@Input() showTZ = true;
@Input() timezone: string = this.format.wsOrgTimezone;
@Input() readOnly = false;
+ @Input() noPast = false;
+ @Input() noFuture = false;
+ @Input() minDate: any;
+ @Input() maxDate: any;
@Output() onChangeAsIso: EventEmitter<string>;
dateTimeForm: FormGroup;
}
ngOnInit() {
+ if (this.noPast) {
+ this.minDate = DateUtil.localYmdPartsFromDate();
+ }
+ if (this.noFuture) {
+ this.maxDate = DateUtil.localYmdPartsFromDate();
+ }
if (!this.timezone) {
this.timezone = this.format.wsOrgTimezone;
}
/* Utility code for dates */
+export interface YmdParts {
+ year: number;
+ month: number;
+ day: number;
+}
+
export class DateUtil {
/**
((now.getMonth() + 1) + '').padStart(2, '0') + '-' +
(now.getDate() + '').padStart(2, '0');
}
+
+ static localYmdPartsFromDate(date?: Date): YmdParts {
+ const ymd = DateUtil.localYmdFromDate(date);
+ const parts = ymd.split(/-/);
+ return {
+ year: Number(parts[0]),
+ month: Number(parts[1]),
+ day: Number(parts[2])
+ };
+ }
}