Skip to content
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

Conversation

ameeetgaikwad
Copy link
Contributor

@ameeetgaikwad ameeetgaikwad commented Feb 25, 2024

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

Copy link

netlify bot commented Feb 25, 2024

Deploy Preview for ethereumorg ready!

Name Link
🔨 Latest commit 01a6b33
🔍 Latest deploy log https://app.netlify.com/sites/ethereumorg/deploys/663a838fd0f1cd0008344899
😎 Deploy Preview https://deploy-preview-12287--ethereumorg.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
7 paths audited
Performance: 51 (🟢 up 12 from production)
Accessibility: 92 (🔴 down 1 from production)
Best Practices: 95 (🔴 down 5 from production)
SEO: 95 (🔴 down 5 from production)
PWA: -
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify site configuration.

@nhsz
Copy link
Member

nhsz commented Feb 25, 2024

@wackerow I think PR #12209 overlaps a bit with this one, not sure if this one is still needed

Copy link
Member

@wackerow wackerow left a 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!

Comment on lines 3 to 5
export const formatDate = (date: Date, locale: string): string => {
return Intl.DateTimeFormat(locale).format(date)
}
Copy link
Member

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export const formatDate = (date: Date, locale: string): string => {
return Intl.DateTimeFormat(locale).format(date)
}

Comment on lines 62 to 66
? formatDate(dateParse(event.startDate), locale)
: `${formatDate(dateParse(event.startDate), locale)} - ${formatDate(
dateParse(event.endDate),
locale
)}`
Copy link
Member

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()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import { formatDate } from "@/lib/utils/date"

@wackerow
Copy link
Member

Just pushed a commit to update this with the latest from dev branch

Copy link
Contributor

github-actions bot commented May 7, 2024

This issue is stale because it has been open 30 days with no activity.

@github-actions github-actions bot added the Stale label May 7, 2024
@nhsz
Copy link
Member

nhsz commented May 7, 2024

@wackerow do you think this PR is still relevant?

@wackerow wackerow removed the Stale label May 7, 2024
@wackerow wackerow self-assigned this May 7, 2024
Copy link
Member

@wackerow wackerow left a 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!

@wackerow wackerow merged commit 490e337 into ethereum:dev May 7, 2024
7 of 9 checks passed
Copy link

gitpoap-bot bot commented May 7, 2024

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:

GitPOAP: 2024 Ethereum.org Contributor GitPOAP Badge

Head to gitpoap.io & connect your GitHub account to mint!

Learn more about GitPOAPs here.

@wackerow
Copy link
Member

wackerow commented May 7, 2024

@wackerow do you think this PR is still relevant?

@nhsz And yes, this patches the number formatting on the community events page

This was referenced May 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incorrect intl number formatting
3 participants