fix(curriculum): expected dates includes <tomorrow>
Checklist:
- [x] I have read and followed the contribution guidelines.
- [x] I have read and followed the how to open a pull request guide.
- [x] My pull request targets the
mainbranch of freeCodeCamp. - [x] I have tested these changes either locally on my machine, or GitPod.
Closes #58430
I'm fine with this change.
But I'm wondering if setting the current date in the middle value might read a little clearer? We have to set the date an extra time, but I think that is fine.
So:
Set date -1
Set current date
Set date +1
Instead of:
Set date -1
current date but not set
Set date +2
Or something like this?
const epochDay = 24 * 60 * 60 * 1000:
const today = new Date();
const yesterday = new Date(today.getTime() - epochDay);
const tomorrow = new Date(today.getTime() + epochDay);
Are you suggesting something like this?
const epochDay = 24 * 60 * 60 * 1000;
const today = new Date();
const yesterday = new Date(today.getTime() - epochDay);
const tomorrow = new Date(today.getTime() + epochDay);
const expectedDates = [
new Date(yesterday).toLocaleDateString("en-US", {
timeZone: "UTC", weekday: "short", month: "short",
day: "2-digit", year: "numeric"
}).replaceAll(',', ''),
new Date(today).toLocaleDateString("en-US", {
timeZone: "UTC", weekday: "short", month: "short",
day: "2-digit", year: "numeric"
}).replaceAll(',', ''),
new Date(tomorrow).toLocaleDateString("en-US", {
timeZone: "UTC", weekday: "short", month: "short",
day: "2-digit", year: "numeric"
}).replaceAll(',', '')
];
I would be fine with that. As long as it is clear what the three dates are, and we avoid "magic" numbers.
I don't think we even need to use the new Date() constructur in the array anymore, since yesterday, today and tomorrow already are dates. While at it, it probably makes sense to create a function for formatting the dates instead of repeating the same code three tiems.
// 24 hours * 60 minutes * 60 seconds * 1000 ms
const epochDay = 24 * 60 * 60 * 1000;
const today = new Date();
const yesterday = new Date(today.getTime() - epochDay);
const tomorrow = new Date(today.getTime() + epochDay);
const dateAsLocaleUSString = (date) => date.toLocaleDateString("en-US", {
timeZone: "UTC", weekday: "short", month: "short",
day: "2-digit", year: "numeric"
}).replaceAll(',', '')
const expectedDates = [
dateAsLocaleUSString(yesterday),
dateAsLocaleUSString(today),
dateAsLocaleUSString(tomorrow)
];
Hi @Orkfaeller your last suggestion sounded pretty good. I know it's been several months, but are you able to make the change?