From 3b59a8560b71045baefb0daf84325b66c54f0c28 Mon Sep 17 00:00:00 2001 From: chamiakJ Date: Tue, 20 May 2025 08:08:34 +0530 Subject: [PATCH] refactor(reporting): simplify date parsing and improve logging format - Updated date parsing to remove UTC conversion, maintaining local date context. - Enhanced console logging to display dates in 'YYYY-MM-DD' format for clarity. - Adjusted date range clause to directly use formatted dates for improved query accuracy. --- .../reporting/reporting-allocation-controller.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/worklenz-backend/src/controllers/reporting/reporting-allocation-controller.ts b/worklenz-backend/src/controllers/reporting/reporting-allocation-controller.ts index 3b949b2b..9f0ae22a 100644 --- a/worklenz-backend/src/controllers/reporting/reporting-allocation-controller.ts +++ b/worklenz-backend/src/controllers/reporting/reporting-allocation-controller.ts @@ -412,14 +412,14 @@ export default class ReportingAllocationController extends ReportingControllerBa let startDate: moment.Moment; let endDate: moment.Moment; if (date_range && date_range.length === 2) { - // Parse dates and convert to UTC while preserving the intended local date + // Parse dates without timezone startDate = moment(date_range[0]).startOf('day'); endDate = moment(date_range[1]).endOf('day'); console.log("Original start date:", date_range[0]); console.log("Original end date:", date_range[1]); - console.log("Local startDate:", startDate.format()); - console.log("Local endDate:", endDate.format()); + console.log("Start date:", startDate.format('YYYY-MM-DD')); + console.log("End date:", endDate.format('YYYY-MM-DD')); } 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})`; @@ -495,13 +495,13 @@ export default class ReportingAllocationController extends ReportingControllerBa current.add(1, 'day'); } console.log("workingDays", workingDays); - console.log("Start date for working days:", startDate.format()); - console.log("End date for working days:", endDate.format()); + console.log("Start date for working days:", startDate.format('YYYY-MM-DD')); + console.log("End date for working days:", endDate.format('YYYY-MM-DD')); // Use organization working hours for total working hours const totalWorkingHours = workingDays * orgWorkingHours; - const durationClause = this.getDateRangeClause(duration || DATE_RANGES.LAST_WEEK, date_range); + const durationClause = `AND DATE(task_work_log.created_at) >= '${startDate.format('YYYY-MM-DD')}' AND DATE(task_work_log.created_at) <= '${endDate.format('YYYY-MM-DD')}'`; const archivedClause = archived ? "" : `AND p.id NOT IN (SELECT project_id FROM archived_projects WHERE project_id = p.id AND user_id = '${req.user?.id}') `;