Skip to content

Support Short Japanese Era Name #5698

Description

@anaskiee

Hi,

To put a little bit of context, japanese dates can be written using the imperial calendar. The current Japanese era is Reiwa. It is written 令和 and can be abbreviated 令 or R. For instance 令和2年1月1日 which stands for january 1st of the 2th year of 令和 era, can also be abbreviated 令2年1月1日 or R2.1.1

Since moment 2.25, it is possible to extract japanese dates using era notation.

Code Result
moment("令和2年1月1日", "NNNNyoM月D日", "ja").format('YYYY-MM-DD') "2020-01-01"
moment("R2.1.1", "Ny.M.D", "ja").format('YYYY-MM-DD') "2020-01-01"

But, it is not possible to parse "令2年1月1日", because there is no token for this abbreviation. Tokens N, NN and NNN are all linked to the property eraAbbr which is R for the current japanese Reiwa era. And NNNN is for 令和.

By the way, the documentation does not describe the current implementation.
https://momentjs.com/docs/#/parsing/string-format/
It is written

Input Examples Description
N AD Abbr Era name
NN AD Short Era name
NNN Anno Domini Full Era name

The documentation description would be great.
That also would correlate to the LibreOffice tokens

Input Result
GGGE 令和
GGE 令
GE R

Thanks

Activity

  1. simonrey1 commented on Aug 31, 2020

    @simonrey1

    @eternalharvest Could you take a look at this issue please?

  2. eternalharvest commented on Aug 31, 2020

    @eternalharvest
    Contributor

    @eqqe, @anaskiee

    Sorry, I didn't noticed there is inconsistentency between document description and the implementation.
    As @anaskiee mentioned, it seems document description is wrong.
    In current version, there is no feature to format short era name (single Kanji character).

    Correct Description of Current Implementation

    Input LibreOffice Examples (en) Example (ja) Description
    N,NN,NNN G AD R Abbr Era name
    n/a GG ? 令 Short Era name (not implemented)
    NNNN GGG Anno Domini 令和 Full Era name
    NNNNN n/a AD ㋿ Narrow Era name

    I confirmed that Excel has same implementation with LibreOffice.
    I think there is no narrow era name feature in LibreOffice and Excel, so I choosed 'NNNNN' as narrow era name.

    I think I need to write a PR for fix the wrong document descritpion.
    And also need to improve the feature format era name like below.
    In Japan, short era name is first Kanji character of era name, but it may need to consider about implementation whether if we need to add new 'Short era name' mapping field or not.

    Improved Version (candidate)

    Input LibreOffice Examples (en) Example (ja) Description
    N G AD R Abbr Era name
    NN GG ? 令 Short Era name
    NNN,NNNN GGG Anno Domini 令和 Full Era name
    NNNNN n/a AD ㋿ Narrow Era name

    Please tell me any opinion/advice if you have any idea to improve the formatting token.

  3. simonrey1 commented on Sep 1, 2020

    @simonrey1

    @eternalharvest Your Improved Version looks good to me.

  4. marwahaha commented on Sep 14, 2020

    @marwahaha
    Member

    Hi, thanks for this request.

    See https://momentjs.com/docs/#/-project-status/ - we will not be adding new features. But perhaps this is simple enough to add.

    I updated the docs myself.

  5. qqweng commented on Nov 11, 2020

    @qqweng

    Hi, I was hoping to contribute, but I think this issue seems to have been fixed. Please confirm. Thanks!

  6. anaskiee commented on Nov 16, 2020

    @anaskiee
    Author

    @qqweng
    The issue was closed but not fixed. The project moment.js is now a legacy and only mandatory updates are going to be pushed. See https://momentjs.com/docs/#/-project-status/

    For information, to workaround the issue, I replaced the text 令 (when not followed by 和) by 令和. That's independant of moment.js because the text is replaced before calling moment()

  7. marwahaha commented on Nov 18, 2020

    @marwahaha
    Member

    If this change is simple, you can make a pull request and I can look at it. But I cannot promise we will merge it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions