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

i18n: format date #29

Closed
rachel-carvalho opened this issue Oct 20, 2011 · 5 comments
Closed

i18n: format date #29

rachel-carvalho opened this issue Oct 20, 2011 · 5 comments
Milestone

Comments

@rachel-carvalho
Copy link
Contributor

First I just want to say that this is a great lib, gets the job done and has great i18n support.

Anyway, I'm dealing with a website that has to show dates both in english and in portuguese (great to see that pt was already implemented!). It was all good, until I found this place where I need to write a full date in both languages.

I realized I would need 2 different formats: one for english (MMMM D, YYYY - October 20, 2011) and one for portuguese (D \de MMMM \de YYYY - 20 de Outubro de 2011 [and just now I see that I don't know if it's possible to escape the lowercase d, but anyway, focus]).

Is there a way to call moment().format() with no parameters so that it assumes a default formatting for the whole date?

If there isn't, it would be nice to implement it, I could give it a go.

Maybe a new token that contains the whole date and whole time, like moment().format('T'); // 2:17 PM in english and 14:17 in portuguese. Though I have no idea what a good token would be for the whole date...

@timrwood
Copy link
Member

Yeah, I can see how that would be useful.

It should probably work something like this.

moment().format('L') // 07/10/1986
moment().format('LL') // July 10 1986
moment().format('LLL') // July 10 1986 8:30 PM
moment().format('LLLLL') // Saturday, July 10 1986 8:30PM

Then each language would specify a default format for each length.

By the way, escaping characters should work, but if you're writing as JS strings, you'll need to escape the escape character.

moment().format('D \\de MMMM \\de YYYY');

@rachel-carvalho
Copy link
Contributor Author

Okay, when I've got some time, I'll take a shot at it.

rachel-carvalho added a commit to rachel-carvalho/moment that referenced this issue Oct 21, 2011
@rachel-carvalho
Copy link
Contributor Author

When you've got some time, please take a look. I updated the tests and the docs.

I added support for all languages, but I'm just learning french, not completely sure if it's correct and italian I just added the same as french, some google search showed me it should be similar. But it would be good to have someone native to review those.

@timrwood
Copy link
Member

Wow, this looks great! You even updated the docs + unit tests!

Please submit a pull request to the dev branch when you get a chance.

I'll send a message to the people who committed the French and Italian language files about the formats.

Thanks for contributing!

@timrwood
Copy link
Member

This is in 1.1.0 and has been published in npm.

This was referenced Oct 31, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants