Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

fix: safari date parsing using dayjs CustomParseFormat

phamhieu899b70dbc138
diff --git a/studio/components/interfaces/Authentication/Users/Users.utils.ts b/studio/components/interfaces/Authentication/Users/Users.utils.ts
index 2a0684e62d3..f575d1457f9 100644
--- a/studio/components/interfaces/Authentication/Users/Users.utils.ts
+++ b/studio/components/interfaces/Authentication/Users/Users.utils.ts
@@ -1,4 +1,4 @@
-import { detectBrowser } from 'lib/helpers'
+import dayjs from 'dayjs'
/**
* Formats the user datetime string into a format that's
@@ -13,12 +13,11 @@ import { detectBrowser } from 'lib/helpers'
* Note: I've only seen this issue on the Auth page, hence why keeping
* this util here for now. But if it does happen elsewhere i'll bring it
* to lib/helpers
+ *
+ * Update 18-May-2022
+ * Ref: https://github.com/iamkun/dayjs/issues/931
+ * Instead of using the default parsing. We should use CustomParseFormat.
*/
-export const formatUserDateString = (dateString?: string) => {
- const browser = detectBrowser()
- if (browser === 'Safari') {
- return dateString?.replace(' ', 'T')
- } else {
- return dateString
- }
+export const getDateFromIsoString = (dateString?: string): dayjs.Dayjs | undefined => {
+ return dateString ? dayjs(dateString, 'YYYY-MM-DD HH:mm:ss.SSSSSSZZ') : undefined
}
diff --git a/studio/components/interfaces/Authentication/Users/UsersListItem.tsx b/studio/components/interfaces/Authentication/Users/UsersListItem.tsx
index 20a04448be1..a128f957f69 100644
--- a/studio/components/interfaces/Authentication/Users/UsersListItem.tsx
+++ b/studio/components/interfaces/Authentication/Users/UsersListItem.tsx
@@ -1,4 +1,3 @@
-import dayjs from 'dayjs'
import { FC } from 'react'
import { observer } from 'mobx-react-lite'
import { Badge } from '@supabase/ui'
@@ -6,16 +5,30 @@ import { Badge } from '@supabase/ui'
import Table from 'components/to-be-cleaned/Table'
import SimpleCodeBlock from 'components/to-be-cleaned/SimpleCodeBlock'
import UserDropdown from './UserDropdown'
-import { formatUserDateString } from './Users.utils'
+import { getDateFromIsoString } from './Users.utils'
interface Props {
- user: any
+ user: {
+ id: string
+ email: string
+ phone: string
+ email_confirmed_at: string
+ phone_confirmed_at: string
+ created_at: string
+ last_sign_in_at: string
+ raw_app_meta_data?: {
+ provider: string
+ }
+ app_metadata?: {
+ provider: string
+ }
+ }
}
const UserListItem: FC<Props> = ({ user }) => {
const isUserConfirmed = user.email_confirmed_at || user.phone_confirmed_at
- const createdAt = formatUserDateString(user.created_at)
- const lastSignedIn = formatUserDateString(user.last_sign_in_at)
+ const createdAt = getDateFromIsoString(user.created_at)
+ const lastSignedIn = getDateFromIsoString(user.last_sign_in_at)
return (
<Table.tr key={user.id}>
@@ -33,13 +46,13 @@ const UserListItem: FC<Props> = ({ user }) => {
</span>
</Table.td>
<Table.td className="hidden 2xl:table-cell">
- <span className="text-scale-1200">{dayjs(createdAt).format('DD MMM, YYYY HH:mm')}</span>
+ <span className="text-scale-1200">{createdAt?.format('DD MMM, YYYY HH:mm')}</span>
</Table.td>
<Table.td className="hidden xl:table-cell">
{!isUserConfirmed ? (
<Badge color="yellow">Waiting for verification..</Badge>
) : user.last_sign_in_at ? (
- dayjs(lastSignedIn).format('DD MMM, YYYY HH:mm')
+ lastSignedIn?.format('DD MMM, YYYY HH:mm')
) : (
'Never'
)}