Luxon's hasSame function for DateTimes
Luxon’s .hasSame
lets you easlity check if two DateTime
s contain the same specified time unit (such as year, month, or day).
import { DateTime } from "luxon";
const a = DateTime.local(2025, 8, 15, 10);
const b = DateTime.local(2025, 8, 15, 22);
a.hasSame(b, "day");
// true
a.hasSame(b, "hour");
// false
a.hasSame(b, "month");
// true
Tweet