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
fromNow short hand #3049
Comments
Assuming you are running 2.12.0, the following would do the trick: moment.updateLocale('en', {
relativeTime : {
future: "in %s",
past: "%s ",
s: "s",
m: "m",
mm: "%d m",
h: "h",
hh: "%d h",
d: "d",
dd: "%d d",
M: "a mth",
MM: "%d mths",
y: "y",
yy: "%d y"
}
});
moment().subtract(2, 'minutes').fromNow()
"2 m " If you are running pre 2.12.0, it would be: moment.locale('en', {
relativeTime : {
future: "in %s",
past: "%s ",
s: "s",
m: "m",
mm: "%d m",
h: "h",
hh: "%d h",
d: "d",
dd: "%d d",
M: "a mth",
MM: "%d mths",
y: "y",
yy: "%d y"
}
}); You could replace my hastily done shorthand with whatever you wanted. It would also be an option to create a new locale, something like "en-mobile", that inherited from the parent locale. Then when you were on desktop you could use long form, and when you were on mobile you could flip over. moment.locale('en-mobile', {
parentLocale:'en',
relativeTime : {
future: "in %s",
past: "%s ",
s: "ssssssssssss",
m: "m",
mm: "%d m",
h: "h",
hh: "%d h",
d: "d",
dd: "%d d",
M: "a mth",
MM: "%d mths",
y: "y",
yy: "%d y"
}
}); Is that what you needed? |
Hi Maggie - thanks! I'll try that! Thanks for the code example too and fast reply! |
Closing since I think the problem is solved. |
(I also posted this comment on #2781 - sorry for the spam) I would really love to see this feature be implemented in the core codebase. These instagram style short abbreviations are pretty ubiquitous these days. Yes, I agree, it is quite easy to customize for one language. But... if your app needs to support multiple locales, suddenly you need to handle customizing it in the all langs you support. It would be really nice to have the power of moment's community take that burden on. |
+1 Additionally, there are often times when you need long-hand and short-hand in different parts of the app… In those instances, updating locales seems a bit overkill… Or maybe that’s just me? |
REFERENCE IMPLEMENTATION GUIDANCE |
Any movement on this? I agree the strings are way too long for mobile. I'm shying away from using the suggested locale trick, as ultimately I need everything: short form, long form AND multiple locales. |
Is there a really simple suggestion where I can override all the relative past times to short hand? I would think this is really useful for mobile. I don't need a string a mile long for a mobile screen.
Hoping to change these to short hand, like 1m or 1d or 1w - I think some other small time social apps do this already. I think someone already posted about similar thing n secongs ago should be just now. This is a similar request.
How can I override this format to short hand using the component, or do I do my own string replace?
thanks
The text was updated successfully, but these errors were encountered: