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

Conditional Relative Time Locale Update #1650

Open
mirabledictu opened this issue Sep 30, 2021 · 1 comment
Open

Conditional Relative Time Locale Update #1650

mirabledictu opened this issue Sep 30, 2021 · 1 comment

Comments

@mirabledictu
Copy link

Hello, is there a way to conditionally update relativeTime?

The current way we do it from docs is like this:

dayjs.extend(updateLocale)

dayjs.updateLocale('en', {
  relativeTime: {
    future: "in %s",
    past: "%s ago",
    s: 'a few seconds',
    m: "a minute",
    mm: "%d minutes",
    h: "an hour",
    hh: "%d hours",
    d: "a day",
    dd: "%d days",
    M: "a month",
    MM: "%d months",
    y: "a year",
    yy: "%d years"
  }
})

In my code, I want to keep this formats but also want to update it conditionally?

I have some code that I want to use this format

dayjs('2021-09-29').fromNow() // 1 day ago

and I also have some code that I want to update some if a condition is met somewhere

dayjs.updateLocale('en', {
  relativeTime: {
    ...
    d: "1d",
    dd: "%dd",
   ...
  }
})
dayjs('2021-09-29').fromNow() // 1d
@andreasvirkus
Copy link

@mirabledictu did you ever find a way to do this? only way we can think of is setting the locale and then later changing the global locale of dayjs back to the original 😕

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

No branches or pull requests

2 participants