Comparing and Sorting Appointments

The export lists appointments in booking order, so Dana’s Sunday comes before Fiona’s Friday. Python filters appointments for the week with if now <= start < now + WEEK and orders them with week.sort(key=lambda appt: appt["start"]). The port now has zoned start times, and it needs the same five appointments in time order.

Add a Week to a ZonedDateTime

clinicTime() wraps the two calls from the previous lesson, reading an Instant and converting it to London time. A Duration from Temporal.Duration.from({ days: 7 }) plays the part of timedelta(days=7), and .add() returns a new value, as datetime + timedelta does. Durations get their own lesson later. Save this as compare.js in ~/reminders and run it with node compare.js:

Language: JavaScript
const CLINIC_ZONE = "Europe/London";

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

const now = clinicTime("2026-10-29T08:00:00Z");
const WEEK = Temporal.Duration.from({ days: 7 });
const weekEnd = now.add(WEEK);
console.log(`${weekEnd}`);

The week ends at eight on Thursday morning in London:

Language: Program Output
2026-11-05T08:00:00+00:00[Europe/London]

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

Become a Member to join the conversation.