-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: fixed date format #12287
fix: fixed date format #12287
Conversation
✅ Deploy Preview for ethereumorg ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @ameeetgaikwad! Thanks for the PR... as @nhsz mentioned, we do have some other related helper functions already in the codebase for this.. Left some suggestions as to how we could reuse these and get this cleaned up. Let us know if you hit issues!
src/lib/utils/date.ts
Outdated
export const formatDate = (date: Date, locale: string): string => { | ||
return Intl.DateTimeFormat(locale).format(date) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have getLocaleTimestamp
inside src/lib/utils/time.ts
which does this same thing with a bit more flexibility and type safety (allowing display options to be passed for example).
I think we should remove this addition and use getLocaleTimestamp
instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
export const formatDate = (date: Date, locale: string): string => { | |
return Intl.DateTimeFormat(locale).format(date) | |
} |
? formatDate(dateParse(event.startDate), locale) | ||
: `${formatDate(dateParse(event.startDate), locale)} - ${formatDate( | ||
dateParse(event.endDate), | ||
locale | ||
)}` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would update this to use getLocaleTimestamp
from time.ts
... it accepts the locale
, (of Lang
type) then timestamp
as a string (then optional options
override argument which may be able to be left out here)
ie. getLocaleTimestamp(locale! as Lang, dateParse(event.startDate).getTime())
locale!
force unwraps it, since we know we'll get a locale back from useRouter
... and as Lang
casts it to the expected type as defined inside getLocaleTimestamp
.
^ With this, we need to fix the locale
instantiation (see above), and also import Lang
type above:
import type { CommunityConference, Lang } from "@/lib/types"
@@ -19,6 +21,7 @@ type OrderedUpcomingEvent = CommunityConference & { | |||
} | |||
|
|||
const UpcomingEventsList = () => { | |||
const { locale = "" } = useRouter() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const { locale = "" } = useRouter() | |
const { locale } = useRouter() |
@@ -9,6 +10,7 @@ import EventCard from "@/components/EventCard" | |||
import InfoBanner from "@/components/InfoBanner" | |||
import InlineLink from "@/components/Link" | |||
|
|||
import { formatDate } from "@/lib/utils/date" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import { formatDate } from "@/lib/utils/date" |
Just pushed a commit to update this with the latest from |
This issue is stale because it has been open 30 days with no activity. |
@wackerow do you think this PR is still relevant? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Went ahead and made a few updates to just use the getLocaleTimestamp function that already exists. Made a little helper function in-component to avoid repeating the options we want for this specific component. Pulling in!
Congrats, your important contribution to this open-source project has earned you a GitPOAP! Be sure to join the Ethereum.org discord if you are interested in contributing further to the project or have any questions for the team. GitPOAP: 2024 Ethereum.org Contributor: Head to gitpoap.io & connect your GitHub account to mint! Learn more about GitPOAPs here. |
Description
Created a function in src/lib/utils/date.ts which can be used to format dates in a certain format according to the language.
Related Issue
fixes #11335
closes #11443