Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

make static formatters

Abhinav4a1c2e2c7952
diff --git a/apps/photos/src/utils/time/format.ts b/apps/photos/src/utils/time/format.ts
index 6b3e6c8fec..59caefa807 100644
--- a/apps/photos/src/utils/time/format.ts
+++ b/apps/photos/src/utils/time/format.ts
@@ -1,57 +1,48 @@
import i18n, { t } from 'i18next';
-export function formatDateFull(date: number | Date) {
- const dateTimeFormat1 = new Intl.DateTimeFormat(i18n.language, {
- weekday: 'short',
- month: 'short',
- day: 'numeric',
- });
+const dateTimeFullFormatter1 = new Intl.DateTimeFormat(i18n.language, {
+ weekday: 'short',
+ month: 'short',
+ day: 'numeric',
+});
- const dateTimeFormat2 = new Intl.DateTimeFormat(i18n.language, {
- year: 'numeric',
- });
+const dateTimeFullFormatter2 = new Intl.DateTimeFormat(i18n.language, {
+ year: 'numeric',
+});
+const dateTimeShortFormatter = new Intl.DateTimeFormat(i18n.language, {
+ month: 'short',
+ day: 'numeric',
+ year: 'numeric',
+ hour: '2-digit',
+ minute: '2-digit',
+});
- return [dateTimeFormat1, dateTimeFormat2]
+const timeFormatter = new Intl.DateTimeFormat(i18n.language, {
+ timeStyle: 'short',
+});
+
+export function formatDateFull(date: number | Date) {
+ return [dateTimeFullFormatter1, dateTimeFullFormatter2]
.map((f) => f.format(date))
.join(' ');
}
export function formatDate(date: number | Date) {
- const dateTimeFormat1 = new Intl.DateTimeFormat(i18n.language, {
- weekday: 'short',
- month: 'short',
- day: 'numeric',
- });
const withinYear =
new Date().getFullYear() === new Date(date).getFullYear();
- const dateTimeFormat2 = !withinYear
- ? new Intl.DateTimeFormat(i18n.language, {
- year: 'numeric',
- })
- : null;
- return [dateTimeFormat1, dateTimeFormat2]
+ const dateTimeFormat2 = !withinYear ? dateTimeFullFormatter2 : null;
+ return [dateTimeFullFormatter1, dateTimeFormat2]
.filter((f) => !!f)
.map((f) => f.format(date))
.join(' ');
}
export function formatDateTimeShort(date: number | Date) {
- const dateTimeFormat = new Intl.DateTimeFormat(i18n.language, {
- month: 'short',
- day: 'numeric',
- year: 'numeric',
- hour: '2-digit',
- minute: '2-digit',
- });
-
- return dateTimeFormat.format(date);
+ return dateTimeShortFormatter.format(date);
}
export function formatTime(date: number | Date) {
- const timeFormat = new Intl.DateTimeFormat(i18n.language, {
- timeStyle: 'short',
- });
- return timeFormat.format(date).toUpperCase();
+ return timeFormatter.format(date).toUpperCase();
}
export function formatDateTimeFull(dateTime: number | Date): string {