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

POC-885: fixed Lists not getting generated due to weeks overlap in th… #1776

Merged
merged 4 commits into from
Jan 7, 2025
Merged
Changes from 1 commit
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
Next Next commit
POC-885: fixed Lists not getting generated due to weeks overlap in th…
…e new and past year
Kipkemoii committed Jan 3, 2025
commit 8cd5b1de6acbe3db804865681ced2135e0fa50dc
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@ import { ActivatedRoute, Router } from '@angular/router';
import * as _ from 'lodash';
import { Subscription } from 'rxjs';
import { PreAppointmentOutreachResourceService } from 'src/app/etl-api/pre-appointment-outreach-resource.service';
import { getISOWeek } from 'date-fns';

interface ReportParams {
locationUuids: string;
@@ -53,7 +54,7 @@ export class PreAppointmentOutreachComponent implements OnInit {
private route: ActivatedRoute
) {
const today = new Date();
const currentWeek = this.getISOWeek(today);
const currentWeek = getISOWeek(today);
const currentYear = today.getFullYear();
const startYear = 2023;
const numberOfWeeks = 52; // Set the maximum number of weeks to 52
@@ -86,7 +87,7 @@ export class PreAppointmentOutreachComponent implements OnInit {
public setSelectedWeek() {
this.selectedFormattedWeek = this.weeks.find(
(week) => week.value === this.selectedWeek
).label;
);
}

public setSelectedFilterType() {
@@ -362,20 +363,21 @@ export class PreAppointmentOutreachComponent implements OnInit {
);
}

private getISOWeek(date: Date): number {
const firstDayOfYear = new Date(date.getFullYear(), 0, 1);
const daysOffset = firstDayOfYear.getDay() - 1;
const firstMondayOfYear = new Date(
firstDayOfYear.getFullYear(),
0,
1 + (daysOffset > 0 ? 7 - daysOffset : 0)
);
// private getISOWeek(date: Date): number {
// const firstDayOfYear = new Date(date.getFullYear(), 0, 1);
// console.log('current dY OF THE YEAR: ', firstDayOfYear);
// const daysOffset = firstDayOfYear.getDay() - 1;
// const firstMondayOfYear = new Date(
// firstDayOfYear.getFullYear(),
// 0,
// 1 + (daysOffset > 0 ? 7 - daysOffset : 0)
// );

const daysPassed = Math.floor(
(date.getTime() - firstMondayOfYear.getTime()) / 86400000
);
const weeksPassed = Math.floor(daysPassed / 7) + 1;
// const daysPassed = Math.floor(
// (date.getTime() - firstMondayOfYear.getTime()) / 86400000
// );
// const weeksPassed = Math.floor(daysPassed / 7) + 1;

return weeksPassed;
}
// return weeksPassed;
// }
}