Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Locked learning resources

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Porting the Reminder Script

You ported Larkspur Physio’s reminder report from Python to JavaScript. The report reads the clinic’s export, keeps the coming week’s appointments, orders them, and prints each patient’s appointment and reminder in their own zone. The clinician totals are the next exercise’s task.

  • Keep the clinic zone as a region name, the week as a seven-day duration, and the reminder lead as one calendar day. The formatting options replace Python’s format pattern.
  • Parse the export once. clinicTime() reads each UTC timestamp as an Instant and converts it to the clinic’s London zone. Mapping copies the other appointment fields.
  • Use the static Temporal.ZonedDateTime.compare() method for both ends of the week and for sorting the start fields. The opening boundary is inclusive; the ending boundary is exclusive.
  • Change to the patient’s zone for the printed label and reminder. Check the closed day against the appointment’s London date with .equals(). A closed booking skips both its reminder and its booked-time contribution.
  • subtract({ days: 1 }) preserves the intended local reminder time across the New York clock change. The locale chooses the wording; the zoned value supplies the time zone.
  • The header formats the supplied run clock. The fixed Thursday check shows 08:00 in both London and UTC.
  • The map accumulates each clinician’s booked minutes. The daily entry point calls Temporal.Now.zonedDateTimeISO("UTC") to read the current moment in UTC, matching Python’s run clock. The separate check supplies a fixed Thursday morning instead.

Save this port as reminders.js in your existing ~/reminders folder. Its package.json contains { "type": "module" }. The complete port so far is below.

The complete reminders.js so far

Here is the complete file so far:

Language: JavaScript Filename: reminders.js
/**
 * Print the clinic's weekly appointment reminders.
 */

const CLINIC_ZONE = "Europe/London";
const WEEK = Temporal.Duration.from({ days: 7 });
const REMINDER_LEAD = { days: 1 };
const TIME_FORMAT = {
  weekday: "long",
  day: "2-digit",
  month: "long",
  hour: "2-digit",
  minute: "2-digit",
};
const ZONES = {
  "Fiona Mackay": "Europe/London",
  "Dana Whitfield": "America/New_York",
  "Jonas Becker": "Europe/Berlin",
  "Isla Grant": "Europe/London",
  "Callum Reid": "America/New_York",
};
const EXPORT_TEXT = `{
  "closed": "2026-11-03",
  "appointments": [
    {
      "patient": "Dana Whitfield",
      "clinician": "Callum Reid",
      "start": "2026-11-01T15:00:00Z",
      "minutes": 50
    },
    {
      "patient": "Fiona Mackay",
      "clinician": "Isla Grant",
      "start": "2026-10-30T09:30:00Z",
      "minutes": 50
    },
    {
      "patient": "Jonas Becker",
      "clinician": "Isla Grant",
      "start": "2026-11-02T16:00:00Z",
      "minutes": 50
    },
    {
      "patient": "Fiona Mackay",
      "clinician": "Isla Grant",
      "start": "2026-11-03T11:00:00Z",
      "minutes": 50
    },
    {
      "patient": "Dana Whitfield",
      "clinician": "Callum Reid",
      "start": "2026-10-30T17:00:00Z",
      "minutes": 30
    },
    {
      "patient": "Jonas Becker",
      "clinician": "Isla Grant",
      "start": "2026-11-05T09:00:00Z",
      "minutes": 50
    }
  ]
}`;

function clinicTime(text) {
  return Temporal.Instant.from(text)
    .toZonedDateTimeISO(CLINIC_ZONE);
}

