Skip to content
Open
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
36 changes: 31 additions & 5 deletions src/scripts/scrumHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -1507,25 +1507,51 @@ ${userReason}`;
nextWeekArray.push(li2);
}

// Determine if issue was created or updated in date range
const issueCreatedDate = new Date(item.created_at);

// Get the correct date range for filtering
let startDateFilter, endDateFilter;
if (yesterdayContribution) {
const today = new Date();
const yesterday = new Date(today.getTime() - 24 * 60 * 60 * 1000);
startDateFilter = new Date(yesterday.toISOString().split('T')[0] + 'T00:00:00Z');
endDateFilter = new Date(today.toISOString().split('T')[0] + 'T23:59:59Z');
} else if (startingDate && endingDate) {
startDateFilter = new Date(startingDate + 'T00:00:00Z');
endDateFilter = new Date(endingDate + 'T23:59:59Z');
} else {
// Default to last 7 days if no date range is set
const today = new Date();
const lastWeek = new Date(today.getFullYear(), today.getMonth(), today.getDate() - 7);
startDateFilter = new Date(lastWeek.toISOString().split('T')[0] + 'T00:00:00Z');
endDateFilter = new Date(today.toISOString().split('T')[0] + 'T23:59:59Z');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (bug_risk): Subtracting days using Date constructor can yield unexpected results at month boundaries.

Date arithmetic using the Date constructor can fail at month boundaries. Use getTime() subtraction for consistent results.

Suggested change
const lastWeek = new Date(today.getFullYear(), today.getMonth(), today.getDate() - 7);
startDateFilter = new Date(lastWeek.toISOString().split('T')[0] + 'T00:00:00Z');
endDateFilter = new Date(today.toISOString().split('T')[0] + 'T23:59:59Z');
const lastWeek = new Date(today.getTime() - 7 * 24 * 60 * 60 * 1000);
startDateFilter = new Date(lastWeek.toISOString().split('T')[0] + 'T00:00:00Z');
endDateFilter = new Date(today.toISOString().split('T')[0] + 'T23:59:59Z');

}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (bug_risk): Date construction using string manipulation may introduce timezone inconsistencies.

This approach may cause bugs when local dates cross midnight or during daylight saving changes. Use UTC-based methods or a date library for consistent results.

Suggested change
if (yesterdayContribution) {
const today = new Date();
const yesterday = new Date(today.getTime() - 24 * 60 * 60 * 1000);
startDateFilter = new Date(yesterday.toISOString().split('T')[0] + 'T00:00:00Z');
endDateFilter = new Date(today.toISOString().split('T')[0] + 'T23:59:59Z');
} else if (startingDate && endingDate) {
startDateFilter = new Date(startingDate + 'T00:00:00Z');
endDateFilter = new Date(endingDate + 'T23:59:59Z');
} else {
// Default to last 7 days if no date range is set
const today = new Date();
const lastWeek = new Date(today.getFullYear(), today.getMonth(), today.getDate() - 7);
startDateFilter = new Date(lastWeek.toISOString().split('T')[0] + 'T00:00:00Z');
endDateFilter = new Date(today.toISOString().split('T')[0] + 'T23:59:59Z');
}
if (yesterdayContribution) {
const now = new Date();
// Get UTC date parts for today and yesterday
const todayUTC = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate()));
const yesterdayUTC = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate() - 1));
startDateFilter = new Date(Date.UTC(yesterdayUTC.getUTCFullYear(), yesterdayUTC.getUTCMonth(), yesterdayUTC.getUTCDate(), 0, 0, 0));
endDateFilter = new Date(Date.UTC(todayUTC.getUTCFullYear(), todayUTC.getUTCMonth(), todayUTC.getUTCDate(), 23, 59, 59));
} else if (startingDate && endingDate) {
// Parse startingDate and endingDate as UTC
const [startYear, startMonth, startDay] = startingDate.split('-').map(Number);
const [endYear, endMonth, endDay] = endingDate.split('-').map(Number);
startDateFilter = new Date(Date.UTC(startYear, startMonth - 1, startDay, 0, 0, 0));
endDateFilter = new Date(Date.UTC(endYear, endMonth - 1, endDay, 23, 59, 59));
} else {
// Default to last 7 days if no date range is set
const now = new Date();
const todayUTC = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate()));
const lastWeekUTC = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate() - 7));
startDateFilter = new Date(Date.UTC(lastWeekUTC.getUTCFullYear(), lastWeekUTC.getUTCMonth(), lastWeekUTC.getUTCDate(), 0, 0, 0));
endDateFilter = new Date(Date.UTC(todayUTC.getUTCFullYear(), todayUTC.getUTCMonth(), todayUTC.getUTCDate(), 23, 59, 59));
}


const isNewIssue = issueCreatedDate >= startDateFilter && issueCreatedDate <= endDateFilter;
const issueAction = isNewIssue ? 'Opened Issue' : 'Updated Issue';

log(`[ISSUE DEBUG] Issue #${number} - isNewIssue: ${isNewIssue}, issueAction: ${issueAction}, state: ${item.state}, created: ${item.created_at}, updated: ${item.updated_at}`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Consider removing or gating debug logging for production environments.

