freeCodeCamp icon indicating copy to clipboard operation
freeCodeCamp copied to clipboard

fix(curriculum): expected dates includes <tomorrow>

Open Orkfaeller opened this issue 10 months ago • 4 comments

Checklist:

Closes #58430

Orkfaeller avatar Jan 27 '25 22:01 Orkfaeller

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

lasjorg avatar Jan 27 '25 23:01 lasjorg

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);

Orkfaeller avatar Jan 28 '25 20:01 Orkfaeller

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.

lasjorg avatar Jan 29 '25 19:01 lasjorg

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)
];

Orkfaeller avatar Jan 30 '25 17:01 Orkfaeller

Hi @Orkfaeller your last suggestion sounded pretty good. I know it's been several months, but are you able to make the change?

a2937 avatar Jul 26 '25 19:07 a2937