This commit is contained in:
Manav Rathi
2025-02-21 12:44:27 +05:30
parent 6724527c27
commit e8d9f4f6cf
4 changed files with 21 additions and 4 deletions

View File

@@ -293,9 +293,7 @@ const ManagePasskeyDrawer: React.FC<ManagePasskeyDrawerProps> = ({
onRootClose={onClose}
/>
<CreatedAtEntry>
{formattedDateTime(
new Date(passkey.createdAt / 1000),
)}
{formattedDateTime(passkey.createdAt)}
</CreatedAtEntry>
<RowButtonGroup>
<RowButton

View File

@@ -1,6 +1,8 @@
/**
* Convert an epoch microsecond value to a JavaScript date.
*
* [Note: Remote timestamps are epoch microseconds]
*
* This is a convenience API for dealing with optional epoch microseconds in
* various data structures. Remote talks in terms of epoch microseconds, but
* JavaScript dates are underlain by epoch milliseconds, and this does a

View File

@@ -53,10 +53,25 @@ export const formattedTime = (date: Date) => _timeFormat.format(date);
* Example:
* - If within year: "Fri, 21 Feb at 11:51 AM".
* - Otherwise: "Fri, 21 Feb 2025 at 11:51 AM"
*
* @param dateOrEpochMicroseconds A JavaScript Date or a numeric epoch
* microseconds value.
*
* As a convenience, this function can be either be directly passed a JavaScript
* date, or it can be given the raw epoch microseconds value and it'll convert
* internally.
*
* See: [Note: Remote timestamps are epoch microseconds]
*/
export const formattedDateTime = (date: Date) =>
export const formattedDateTime = (dateOrEpochMicroseconds: Date | number) =>
_formattedDateTime(toDate(dateOrEpochMicroseconds));
const _formattedDateTime = (date: Date) =>
[formattedDate(date), t("at"), formattedTime(date)].join(" ");
const toDate = (dm: Date | number) =>
typeof dm == "number" ? new Date(dm / 1000) : dm;
let _relativeTimeFormat: Intl.RelativeTimeFormat | undefined;
export const formattedDateRelative = (date: Date) => {

View File

@@ -134,6 +134,8 @@ export const setupI18n = async () => {
// Value is an epoch microsecond so that we can directly pass the
// timestamps we get from our API responses. The formatter expects
// milliseconds, so divide by 1000.
//
// See [Note: Remote timestamps are epoch microseconds].
return (val) => formatter.format(val / 1000);
});
};