Larkspur Physio’s reminder script starts Thursday’s run at datetime(2026, 10, 29, 8, 0, tzinfo=UTC) in Python and keeps five appointments. You’ll port that starting point using Date, the type you’ll meet in older JavaScript code and libraries. Temporal, the modern application programming interface (API), takes over in the next course section.
Port the Week’s Filter
Create and enter the project folder in your terminal:
Save this as package.json there to make the JavaScript files ECMAScript (ES) modules:
{ "type": "module" }
Save the program below as reminders.js and keep a backup. JSON.parse() reads the export. .map() uses an arrow function, (appt) => ({...}), to return a copy of each appointment object: ...appt copies its fields, and then start becomes a Date.
.filter() keeps matches, and ${week.length} inserts their count into the template literal, like a Python f-string. The relational operators <= and < shown here compare Dates by their timestamps, and && combines the comparisons that Python chains.
Python adds a timedelta to a datetime. Here, .getTime() returns a timestamp in milliseconds, WEEK_MS supplies a week in milliseconds, and new Date(number) turns their sum into the upper-bound Date. The last line instead passes Python’s numeric date parts to new Date().
process.env.TZ sets this Node process’s zone to Isla’s London setting. Predict the count, then run node reminders.js:
process.env.TZ = "Europe/London";
const EXPORT_TEXT = `[
{"start": "2026-11-01T15:00:00Z"},
{"start": "2026-10-30T09:30:00Z"},
{"start": "2026-11-02T16:00:00Z"},
{"start": "2026-11-03T11:00:00Z"},
{"start": "2026-10-30T17:00:00Z"},
{"start": "2026-11-05T09:00:00Z"}
]`;
const appointments = JSON.parse(EXPORT_TEXT).map((appt) => ({
...appt, start: new Date(appt.start),
}));
const WEEK_MS = 7 * 24 * 60 * 60 * 1000;
function main(now) {
const weekEnd = new Date(now.getTime() + WEEK_MS);
const week = appointments.filter((appt) =>
now <= appt.start && appt.start < weekEnd
);
console.log(`${week.length} appointments this week`);
}
main(new Date(2026, 10, 29, 8, 0));
Where Python prints 5 appointments this week, JavaScript prints:
0 appointments this week
No error, and nothing kept. For each diagnostic below, replace all of reminders.js and run node reminders.js. First, inspect UTC with .toISOString():
process.env.TZ = "Europe/London";
console.log(new Date(2026, 10, 29, 8, 0).toISOString());
It’s a month late:
2026-11-29T08:00:00.000Z
The numeric constructor counts months from zero, so ten is November, a valid month. The filter looked at Sunday, November 29, past every appointment.
Read a Date as One Moment
A valid Date holds one moment as milliseconds since 1970 in UTC. The filter program adds 168 elapsed hours, matching Python’s UTC week rather than seven local calendar days across a clock change. To inspect a Date’s fields, replace Python’s attributes with JavaScript’s local-time getters:
Python datetime |
JavaScript Date |
|---|---|
.year, .day, .hour |
.getFullYear(), .getDate(), .getHours() (local) |
.month (1 to 12) |
.getMonth() (0 to 11) |
.weekday() (Monday is 0) |
.getDay() (Sunday is 0) |
.timestamp() (seconds) |
.getTime() (milliseconds) |
datetime.now(UTC) |
new Date() |
.isoformat() |
.toISOString() (always UTC) |
Date stores whole milliseconds, so Python timestamps with microseconds lose submillisecond precision when converted to Date.
The local-time getters use the process’s local zone, while their UTC counterparts read UTC fields. .getTime() reads the stored number, and Date.now() gives the current timestamp in milliseconds.
The numeric constructor uses local time too, unlike Python’s tzinfo=UTC. Check Callum’s New York setting:
process.env.TZ = "America/New_York";
const now = new Date(2026, 10, 29, 8, 0);
console.log(now.getMonth(), now.getHours(), now.toISOString());
The local getters report month index ten and eight o’clock, and UTC says thirteen:
10 8 2026-11-29T13:00:00.000Z
The local fields reflect Callum’s clock. Fix the run’s moment with an ISO 8601 timestamp whose Z means UTC. Prepend process.env.TZ = "Europe/London"; to this diagnostic, run it, then change that first line to process.env.TZ = "America/New_York"; and run it again:
const now = new Date("2026-10-29T08:00:00Z");
console.log(now.toISOString());
It prints the same moment in London and New York:
2026-10-29T08:00:00.000Z
Months in the string are numbered from one. Restore your saved filter program and replace its last line with main(new Date("2026-10-29T08:00:00Z"));. Run it with the first line set to process.env.TZ = "Europe/London";, then change that line to process.env.TZ = "America/New_York"; and rerun. Both runs print 5 appointments this week.
Two more behaviors matter when maintaining Date code:
- A day past the month’s end rolls forward:
new Date(2026, 1, 30)is March 2, whereas Python’sdatetime(2026, 2, 30)raisesValueError. - A Date changes in place, unlike Python’s immutable
datetime: afterconst start = new Date("2026-10-29T08:00:00Z");andconst end = start;,end.setDate(end.getDate() + 1)movesstarttoo because both names refer to one object.
When you need a Date for a known moment, use the extended timestamp form shown: YYYY-MM-DDTHH:mm:ssZ, optionally with .sss milliseconds before Z, or with Z replaced by a ±HH:mm offset. Its meaning stays fixed across the clinic’s laptops, and your filter keeps the intended appointments.
Next up is Reading Date Strings With Date, where you’ll read the export’s timestamps and the date-only value for the clinic’s closed day on Isla’s and Callum’s laptops. You’ll also check for invalid parsed Dates that would otherwise silently fail the filter’s comparisons.