mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-22 22:49:45 +01:00
29 lines
684 B
JavaScript
29 lines
684 B
JavaScript
import dayjs from "dayjs";
|
|
|
|
export function getWeekGroupFromTimestamp(timestamp) {
|
|
const date = dayjs(timestamp);
|
|
const start = date.startOf("week");
|
|
const end = date.endOf("week");
|
|
const startMonth = start.month() === end.month() ? "" : " MMM";
|
|
const startYear = start.year() === end.year() ? "" : ", YYYY";
|
|
return `${start.format(`DD${startMonth}${startYear}`)} - ${end.format(
|
|
"DD MMM, YYYY"
|
|
)}`;
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param {number} date
|
|
* @param {Intl.DateTimeFormatOptions} options
|
|
* @returns
|
|
*/
|
|
export function formatDate(
|
|
date,
|
|
options = {
|
|
dateStyle: "medium",
|
|
timeStyle: "short",
|
|
}
|
|
) {
|
|
return new Date(date).toLocaleString(undefined, options);
|
|
}
|