feat(reporting): enhance date range handling in reporting allocation

- Added support for 'LAST_7_DAYS' and 'LAST_30_DAYS' date ranges in the reporting allocation logic.
- Updated date parsing to convert input dates to UTC while preserving the intended local date.
- Included console logs for debugging date values during processing.
This commit is contained in:
chamiakJ
2025-05-20 07:59:49 +05:30
parent 34613e5e0c
commit 1dade05f54
2 changed files with 19 additions and 2 deletions

View File

@@ -412,8 +412,14 @@ export default class ReportingAllocationController extends ReportingControllerBa
let startDate: moment.Moment;
let endDate: moment.Moment;
if (date_range && date_range.length === 2) {
startDate = moment(date_range[0]);
endDate = moment(date_range[1]);
// Parse dates and convert to UTC while preserving the intended local date
startDate = moment(date_range[0]).utc().startOf('day');
endDate = moment(date_range[1]).utc().endOf('day');
console.log("Original start date:", date_range[0]);
console.log("Original end date:", date_range[1]);
console.log("UTC startDate:", startDate.format());
console.log("UTC endDate:", endDate.format());
} else if (duration === DATE_RANGES.ALL_TIME) {
// Fetch the earliest start_date (or created_at if null) from selected projects
const minDateQuery = `SELECT MIN(COALESCE(start_date, created_at)) as min_date FROM projects WHERE id IN (${projectIds})`;
@@ -427,10 +433,18 @@ export default class ReportingAllocationController extends ReportingControllerBa
startDate = moment().subtract(1, "day");
endDate = moment().subtract(1, "day");
break;
case DATE_RANGES.LAST_7_DAYS:
startDate = moment().subtract(7, "days");
endDate = moment();
break;
case DATE_RANGES.LAST_WEEK:
startDate = moment().subtract(1, "week").startOf("isoWeek");
endDate = moment().subtract(1, "week").endOf("isoWeek");
break;
case DATE_RANGES.LAST_30_DAYS:
startDate = moment().subtract(30, "days");
endDate = moment();
break;
case DATE_RANGES.LAST_MONTH:
startDate = moment().subtract(1, "month").startOf("month");
endDate = moment().subtract(1, "month").endOf("month");
@@ -480,6 +494,7 @@ export default class ReportingAllocationController extends ReportingControllerBa
if (orgWorkingDays[weekday]) workingDays++;
current.add(1, 'day');
}
console.log("workingDays", workingDays);
// Use organization working hours for total working hours
const totalWorkingHours = workingDays * orgWorkingHours;

View File

@@ -166,7 +166,9 @@ export const UNMAPPED = "Unmapped";
export const DATE_RANGES = {
YESTERDAY: "YESTERDAY",
LAST_7_DAYS: "LAST_7_DAYS",
LAST_WEEK: "LAST_WEEK",
LAST_30_DAYS: "LAST_30_DAYS",
LAST_MONTH: "LAST_MONTH",
LAST_QUARTER: "LAST_QUARTER",
ALL_TIME: "ALL_TIME"