mirror of
https://github.com/projectsend/projectsend.git
synced 2026-09-19 10:05:11 +00:00
6e47d76ba6
Client file sharing, rebuilt from the ground up: a private area per client, resumable uploads, folders, groups and categories, sharing with expiry dates and download limits, comments, file versions, an activity log, a REST API, and sixteen languages. This repository begins here. ProjectSend 2 was developed privately, and that development history is not published — the previous generation remains available, with its own history, at projectsend/legacy. Free software under the GNU General Public License v2, or (at your option) any later version.
37 lines
1.6 KiB
TypeScript
37 lines
1.6 KiB
TypeScript
import { formatCalendarDate, formatCalendarDateShort, formatDate, formatDateTime, type DateFormatOptions } from '@/lib/format-date';
|
|
import { SharedData } from '@/types';
|
|
import { usePage } from '@inertiajs/react';
|
|
|
|
/**
|
|
* Render a date the way this viewer reads dates.
|
|
*
|
|
* Locale and timezone both come off the shared props, so a component never
|
|
* threads either by hand and can never accidentally omit one — which is how
|
|
* a third of the app ended up formatting in the browser's language instead
|
|
* of the one the user picked. Every date a component shows goes through
|
|
* here, the same rule `useTranslation` has for strings.
|
|
*
|
|
* Pick by what the value *is*, not by how it should look:
|
|
*
|
|
* date / dateTime an instant (a `toIso8601String()` timestamp) — moved
|
|
* into the viewer's zone
|
|
* calendarDate a bare `YYYY-MM-DD` (an expiry, a chart's day key) —
|
|
* left exactly where it is
|
|
*
|
|
* See `lib/format-date.ts` for why conflating the two is a bug and not a
|
|
* detail.
|
|
*/
|
|
export function useFormatDate() {
|
|
const { locale, timezone } = usePage<SharedData>().props;
|
|
|
|
const options: DateFormatOptions = { locale, timeZone: timezone };
|
|
|
|
return {
|
|
date: (iso: string | null) => formatDate(iso, options),
|
|
dateTime: (iso: string | null) => formatDateTime(iso, options),
|
|
calendarDate: (date: string | null) => formatCalendarDate(date, options),
|
|
/** A calendar date trimmed for a chart axis: "12 Aug". */
|
|
calendarDateShort: (date: string | null) => formatCalendarDateShort(date, options),
|
|
};
|
|
}
|