getEachLatestDate
与えられた日時のリストから、各日付で最新のものだけを一つづつ取り出したリストを作る
custom-new-pageのformatで、切り出し内容の更新日時を日付タグにするときに使う
code:mod.ts
import { isSameDay, getYear, getMonth, getDate } from "../date-fns/mod.ts";
export const getEachLatestDate = (dates: Date[]): Date[] => {
const map = new Map<${number}-${number}-${number}, Date>();
for (const date of dates) {
const key = ${getYear(date)}-${getMonth(date)}-${getDate(date)} as const;
const sameDate = map.get(key);
if (sameDate && sameDate.getTime() > date.getTime()) continue;
map.set(key, date);
}
return ...map.values();
};
#2024-04-19
#2023-02-04 14:41:51
#2023-02-03 21:52:58
#2022-04-07 06:40:09