Skip to content

armgit / ente

Public Imported from GitHub
0

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

Another

Manav Rathi6724527c2788
diff --git a/web/apps/accounts/src/pages/passkeys/index.tsx b/web/apps/accounts/src/pages/passkeys/index.tsx
index 629b824135..d6d501d554 100644
--- a/web/apps/accounts/src/pages/passkeys/index.tsx
+++ b/web/apps/accounts/src/pages/passkeys/index.tsx
@@ -11,9 +11,9 @@ import { Titlebar } from "@/base/components/Titlebar";
import { errorDialogAttributes } from "@/base/components/utils/dialog";
import { useModalVisibility } from "@/base/components/utils/modal";
import { useBaseContext } from "@/base/context";
+import { formattedDateTime } from "@/base/i18n-date";
import log from "@/base/log";
import SingleInputForm from "@ente/shared/components/SingleInputForm";
-import { formatDateTimeFull } from "@ente/shared/time/format";
import CalendarTodayIcon from "@mui/icons-material/CalendarToday";
import ChevronRightIcon from "@mui/icons-material/ChevronRight";
import DeleteIcon from "@mui/icons-material/Delete";
@@ -293,7 +293,9 @@ const ManagePasskeyDrawer: React.FC<ManagePasskeyDrawerProps> = ({
onRootClose={onClose}
/>
<CreatedAtEntry>
- {formatDateTimeFull(passkey.createdAt / 1000)}
+ {formattedDateTime(
+ new Date(passkey.createdAt / 1000),
+ )}
</CreatedAtEntry>
<RowButtonGroup>
<RowButton
diff --git a/web/packages/base/i18n-date.ts b/web/packages/base/i18n-date.ts
index 2a8e21f95f..b23fed67f0 100644
--- a/web/packages/base/i18n-date.ts
+++ b/web/packages/base/i18n-date.ts
@@ -4,7 +4,7 @@
* Note that we rely on the current behaviour of a full reload on changing the
* language. See: [Note: Changing locale causes a full reload].
*/
-import i18n from "i18next";
+import i18n, { t } from "i18next";
const _dateFormat = new Intl.DateTimeFormat(i18n.language, {
weekday: "short",
@@ -46,6 +46,17 @@ const isSameYear = (date: Date) =>
*/
export const formattedTime = (date: Date) => _timeFormat.format(date);
+/**
+ * Return a locale aware formatted date and time from the given {@link Date},
+ * using the year omission behavior as documented in {@link formattedDate}.
+ *
+ * Example:
+ * - If within year: "Fri, 21 Feb at 11:51 AM".
+ * - Otherwise: "Fri, 21 Feb 2025 at 11:51 AM"
+ */
+export const formattedDateTime = (date: Date) =>
+ [formattedDate(date), t("at"), formattedTime(date)].join(" ");
+
let _relativeTimeFormat: Intl.RelativeTimeFormat | undefined;
export const formattedDateRelative = (date: Date) => {
diff --git a/web/packages/shared/time/format.ts b/web/packages/shared/time/format.ts
index 06638a66c6..bce4644699 100644
--- a/web/packages/shared/time/format.ts
+++ b/web/packages/shared/time/format.ts
@@ -36,9 +36,9 @@ function formatTime(date: number | Date) {
return timeFormatter.format(date).toUpperCase();
}
-export function formatDateTimeFull(dateTime: number | Date): string {
- return [formatDateFull(dateTime), t("at"), formatTime(dateTime)].join(" ");
-}
+// function formatDateTimeFull(dateTime: number | Date): string {
+// return [formatDateFull(dateTime), t("at"), formatTime(dateTime)].join(" ");
+// }
export function formatDateTime(dateTime: number | Date): string {
return [formatDate(dateTime), t("at"), formatTime(dateTime)].join(" ");