-
Notifications
You must be signed in to change notification settings - Fork 78
adding time in calculations of yesterday and today #66
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -101,35 +101,26 @@ function allIncluded() { | |
endingDate = getToday(); | ||
startingDate = getLastWeek(); | ||
} | ||
|
||
function getLastWeek() { | ||
var today = new Date(); | ||
var noDays_to_goback = gsoc == 0 ? 7 : 1; | ||
var lastWeek = new Date(today.getFullYear(), today.getMonth(), today.getDate() - noDays_to_goback); | ||
var lastWeekMonth = lastWeek.getMonth() + 1; | ||
var lastWeekDay = lastWeek.getDate(); | ||
var lastWeekYear = lastWeek.getFullYear(); | ||
var lastWeekDisplayPadded = | ||
('0000' + lastWeekYear.toString()).slice(-4) + | ||
'-' + | ||
('00' + lastWeekMonth.toString()).slice(-2) + | ||
'-' + | ||
('00' + lastWeekDay.toString()).slice(-2); | ||
return lastWeekDisplayPadded; | ||
lastWeek.setHours(0, 0, 0, 0); | ||
|
||
const utc = new Date(lastWeek.getTime() + (14 * 60* 60* 1000)); | ||
|
||
return utc.toISOString().slice(0,19) + "Z"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue (complexity): Consider extracting the date transformation logic into a shared helper function to avoid repetition and improve code maintainability Extract a shared helper to handle the date transformation so you don’t repeat the setHours and offset logic. For example: function formatDateWithOffset(date, isStart) {
if (isStart) {
date.setHours(0, 0, 0, 0);
} else {
date.setHours(23, 59, 59, 999);
}
const offsetHours = 14;
const utc = new Date(date.getTime() + (offsetHours * 60 * 60 * 1000));
return utc.toISOString().slice(0, 19) + "Z";
} Then update your functions as follows: function getLastWeek() {
const today = new Date();
const daysBack = gsoc === 0 ? 7 : 1;
const lastWeek = new Date(today.getFullYear(), today.getMonth(), today.getDate() - daysBack);
return formatDateWithOffset(lastWeek, true);
}
function getToday() {
const today = new Date();
return formatDateWithOffset(today, false);
} This refactoring reduces duplication while keeping the functionality identical. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it is used in only two functions, also its a single line, I don't think a function is necessary. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll respond to the comment by the developer: While I understand your perspective that the code is used in only two functions and appears to be a single line, creating a helper function offers several benefits:
The proposed refactoring is lightweight and doesn't add unnecessary complexity. It actually simplifies the existing code by:
I recommend considering the proposed refactoring, but if you feel strongly against it, that's okay too. The most important thing is maintaining clean, understandable code. Would you like to discuss this further or share your thoughts on the suggested approach? |
||
} | ||
function getToday() { | ||
var today = new Date(); | ||
var Week = new Date(today.getFullYear(), today.getMonth(), today.getDate()); | ||
var WeekMonth = Week.getMonth() + 1; | ||
var WeekDay = Week.getDate(); | ||
var WeekYear = Week.getFullYear(); | ||
var WeekDisplayPadded = | ||
('0000' + WeekYear.toString()).slice(-4) + | ||
'-' + | ||
('00' + WeekMonth.toString()).slice(-2) + | ||
'-' + | ||
('00' + WeekDay.toString()).slice(-2); | ||
return WeekDisplayPadded; | ||
} | ||
today.setHours(23, 59, 59, 999); | ||
|
||
const utc = new Date(today.getTime() + (14 * 60 * 60 * 1000)); | ||
Comment on lines
+117
to
+119
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: Review the repetitive pattern of applying a timezone offset. Both getLastWeek() and getToday() apply the same 14-hour offset adjustment. It might be worthwhile to refactor this repeated logic into a shared helper function for clarity and maintainability. Suggested implementation: // Helper function to apply a 14-hour timezone offset and format the date as ISO string
function applyTimezoneOffset(date) {
const offsetInMilliseconds = 14 * 60 * 60 * 1000;
const utcDate = new Date(date.getTime() + offsetInMilliseconds);
return utcDate.toISOString().slice(0, 19) + "Z";
} today.setHours(23, 59, 59, 999);
return applyTimezoneOffset(today);
} You should also update the getLastWeek() function (if it uses the same pattern) in a similar fashion by replacing its 14-hour offset logic with a call to applyTimezoneOffset(). |
||
|
||
return utc.toISOString().slice(0, 19) + "Z"; | ||
} | ||
|
||
// fetch github data | ||
function fetchGithubData() { | ||
var issueUrl = | ||
|
@@ -185,6 +176,30 @@ function allIncluded() { | |
githubUserData = data; | ||
}, | ||
}); | ||
filterAndStoreData(); | ||
} | ||
|
||
function filterDataByDate(data, startingDate, endingDate){ | ||
|
||
const localStart = new Date(startingDate + 'T00:00:00Z'); | ||
const localEnd = new Date(endingDate + 'T23:59:59Z'); | ||
|
||
return data.items.filter(item => { | ||
const updatedAt = new Date(item.updated_at); | ||
return updatedAt >= localStart && updatedAt <= localEnd; | ||
}) | ||
} | ||
|
||
function filterAndStoreData() { | ||
if(githubIssuesData) { | ||
githubIssuesData.items = filterDataByDate(githubIssuesData, startingDate, endingDate); | ||
} | ||
if(githubPrsReviewData) { | ||
githubPrsReviewData.items = filterDataByDate(githubPrsReviewData, startingDate, endingDate); | ||
} | ||
if(githubUserData) { | ||
githubUserData.items = filterDataByDate(githubUserData, startingDate, endingDate); | ||
} | ||
} | ||
|
||
function formatDate(dateString) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: Reconsider duplicated date formatting logic in getToday().
getToday() in main.js manually formats the date after adjusting with the offset, while scrumHelper.js uses toISOString slicing. Aligning these approaches (potentially via a common utility function) could improve consistency and reduce potential formatting discrepancies.