export function main(now) {
  const data = JSON.parse(EXPORT_TEXT);
  const closed = Temporal.PlainDate.from(data.closed);
  const weekEnd = now.add(WEEK);
  const week = data.appointments
    .map(appt => ({
      ...appt,
      start: clinicTime(appt.start),
    }))
    .filter(appt =>
      Temporal.ZonedDateTime.compare(now, appt.start) <= 0
      && Temporal.ZonedDateTime.compare(
        appt.start, weekEnd,
      ) < 0
    )
    .toSorted((a, b) =>
      Temporal.ZonedDateTime.compare(a.start, b.start)
    );
  const heading = now.toLocaleString("en-GB", TIME_FORMAT);
  console.log(`Reminders for the week from ${heading}`);
  const booked = new Map();
  for (const appt of week) {
    const start = appt.start.withTimeZone(ZONES[appt.patient]);
    const when = start.toLocaleString("en-GB", TIME_FORMAT);
    const label = `${appt.patient}: ${when}`;
    if (appt.start.toPlainDate().equals(closed)) {
      console.log(`${label}, clinic closed: rebook`);
      continue;
    }
    const reminder = start.subtract(REMINDER_LEAD);
    const due = reminder.toLocaleString("en-GB", TIME_FORMAT);
    console.log(`${label}, reminder ${due}`);
    const clinician = appt.clinician;
    const total = booked.get(clinician) ?? new Temporal.Duration();
    booked.set(clinician, total.add({ minutes: appt.minutes }));
  }
  // Add the booked-time lines in the exercise.
}

if (import.meta.main) {
  main(Temporal.Now.zonedDateTimeISO("UTC"));
}

This brings the reminder report together in one file.

To check the same Thursday-morning run as Python, save this separate caller as check-reminders.js in the same folder. Importing the script doesn’t run its daily entry point:

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

00:00 You’ll port Larkspur Physio’s reminder script as the booking system moves to JavaScript. The Python script reads six bookings, checks the clinic’s closed day and prints each patient’s local times.

00:14 Assemble the pieces you’ve practiced, then check the first six lines. The booked-time display is your next task. The settings keep their roles: a zone name, seven-day duration, and one-day reminder.

00:32 The format pattern becomes an options object.

00:41 Quoted keys keep full names.

00:53 Backticks hold the exported text.

00:59 The documentation becomes a JSDoc comment. Temporal is built in here, so the Python imports go. In JavaScript, parse the JSON, then map each record to a copy with a clinic-zoned start.

01:15 The helper reads an Instant before attaching London’s zone, as before; a UTC string alone isn’t a zoned value. The spread keeps the other fields, and parentheses return the new object.

01:30 The window starts at the supplied run time and ends seven calendar days later. Python chains comparisons; JavaScript calls the static comparison method twice, joining its numeric tests with &&.

01:44 Temporal values don’t use ordinary ordering operators, as before. The fifth of November booking misses the window, leaving five appointments.

01:56 Python sorts by start. JavaScript’s comparator compares two records’ starts; the sorted copy begins with Fiona’s Friday session. The header uses the supplied run clock.

02:10 Call the zoned value’s locale method directly, as before; handing that value to Intl.DateTimeFormat() isn’t the route used here. The patient lookup supplies a zone for the same moment’s local view.

02:24 British wording doesn’t choose the time zone. The closure check uses the clinic’s London date. Use date equality, as before, rather than object identity. Fiona’s Tuesday booking is marked for rebooking and skipped.

02:42 The reminder goes one calendar day before the patient’s appointment. Python’s subtraction keeps the local time here; JavaScript spells that intent with days, as before, rather than twenty-four hours.

02:56 Dana’s Sunday session keeps Saturday at ten as its reminder across New York’s clock change. Format both values and print the line. The Map holds booked time by clinician.

03:11 A missing entry gets a zero duration from the question-mark fallback. Add the appointment’s minutes and store the duration it returns. Isla’s first entry holds fifty minutes.

03:24 Closed bookings bypass this block; displaying the totals remains your exercise.

03:31 The function accepts its run time for repeatable checks. The direct-run guard keeps importing the file from running the report. For the daily run, the Temporal.Now object reads the current moment in Coordinated Universal Time, or UTC, matching Python’s run clock.

03:50 Pass that value into main() for the report. The syntax check prints nothing on success. A separate caller supplies the fixed Thursday. Import brings the exported main() from the neighboring file.

04:07 Callum runs that caller in New York. Does Dana’s Friday reminder line change? Your turn: pause the video and predict the result.

04:21 No. Both runs show Thursday at thirteen hundred.

04:27 Both reports have the same header and five appointment lines. Patient zones choose the clock, the clinic’s date chooses rebooking, and calendar days choose reminders.

04:39 The port assembles those choices in one script. Next up is Finish the Reminder Script. Add each clinician’s booked-time lines for this week and a second week.

Become a Member to join the conversation.