Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (this.etaModel && this.etdModel) {
const etaDate = new NgbDate(this.etaModel.date.year, this.etaModel.date.month, this.etaModel.date.day);
const etdDate = new NgbDate(this.etdModel.date.year, this.etdModel.date.month, this.etdModel.date.day);
this.etaIsAfterEtdError = etdDate.before(etaDate);
if (etdDate.equals(etaDate)) {
this.etaIsAfterEtdError = this.etaModel.time.hour > this.etdModel.time.hour
|| (this.etaModel.time.hour === this.etdModel.time.hour
&& this.etaModel.time.minute >= this.etdModel.time.minute);
}
} else {
this.etaIsAfterEtdError = false;
}
const prevEtdDate = this.prevEtdModel != null && this.prevEtdModel.date != null ? new NgbDate(this.prevEtdModel.date.year, this.prevEtdModel.date.month, this.prevEtdModel.date.day) : null;
const nextEtaDate = this.nextEtaModel != null && this.nextEtaModel.date != null ? new NgbDate(this.nextEtaModel.date.year, this.nextEtaModel.date.month, this.nextEtaModel.date.day) : null;
// Checking for sequence errors between prev and current port of call
if (prevEtdDate && this.etaModel) {
this.prevEtdIsAfterCurrentEtaError = prevEtdDate.after(this.etaModel.date);
if (prevEtdDate.equals(this.etaModel.date)) {
this.prevEtdIsAfterCurrentEtaError = this.prevEtdModel.time.hour > this.etaModel.time.hour
|| (this.prevEtdModel.time.hour === this.etaModel.time.hour
&& this.prevEtdModel.time.minute >= this.etaModel.time.minute);
}
} else {
this.prevEtdIsAfterCurrentEtaError = false;
}
// Checking for sequence errors between next and current port of call
if (nextEtaDate && this.etdModel) {
const etaDate = new NgbDate(this.etaModel.date.year, this.etaModel.date.month, this.etaModel.date.day);
const etdDate = new NgbDate(this.etdModel.date.year, this.etdModel.date.month, this.etdModel.date.day);
this.etaIsAfterEtdError = etdDate.before(etaDate);
if (etdDate.equals(etaDate)) {
this.etaIsAfterEtdError = this.etaModel.time.hour > this.etdModel.time.hour
|| (this.etaModel.time.hour === this.etdModel.time.hour
&& this.etaModel.time.minute >= this.etdModel.time.minute);
}
} else {
this.etaIsAfterEtdError = false;
}
const prevEtdDate = this.prevEtdModel != null && this.prevEtdModel.date != null ? new NgbDate(this.prevEtdModel.date.year, this.prevEtdModel.date.month, this.prevEtdModel.date.day) : null;
const nextEtaDate = this.nextEtaModel != null && this.nextEtaModel.date != null ? new NgbDate(this.nextEtaModel.date.year, this.nextEtaModel.date.month, this.nextEtaModel.date.day) : null;
// Checking for sequence errors between prev and current port of call
if (prevEtdDate && this.etaModel) {
this.prevEtdIsAfterCurrentEtaError = prevEtdDate.after(this.etaModel.date);
if (prevEtdDate.equals(this.etaModel.date)) {
this.prevEtdIsAfterCurrentEtaError = this.prevEtdModel.time.hour > this.etaModel.time.hour
|| (this.prevEtdModel.time.hour === this.etaModel.time.hour
&& this.prevEtdModel.time.minute >= this.etaModel.time.minute);
}
} else {
this.prevEtdIsAfterCurrentEtaError = false;
}
// Checking for sequence errors between next and current port of call
if (nextEtaDate && this.etdModel) {
this.nextEtaIsBeforeCurrentEtdError = nextEtaDate.before(this.etdModel.date);
private validateData() {
if (this.etaEtdModel.eta && this.etaEtdModel.etd) {
const etaDate = new NgbDate(this.etaEtdModel.eta.date.year, this.etaEtdModel.eta.date.month, this.etaEtdModel.eta.date.day);
const etdDate = new NgbDate(this.etaEtdModel.etd.date.year, this.etaEtdModel.etd.date.month, this.etaEtdModel.etd.date.day);
this.dateSequenceError = etdDate.before(etaDate);
if (etdDate.equals(etaDate)) {
this.timeSequenceError = this.etaEtdModel.eta.time.hour > this.etaEtdModel.etd.time.hour
|| (this.etaEtdModel.eta.time.hour === this.etaEtdModel.etd.time.hour
&& this.etaEtdModel.eta.time.minute >= this.etaEtdModel.etd.time.minute);
} else {
this.timeSequenceError = false;
}
} else {
this.dateSequenceError = false;
this.timeSequenceError = false;
}
this.persistData();
}
private dateStringToDateTime(dateString) {
const date = new Date(dateString);
const dateTime: DateTime = {
date: new NgbDate(date.getFullYear(), date.getMonth() + 1, date.getDate()),
time: new NgbTime(date.getHours(), date.getMinutes(), 0)
};
return dateTime;
}
getNgbDateFormat(date): NgbDate {
const newDate = new NgbDate(date.getFullYear(), date.getMonth() + 1, date.getDate());
return newDate;
}
private isAfter(dt1: DateTime, dt2: DateTime) {
if (dt1.date && dt2.date) {
const dt1Date = new NgbDate(dt1.date.year, dt1.date.month, dt1.date.day);
const dt2Date = new NgbDate(dt2.date.year, dt2.date.month, dt2.date.day);
if (dt1Date.after(dt2Date)) {
return true;
}
if (dt1Date.equals(dt2Date)) {
if (dt1.time.hour > dt2.time.hour || (dt1.time.hour === dt2.time.hour && dt1.time.minute >= dt2.time.minute)) {
return true;
}
}
}
return false;
}
private validateData() {
if (this.etaEtdModel.eta && this.etaEtdModel.etd) {
const etaDate = new NgbDate(this.etaEtdModel.eta.date.year, this.etaEtdModel.eta.date.month, this.etaEtdModel.eta.date.day);
const etdDate = new NgbDate(this.etaEtdModel.etd.date.year, this.etaEtdModel.etd.date.month, this.etaEtdModel.etd.date.day);
this.dateSequenceError = etdDate.before(etaDate);
if (etdDate.equals(etaDate)) {
this.timeSequenceError = this.etaEtdModel.eta.time.hour > this.etaEtdModel.etd.time.hour
|| (this.etaEtdModel.eta.time.hour === this.etaEtdModel.etd.time.hour
&& this.etaEtdModel.eta.time.minute >= this.etaEtdModel.etd.time.minute);
} else {
this.timeSequenceError = false;
}
} else {
this.dateSequenceError = false;
this.timeSequenceError = false;
}
this.persistData();
data => {
if (data) {
const dateTime = new Date(data);
this.nextEtaModel = {
date: new NgbDate(dateTime.getFullYear(), dateTime.getMonth() + 1, dateTime.getDate()),
time: new NgbTime(dateTime.getHours(), dateTime.getMinutes(), 0)
};
} else {
this.nextEtaModel = {
date: null,
time: new NgbTime(0, 0, 0)
};
}
this.validateDateTime();
}
);
validateDateTime() {
let arrival: DateTime = null;
let departure: DateTime = null;
if (this.ataModel && this.ataModel.date) {
arrival = {
date: new NgbDate(this.ataModel.date.year, this.ataModel.date.month, this.ataModel.date.day),
time: new NgbTime(this.ataModel.time.hour, this.ataModel.time.minute, 0)
};
this.portCallModel.locationAta = new Date(arrival.date.year, arrival.date.month - 1, arrival.date.day,
arrival.time.hour, arrival.time.minute, 0);
} else {
this.portCallModel.locationAta = null;
}
if (this.atdModel && this.atdModel.date) {
departure = {
date: new NgbDate(this.atdModel.date.year, this.atdModel.date.month, this.atdModel.date.day),
time: new NgbTime(this.atdModel.time.hour, this.atdModel.time.minute, 0)
};
this.portCallModel.locationAtd = new Date(departure.date.year, departure.date.month - 1, departure.date.day,
departure.time.hour, departure.time.minute, 0);
} else {