Debug logs in production can expose sensitive data and create unnecessary noise. If these logs are only needed for development, use a conditional or appropriate logging level to prevent them from appearing in production.

Suggested change
log(`[ISSUE DEBUG] Issue #${number} - isNewIssue: ${isNewIssue}, issueAction: ${issueAction}, state: ${item.state}, created: ${item.created_at}, updated: ${item.updated_at}`);
if (process.env.NODE_ENV !== 'production') {
log(`[ISSUE DEBUG] Issue #${number} - isNewIssue: ${isNewIssue}, issueAction: ${issueAction}, state: ${item.state}, created: ${item.created_at}, updated: ${item.updated_at}`);
}


if (item.state === 'open') {
li = `<li><i>(${project})</i> - Opened Issue(#${number}) - <a href='${html_url}'>${title}</a>${showOpenLabel ? ' ' + issue_opened_button : ''}</li>`;
li = `<li><i>(${project})</i> - ${issueAction}(#${number}) - <a href='${html_url}'>${title}</a>${showOpenLabel ? ' ' + issue_opened_button : ''}</li>`;

} else if (item.state === 'closed') {


// Use state_reason to distinguish closure reason
if (item.state_reason === 'completed') {
li = `<li><i>(${project})</i> - Opened Issue(#${number}) - <a href='${html_url}'>${title}</a> ${issue_closed_completed_button}</li>`;
li = `<li><i>(${project})</i> - ${issueAction}(#${number}) - <a href='${html_url}'>${title}</a> ${issue_closed_completed_button}</li>`;
} else if (item.state_reason === 'not_planned') {
li = `<li><i>(${project})</i> - Opened Issue(#${number}) - <a href='${html_url}'>${title}</a> ${issue_closed_notplanned_button}</li>`;
li = `<li><i>(${project})</i> - ${issueAction}(#${number}) - <a href='${html_url}'>${title}</a> ${issue_closed_notplanned_button}</li>`;
} else {
li = `<li><i>(${project})</i> - Opened Issue(#${number}) - <a href='${html_url}'>${title}</a> ${issue_closed_button}</li>`;
li = `<li><i>(${project})</i> - ${issueAction}(#${number}) - <a href='${html_url}'>${title}</a> ${issue_closed_button}</li>`;
}


} else {
// Fallback for unexpected state
li = `<li><i>(${project})</i> - Opened Issue(#${number}) - <a href='${html_url}'>${title}</a></li>`;
li = `<li><i>(${project})</i> - ${issueAction}(#${number}) - <a href='${html_url}'>${title}</a></li>`;
}

log('[SCRUM-DEBUG] Added issue to lastWeekArray:', li, item);
Expand Down