import {Component, OnInit, Input, Output, ViewChild, EventEmitter, forwardRef} from '@angular/core';
import {NgbDateStruct} from '@ng-bootstrap/ng-bootstrap';
import {ControlValueAccessor, NG_VALUE_ACCESSOR} from '@angular/forms';
+import {DateUtil} from '@eg/share/util/date';
/**
* RE: displaying locale dates in the input field:
if (this.current == null) { return null; }
if (!this.isValidDate(this.current)) { return null; }
const ymd = `${this.current.year}-${String(this.current.month).padStart(2, '0')}-${String(this.current.day).padStart(2, '0')}`;
- const date = this.localDateFromYmd(ymd);
+ const date = DateUtil.localDateFromYmd(ymd);
const iso = date.toISOString();
return iso;
}
if (this.current == null) { return null; }
if (!this.isValidDate(this.current)) { return null; }
const ymd = `${this.current.year}-${String(this.current.month).padStart(2, '0')}-${String(this.current.day).padStart(2, '0')}`;
- const date = this.localDateFromYmd(ymd);
+ const date = DateUtil.localDateFromYmd(ymd);
return date;
}
ngOnInit() {
if (this.initialYmd) {
- this.initialDate = this.localDateFromYmd(this.initialYmd);
+ this.initialDate = DateUtil.localDateFromYmd(this.initialYmd);
} else if (this.initialIso) {
this.initialDate = new Date(this.initialIso);
onDateSelect(evt) {
const ymd = `${evt.year}-${String(evt.month).padStart(2, '0')}-${String(evt.day).padStart(2, '0')}`;
- const date = this.localDateFromYmd(ymd);
+ const date = DateUtil.localDateFromYmd(ymd);
const iso = date.toISOString();
this.onChangeAsDate.emit(date);
this.onChangeAsYmd.emit(ymd);
this.propagateChange(date);
}
- // Create a date in the local time zone with selected YMD values.
- // TODO: Consider moving this to a date service...
- localDateFromYmd(ymd: string): Date {
- const parts = ymd.split('-');
- return new Date(
- Number(parts[0]), Number(parts[1]) - 1, Number(parts[2]));
- }
-
reset() {
this.current = {
year: null,