Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEVOPS-125 Fix for Number of support days #2546

Merged
merged 5 commits into from
Jan 7, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -498,9 +498,21 @@ export class SupportDetailsComponent implements OnInit, OnDestroy {
*/
updateValidToDate(days?: number): void {
const currentVal = this.supportDetailsForm.get('fromDate').value;
const currentSupportType = this.stepSupportsService.supportTypeToAdd.value;
if (days !== null && currentVal !== '') {
const date = new Date(currentVal);
const finalValue = this.datePipe.transform(date.setDate(date.getDate() + days), 'MM/dd/yyyy');
const fromTime = this.supportDetailsForm.get('fromTime').value;
const afterMidnightBeforeSix = this.isTimeBetween(fromTime, '00:00:00', '06:00:00');
let totalDays = days;
if (
afterMidnightBeforeSix &&
(currentSupportType === SupportSubCategory.Lodging_Hotel ||
currentSupportType === SupportSubCategory.Lodging_Allowance ||
currentSupportType === SupportSubCategory.Lodging_Group)
) {
totalDays -= 1;
}
const finalValue = this.datePipe.transform(date.setDate(date.getDate() + totalDays), 'MM/dd/yyyy');
this.supportDetailsForm.get('toDate').patchValue(new Date(finalValue));
}
}
Expand All @@ -513,9 +525,22 @@ export class SupportDetailsComponent implements OnInit, OnDestroy {
updateToDate(event: MatDatepickerInputEvent<Date>) {
const days = this.supportDetailsForm.get('noOfDays').value;
const currentVal = this.supportDetailsForm.get('fromDate').value;
const fromTime = this.supportDetailsForm.get('fromTime').value;
const currentSupportType = this.stepSupportsService.supportTypeToAdd.value;
const afterMidnightBeforeSix = this.isTimeBetween(fromTime, '00:00:00', '06:00:00');
const date = new Date(currentVal);
const finalValue = this.datePipe.transform(date.setDate(date.getDate() + days), 'MM/dd/yyyy');
this.supportDetailsForm.get('toDate').patchValue(new Date(finalValue));
let finalValue = this.datePipe.transform(date.setDate(date.getDate() + days), 'MM/dd/yyyy');
if (
afterMidnightBeforeSix &&
(currentSupportType === SupportSubCategory.Lodging_Hotel ||
currentSupportType === SupportSubCategory.Lodging_Allowance ||
currentSupportType === SupportSubCategory.Lodging_Group)
) {
finalValue = this.datePipe.transform(date.setDate(date.getDate() + days - 1), 'MM/dd/yyyy');
this.supportDetailsForm.get('toDate').patchValue(new Date(finalValue));
} else {
this.supportDetailsForm.get('toDate').patchValue(new Date(finalValue));
}
}

/**
Expand All @@ -525,13 +550,25 @@ export class SupportDetailsComponent implements OnInit, OnDestroy {
*/
updateNoOfDays(event: MatDatepickerInputEvent<Date>) {
const fromDate = this.datePipe.transform(this.supportDetailsForm.get('fromDate').value, 'dd-MMM-yyyy');
const fromTime = this.supportDetailsForm.get('fromTime').value;
const toDate = this.datePipe.transform(event.value, 'dd-MMM-yyyy');
const dateDiff = new Date(toDate).getTime() - new Date(fromDate).getTime();
const days = dateDiff / (1000 * 60 * 60 * 24);
const currentSupportType = this.stepSupportsService.supportTypeToAdd.value;
let days = dateDiff / (1000 * 60 * 60 * 24);

const afterMidnightBeforeSix = this.isTimeBetween(fromTime, '00:00:00', '06:00:00');

if (days > 30) {
this.supportDetailsForm.get('noOfDays').patchValue(null);
} else {
if (
afterMidnightBeforeSix &&
(currentSupportType === SupportSubCategory.Lodging_Hotel ||
currentSupportType === SupportSubCategory.Lodging_Allowance ||
currentSupportType === SupportSubCategory.Lodging_Group)
) {
days = days + 1;
}
this.supportDetailsForm.get('noOfDays').patchValue(days);
}
}
Expand Down Expand Up @@ -767,6 +804,7 @@ export class SupportDetailsComponent implements OnInit, OnDestroy {
: this.setDefaultTimes();
}
}

private createFromDate() {
let existingSupports = this.existingSupports.filter(
(x) => x.status !== SupportStatus.Cancelled.toString() && x.status !== SupportStatus.Void.toString()
Expand Down Expand Up @@ -984,4 +1022,20 @@ export class SupportDetailsComponent implements OnInit, OnDestroy {
]);
this.supportDetailsForm.get('paperSupportNumber').updateValueAndValidity();
}

private isTimeBetween(time, from, to) {
// Split the times into hours, minutes, and seconds
const [hours, minutes, seconds] = time.split(':').map(Number);
const [fromHours, fromMinutes, fromSeconds] = from.split(':').map(Number);
const [toHours, toMinutes, toSeconds] = to.split(':').map(Number);
// Create Date objects for both times
const imputTime = new Date();
imputTime.setHours(hours, minutes, seconds ? seconds : 0);
const fromTime = new Date();
fromTime.setHours(fromHours, fromMinutes, fromSeconds);
const toTime = new Date();
toTime.setHours(toHours, toMinutes, toSeconds);
//Compare the times
return imputTime >= fromTime && imputTime <= toTime;
}
}
Loading