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

[feature] Add era support for en,ja (closes #4591) #4599

Closed
wants to merge 11 commits into from

Conversation

eternalharvest
Copy link
Contributor

@eternalharvest eternalharvest commented May 1, 2018

Description

Abstract

This PR implements new feature which is proposed in #4591.
I intended to implement this feature to format or parse Japanese date with era name, but this feature is carefully designed so that can be used in any other country.

Historically, there are more than 200 eras in Japan.
But before 6th Meiji era, our ancestors had been using Chinese lunar calendar.
And I think it is inappropriate to represent these historical dates in Gregorian solar calendar dates.
So I define only 4 eras and 2 Christian eras in Japanese locale.

Note: Japanese Meiji government had decided to use Gregorian solar calendar system since Jan 1st, Meiji 6 (Jan 1st 1873).

Currently there is only few country which is using era names, but I think this feature also can be used in Taiwan or some Buddhism country which is using Gregorian calendar.

Thanks and regards.

Related Issue

Format

Abbr Era Name Narrow Name Ordinal Year Year of Era
MOMENT N, NN, NNN NNNN NNNNN yo y, yy, yyy, yyyy
LDML G, GG, GGG GGGG GGGGG ? y, yy, yyy, yyyy
Single Unix Specification n/a %EC n/a %EY %Ey, %02Ey, %03Ey, %04Ey
Java G, GG, GGG GGGG GGGGG yyyy y, yy, yyy
Excel g ggg, gggg gg n/a e, ee
LibreOffice G GGG GG n/a e, ee

Example

Locale (en)

> var moment = require('moment');
> 
> moment.loale('en');
> moment('1989-01-08').format('y N');
'1989 AC'
> moment([-468, 1, 1]).format('y N');
'469 BC'

Locale (ja)

> var moment = require('moment');
> 
> moment.loale('ja');
> moment('1989-01-07').format('NNNNyoM月D日');
'昭和64年1月7日'
> moment('1989-01-08').format('NNNNyoM月D日');
'平成元年1月8日'
> moment('1989-01-07').format('Nyy.MM.DD');
'S64.01.07'
> moment('1989-01-08').format('Nyy.MM.DD');
'H01.01.08'

@coveralls
Copy link

coveralls commented May 1, 2018

Coverage Status

Coverage increased (+0.2%) to 94.673% when pulling 96f5059 on eternalharvest:feature/era_names into 3062ca1 on moment:develop.

@coveralls
Copy link

coveralls commented May 1, 2018

Coverage Status

Coverage decreased (-0.04%) to 94.61% when pulling 753288c on eternalharvest:feature/era_names into ad49bd6 on moment:develop.

@eternalharvest eternalharvest changed the title [feature] Add era name support [feature] Add era name support Close #4591 May 2, 2018
@ichernev
Copy link
Contributor

@eternalharvest the code looks decent. I think it can go in in next release.

In the definition of the eras, why is BC ending on 31 Dec. Does it automatically round the day to the end? Shouldn't it be 1st Jan 0000 the end date for one era (BC) and the begining of the new era (AC).

Also its not AC and BC. But AD and BC ;-)

@eternalharvest
Copy link
Contributor Author

eternalharvest commented Jul 25, 2018

@ichernev

Sorry for late reply and thank u for reviewing my PR.

In the definition of the eras, why is BC ending on 31 Dec. Does it automatically round the day to the end? Shouldn't it be 1st Jan 0000 the end date for one era (BC) and the begining of the new era (AC).

In my implementation, the date is truncated to the day value (by the method call #startOf('day')) before evaluating era name. But I'm not sure if this implementation satisfies any other locale's requirements except for japanese locale.

In japan, the beginning time (hour, minute, second) of era is not defined by the law.
It is natural to interpret the beginning time of era as 00:00:00 (JST) of first day of Japanese era.
And I think the beginning day value of era is enough to evaluate era name.

If we redesign this feature to use datetime as the beginning time of era, I think we have to consider about timezone.

Also its not AC and BC. But AD and BC ;-)

I fixed this wrong era definition.
Than u for ur advise!

@guisehn
Copy link

guisehn commented Dec 22, 2018

Any news on this one?

@eternalharvest
Copy link
Contributor Author

@guisehn
No news about this PR.

I think this PR satisfies with Japanese locale requirements though I'm not sure about any other locale specific problem or requirements itself.

I wish this PR will be merged if there is no concern about this PR in any other locale.

@guisehn
Copy link

guisehn commented Dec 24, 2018

@eternalharvest if I may ask, what is the workaround you use in your project for now?

I'm thinking in maybe creating a plugin so that I can avoid maintaining a fork just for my project while there's no decision about the pull request, but I'm wondering if there is already an existing plugin (I couldn't find) or workaround I could use.

@yopaz-giapnh
Copy link

How is it going? I hope this feature is supported on moment asap.

@ichernev
Copy link
Contributor

Merged in 4b615b9

@ichernev ichernev changed the title [feature] Add era name support Close #4591 [feature] Add era support for en,ja (closes #4591) Apr 27, 2020
@ichernev ichernev closed this Apr 27, 2020
ichernev added a commit that referenced this pull request Apr 27, 2020
[feature] Add era support for en,ja (closes #4591)
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.

None yet

7 participants