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

Cannot set thresholds on a new locale #1660

Open
mansinarain opened this issue Oct 6, 2021 · 1 comment
Open

Cannot set thresholds on a new locale #1660

mansinarain opened this issue Oct 6, 2021 · 1 comment

Comments

@mansinarain
Copy link

Describe the bug
Trying to create a new locale and pass in thresholds such that '23 hours ago' would be '23h' and anything less than 24hours would not show up as days.

Code
`import dayjs from '@/js/be/dayJSPlugins.js';

const localeObject = {
name: 'en-segment',
relativeTime: {
future: 'in %s',
past: '%s',
s: '%ds',
m: '%dm',
mm: '%dm',
h: '%dh',
hh: '%dh',
d: '%dd',
dd: '%dd',
M: '%dM',
MM: '%dM',
y: '%dy',
yy: '%dy',
},
};

export function getRelativeTime(timestamp) {
dayjs.locale('en-segment', localeObject);
delete relativeTime.$i // this allow plugin to be installed again
dayjs.extend(relativeTime, {
rounding: Math.floor,
thresholds: [
{ l: 's', r: 60 },
{ l: 'm', r: 60 },
{ l: 'h', r: 24 },
],
});

return dayjs.unix(timestamp).fromNow();
}
`

Information

  • Day.js Version 1.10.6
  • OS: MacOS Catalina
  • Browser Chrome 93
  • Time zone: GMT-07:00 DST (Pacific Daylight Time)
@mansinarain
Copy link
Author

@iamkun - if you can help with this please - and update the documentation on how to pass in the thresholds on a new locale.
https://day.js.org/docs/en/customization/relative-time

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

1 participant