iamkun / iamkun/dayjs

Conditional Relative Time Locale Update

Open
#1,650 1 comment 2 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
48.7k
Forks
2.5k
PR merge metrics
No merged PRs in 30d

Description

Hello, is there a way to conditionally update relativeTime?

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

```js
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
```

Contributor guide

Open the contributing guide

Research direction

Start with the documented updateLocale API and the relativeTime/fromNow examples shown in the issue. Determine how conditional selection between the existing wording and abbreviated wording should work, then verify that both example calls produce the intended output without changing the default format.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
localization
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.