Skip to content

#539 PrettyTime Missing Unit Workaround#687

Merged
dessalines merged 2 commits into
LemmyNet:mainfrom
lbenedetto:539-PrettyTime-Missing-Unit-Workaround
Jun 19, 2023
Merged

#539 PrettyTime Missing Unit Workaround#687
dessalines merged 2 commits into
LemmyNet:mainfrom
lbenedetto:539-PrettyTime-Missing-Unit-Workaround

Conversation

@lbenedetto

@lbenedetto lbenedetto commented Jun 15, 2023

Copy link
Copy Markdown
Contributor

This is a workaround for #539

A bug in PrettyTime causes four languages to not get any time units when formatted.

We can work around this by detecting an invalid prettyDate (rather than hardcoding a list of broken languages) and switching to English formatting instead.

ocpsoft/prettytime#259

var prettyDate = prettyTime.formatDuration(date)

// A bug in PrettyTime means that some languages (pl, ru, uk, kk) will not include any time unit
if (prettyDate.matches(invalidPrettyDateRegex)) {

@dessalines dessalines Jun 16, 2023

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Where's the bug in prettytime? It seems pretty active. Definitely open up a PR over there, and reference it here, so that we don't always have to use this hack.

@lbenedetto lbenedetto Jun 16, 2023

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I linked the pretty time bug report in the PR description.

But really, it's not so much a bug as a lack of support for these languages. For other languages, they have maps of words in those languages and logic to choose those words with the correct plurality and such.

However, for these four languages, the implementation does not contain any words or logic and just returns back whatever number was passed in.

So I don't think this is a quick fix for them.

I wrote this workaround here so that if/when the issue is fixed, it won't continue defaulting to English, it'll just become irrelevant.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Mmmk, thanks!

A bug in PrettyTime causes four languages to not get any time units when formatted. We can work around this by detecting an invalid prettyDate (rather than hardcoding a list of broken languages) and switching to English formatting instead.

ocpsoft/prettytime#259

@dessalines dessalines left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thx for this!

var prettyDate = prettyTime.formatDuration(date)

// A bug in PrettyTime means that some languages (pl, ru, uk, kk) will not include any time unit
if (prettyDate.matches(invalidPrettyDateRegex)) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Mmmk, thanks!

@dessalines dessalines merged commit 6a8b71b into LemmyNet:main Jun 19, 2023
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.

2 participants