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

Issue317: Introducing Multiple Locale Support #318

Closed
wants to merge 3 commits into from

Conversation

GarreauArthur
Copy link

Partially closes #317

This branch introduces the following new formats (already in use in moment.js):

  • LT
  • LTS
  • L
  • LL
  • LLL
  • LLLL

These tokens define shortcuts to usual, local specific, formats. Example:

dayjs().format('LL');   // August 29, 2018

It works for english, french and spanish. To add a new language, we just need to add the following object into the corresponding locale file. Example (src/locale/fr.js):

  longDateFormat: {
    LT: 'HH:mm',
    LTS: 'HH:mm:ss',
    L: 'DD/MM/YYYY',
    LL: 'D MMMM YYYY',
    LLL: 'D MMMM YYYY HH:mm',
    LLLL: 'dddd D MMMM YYYY HH:mm'
  }

Garreau Arthur added 3 commits August 29, 2018 17:35
This commit introduces the following new formats:

* LT
* LTS
* L
* LL
* LLL
* LLLL

These tokens define shortcuts to usual, local specific, formats. Example:

    dayjs().format('LL');   // August 29, 2018
….test.js

This commit adds the "long date format" object in src/locale/es.js to allow
to use the new LT, LTS, L, LL, LLL, LLLL formats.
These new formats are tested in test/display.test.js
@codecov-io
Copy link

codecov-io commented Aug 30, 2018

Codecov Report

Merging #318 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master   #318   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files          32     32           
  Lines         386    395    +9     
  Branches       53     54    +1     
=====================================
+ Hits          386    395    +9
Impacted Files Coverage Δ
src/locale/fr.js 100% <100%> (ø) ⬆️
src/index.js 100% <100%> (ø) ⬆️
src/locale/es.js 100% <100%> (ø) ⬆️
src/constant.js 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b14bdd1...c754f99. Read the comment docs.

@iamkun
Copy link
Owner

iamkun commented Aug 31, 2018

Thanks. I'm not sure if we should add this logic into our main bundle or not. Wait for discussion.

@limonte
Copy link

limonte commented Sep 1, 2018

As a dayjs user, I'd like to have this in the main bundle 👍

@prantlf
Copy link
Contributor

prantlf commented Sep 3, 2018

I added this functionality as a plugin in #305.

Differences to this PR:

  • Additional formatting tokens introduced as a plugin called LocalisableFormat.
  • Included formats of the new tokens for all locales.
  • Added documentation.

Plugins bring modularity to Date.js. Varous features can be loaded only by applications, which need it. For example, if an application has a date format in the user configuration, it will not need choosing the format by the user's locale from format aliases in Day.js.

@iamkun
Copy link
Owner

iamkun commented Sep 3, 2018

Thanks @prantlf and @GarreauArthur. I tend to agree with prantlf's PR of adding this functionality as a plugin.

@GarreauArthur
Copy link
Author

I am down for @prantlf's plugin. 😄

@prantlf
Copy link
Contributor

prantlf commented Sep 5, 2018

Thank you all! :-) I'm looking forward to getting it merged :-)

I would like to replace Moment.js with Day.js, but formatting according to the the user's locale (PR #305) and incorrect localisability of relative times (PR #304) do not allow it yet.

The application, which I am working on, runs in two modes:

  • The user chooses the format provided by their native locale. Web browser OS, whatever they do. The user wants to have the web application consistent with the rest of their environment.
  • The user chooses the format (very) explicitly. Like "DD/MM/YYYY HH:mm:ss". The user wants the web application to be consistent with the company standard, which other intranet web pages adhere to.

@iamkun
Copy link
Owner

iamkun commented Feb 2, 2019

#305 plugin

@iamkun iamkun closed this Feb 2, 2019
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

Successfully merging this pull request may close these issues.

5 participants