Hacker News new | ask | show | jobs
by mstade 501 days ago
Providing comparison functions that work with existing APIs is solid design, should be required reading for any new types added really. Kudos to the designers!

    const durations = [
      Temporal.Duration.from({ hours: 1 }),
      Temporal.Duration.from({ hours: 2 }),
      Temporal.Duration.from({ hours: 1, minutes: 30 }),
      Temporal.Duration.from({ hours: 1, minutes: 45 }),
    ];

    durations.sort(Temporal.Duration.compare);
    console.log(durations.map((d) => d.toString()));
    // [ 'PT1H', 'PT1H30M', 'PT1H45M', 'PT2H' ]