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

ICU-12973 CLDR Japanese Era data and tentative Japanese new era support #111

Merged
merged 8 commits into from Sep 12, 2018

Conversation

yumaoka
Copy link
Member

@yumaoka yumaoka commented Sep 11, 2018

  1. New internal API class EraRules designed for loading era data from CLDR and look up appropriate era for a given date.
  2. EraRules can enable/disable tentative eras - disabled by default.
  3. Updated JapaneseCalendar class to use EraRules to access Japanese era data.
  4. Environment variable (or system property on Java) - ICU_ENABLE_TENTATIVE_ERA=true enables the tentative era rule and date format will produce placeholder era names (Qqqq/Q).

Note: Other calendar implementation classes may also use EraRules, but it may not add much values. For now, CLDR era data is utilized only by Japanese calendar.

Checklist

@yumaoka
Copy link
Member Author

yumaoka commented Sep 11, 2018

#110 had merge conflict that cannot be resolved through PR. I closed #110 and created a new PR merging master to my branch before creating a PR, and created this one.

Copy link
Member

@srl295 srl295 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

data LGTM

Copy link
Member

@srl295 srl295 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

era rules in C LGTM


EraRules* EraRules::createInstance(const char *calType, UBool includeTentativeEra, UErrorCode& status) {
if(U_FAILURE(status)) {
return NULL;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Can we use nullptr since this is C++ file?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK C++11 :) I'll update.

if(U_FAILURE(status)) {
return NULL;
}
UResourceBundle *rb = ures_openDirect(NULL, "supplementalData", &status);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Could use LocalUResourceBundlePointer for this, so don't need to clean-up manually. :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see - will do.

int32_t firstTentativeIdx = MAX_INT32;

int32_t *startDates = (int32_t*)uprv_malloc(numEras * sizeof(int32_t));
if (startDates == NULL) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nullptr

// By default, such tentative era is disabled.

// 1. Environment variable ICU_ENABLE_TENTATIVE_ERA=true or false
// 2. Windows registry (TBD)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yumaoka It might also be possible to check for environment variable in UWP as well.
Once this PR is in, perhaps I can also make another PR for this? (After the IUC 42 though).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I investigated quickly, but could not find it. I appreciate you can work on it.

- NULL to nullptr
- use of LocalUResourceBundlePointer
- TYPO "name" to "named"
- env var checking stricmp() == 0
@yumaoka
Copy link
Member Author

yumaoka commented Sep 11, 2018

@jefgen I updated ICU4C implementation based on your comments. Also a few bug fixes. Please review it again. #Closed

@srl295
Copy link
Member

srl295 commented Sep 12, 2018

as of 3b01ed4 the tentative formatting works and is selectable. 👍

$ env ICU_ENABLE_TENTATIVE_ERA=false 'LC_ALL=ja@calendar=japanese' DYLD_LIBRARY_PATH=../../lib:../../stubdata:../../tools/ctestfw:$DYLD_LIBRARY_PATH  ./icudate -r 1559898950 -f
平成31年6月7日金曜日 2時15分50秒 アメリカ太平洋夏時間
srl@gozo:~/build/icu/samples/date
$ env ICU_ENABLE_TENTATIVE_ERA=true 'LC_ALL=ja@calendar=japanese' DYLD_LIBRARY_PATH=../../lib:../../stubdata:../../tools/ctestfw:$DYLD_LIBRARY_PATH  ./icudate -r 1559898950 -f
QQ1年6月7日金曜日 2時15分50秒 アメリカ太平洋夏時間
srl@gozo:~/build/icu/samples/date
$ env ICU_ENABLE_TENTATIVE_ERA=true 'LC_ALL=ja@calendar=japanese' DYLD_LIBRARY_PATH=../../lib:../../stubdata:../../tools/ctestfw:$DYLD_LIBRARY_PATH  ./icudate  -f
平成30年9月11日火曜日 17時07分34秒 アメリカ太平洋夏時間
srl@gozo:~/build/icu/samples/date
$ env ICU_ENABLE_TENTATIVE_ERA=false 'LC_ALL=ja@calendar=japanese' DYLD_LIBRARY_PATH=../../lib:../../stubdata:../../tools/ctestfw:$DYLD_LIBRARY_PATH  ./icudate  -f
平成30年9月11日火曜日 17時07分38秒 アメリカ太平洋夏時間
``` #Closed

* <p>
* The Japanese calendar uses a combination of era name and year number.
* When an empror of Japan abdicates and a new emperor ascends the throne,
* a new era is declared and year number is reset to 1. Even the date of
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: wording. Perhaps use this: "Even [if] the date of"

int32_t numEras = ures_getSize(rb.getAlias());
int32_t firstTentativeIdx = MAX_INT32;

int32_t *startDates = (int32_t*)uprv_malloc(numEras * sizeof(int32_t));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: could probably use LocalPointer instead of uprv_malloc. but I don't think this is necessary for now. I can change this later when adding UWP env support.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

jefgen
jefgen previously approved these changes Sep 12, 2018
Copy link
Member

@jefgen jefgen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks Yoshito.

Also, duplicate the comment in ucal.h to calendar.h
srl295
srl295 previously approved these changes Sep 12, 2018
Copy link
Member

@srl295 srl295 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm with minor

icu4c/source/i18n/unicode/calendar.h Outdated Show resolved Hide resolved
}

void EraRulesTest::testJapanese() {
const int32_t HEISEI = 235; // ICU4C does not define constants for eras
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not ideal, but probably fine.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ICU4J exposes some constants for modern eras as int. Heisei is currently 235. ICU4J document says it might be changed in new releases. Markus pointed out it's not a good idea to change the value of these constants.

In this release, I considered that we clearly state these constant values won't change in future releases. But at the same time, I really think we should drop era data before Meiji. This would change the era indexes one more time.

I think it's not too late to find out how to expose some Japanese era constants after we decide what to do with historic eras.

}

void EraRulesTest::testAPIs() {
const char * calTypes[] = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no other way to iterate on these types?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ICU4J has CalType enum. ICU4C has calendar type enum, but their names are defined in calendar.cpp (https://github.com/unicode-org/icu/blob/master/icu4c/source/i18n/calendar.cpp#L159) and has no API exposed to get calendar type name from enum or vise versa.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -634,6 +414,7 @@ protected int handleGetLimit(int field, int limitType) {
* {@inheritDoc}
* @stable ICU 3.8
*/
@Override
public String getType() {
return "japanese";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CalType.JAPANESE.name() ?

Copy link
Member Author

@yumaoka yumaoka Sep 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. If I remember correctly, getType() was implemented before CalType enum.
I did not touch this method for this time - eclipse kindly :) supplied @Override annotation automatically when saving JapaneseCalendar.java changes.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other calendars have the same issue. I'd want to make consistent change with the new ticket https://unicode-org.atlassian.net/projects/ICU/issues/ICU-20134

@jefgen
Copy link
Member

jefgen commented Sep 12, 2018

On Windows, with the Win32 version of ICU4C (UWP is yet to come) using a modified date program (Console is UTF-8 code-page).

>date.exe
平成30年9月12日 11:58:36
>date.exe -r 1559898950
平成31年6月7日 2:15:50
>set ICU_ENABLE_TENTATIVE_ERA=true
>date.exe
平成30年9月12日 13:11:26
>date.exe -r 1559898950
QQ1年6月7日 2:15:50
``` #Closed

@yumaoka yumaoka merged commit 61d446f into unicode-org:master Sep 12, 2018
@yumaoka yumaoka deleted the cldr-era2 branch September 12, 2018 21:13
sffc pushed a commit to sffc/icu that referenced this pull request Sep 26, 2018
…rt (unicode-org#111)

* Updated era data format in supplementalData.

* Include tentative era names in data. Implemented Japanese era loaded from CLDR data in ICU4J.

* ICU4C implementation, ICU4C refactoring. WIP.

* VS project updates and some bug fixes

Also added API comments.

* Review feedback and bug fixes

- NULL to nullptr
- use of LocalUResourceBundlePointer
- TYPO "name" to "named"
- env var checking stricmp() == 0

* API comment correction based on feedback

* Duplicate the comment in ucal.h to calendar.h

* Fixed spelling errors in API comment
sffc pushed a commit to sffc/icu that referenced this pull request Sep 26, 2018
…rt (unicode-org#111)

* Updated era data format in supplementalData.

* Include tentative era names in data. Implemented Japanese era loaded from CLDR data in ICU4J.

* ICU4C implementation, ICU4C refactoring. WIP.

* VS project updates and some bug fixes

Also added API comments.

* Review feedback and bug fixes

- NULL to nullptr
- use of LocalUResourceBundlePointer
- TYPO "name" to "named"
- env var checking stricmp() == 0

* API comment correction based on feedback

* Duplicate the comment in ucal.h to calendar.h

* Fixed spelling errors in API comment
sffc pushed a commit to sffc/icu that referenced this pull request Sep 27, 2018
…rt (unicode-org#111)

* Updated era data format in supplementalData.

* Include tentative era names in data. Implemented Japanese era loaded from CLDR data in ICU4J.

* ICU4C implementation, ICU4C refactoring. WIP.

* VS project updates and some bug fixes

Also added API comments.

* Review feedback and bug fixes

- NULL to nullptr
- use of LocalUResourceBundlePointer
- TYPO "name" to "named"
- env var checking stricmp() == 0

* API comment correction based on feedback

* Duplicate the comment in ucal.h to calendar.h

* Fixed spelling errors in API comment
sffc pushed a commit to sffc/icu that referenced this pull request Sep 27, 2018
…rt (unicode-org#111)

* Updated era data format in supplementalData.

* Include tentative era names in data. Implemented Japanese era loaded from CLDR data in ICU4J.

* ICU4C implementation, ICU4C refactoring. WIP.

* VS project updates and some bug fixes

Also added API comments.

* Review feedback and bug fixes

- NULL to nullptr
- use of LocalUResourceBundlePointer
- TYPO "name" to "named"
- env var checking stricmp() == 0

* API comment correction based on feedback

* Duplicate the comment in ucal.h to calendar.h

* Fixed spelling errors in API comment
sffc pushed a commit to sffc/icu that referenced this pull request Sep 27, 2018
…rt (unicode-org#111)

* Updated era data format in supplementalData.

* Include tentative era names in data. Implemented Japanese era loaded from CLDR data in ICU4J.

* ICU4C implementation, ICU4C refactoring. WIP.

* VS project updates and some bug fixes

Also added API comments.

* Review feedback and bug fixes

- NULL to nullptr
- use of LocalUResourceBundlePointer
- TYPO "name" to "named"
- env var checking stricmp() == 0

* API comment correction based on feedback

* Duplicate the comment in ucal.h to calendar.h

* Fixed spelling errors in API comment
sffc pushed a commit to sffc/icu that referenced this pull request Sep 27, 2018
…rt (unicode-org#111)

* Updated era data format in supplementalData.

* Include tentative era names in data. Implemented Japanese era loaded from CLDR data in ICU4J.

* ICU4C implementation, ICU4C refactoring. WIP.

* VS project updates and some bug fixes

Also added API comments.

* Review feedback and bug fixes

- NULL to nullptr
- use of LocalUResourceBundlePointer
- TYPO "name" to "named"
- env var checking stricmp() == 0

* API comment correction based on feedback

* Duplicate the comment in ucal.h to calendar.h

* Fixed spelling errors in API comment
sffc pushed a commit to sffc/icu that referenced this pull request Sep 27, 2018
…rt (unicode-org#111)

* Updated era data format in supplementalData.

* Include tentative era names in data. Implemented Japanese era loaded from CLDR data in ICU4J.

* ICU4C implementation, ICU4C refactoring. WIP.

* VS project updates and some bug fixes

Also added API comments.

* Review feedback and bug fixes

- NULL to nullptr
- use of LocalUResourceBundlePointer
- TYPO "name" to "named"
- env var checking stricmp() == 0

* API comment correction based on feedback

* Duplicate the comment in ucal.h to calendar.h

* Fixed spelling errors in API comment
jefgen pushed a commit to jefgen/icu that referenced this pull request Feb 6, 2019
… the New Era.

Manually cherry-picked from commit: 45cdda6

Original commit message:


ICU-12973 CLDR Japanese Era data and tentative Japanese new era support (unicode-org#111)

* Updated era data format in supplementalData.

* Include tentative era names in data. Implemented Japanese era loaded from CLDR data in ICU4J.

* ICU4C implementation, ICU4C refactoring. WIP.

* VS project updates and some bug fixes

Also added API comments.

* Review feedback and bug fixes

- NULL to nullptr
- use of LocalUResourceBundlePointer
- TYPO "name" to "named"
- env var checking stricmp() == 0

* API comment correction based on feedback

* Duplicate the comment in ucal.h to calendar.h

* Fixed spelling errors in API comment
jefgen pushed a commit to jefgen/icu that referenced this pull request Mar 13, 2019
… the New Era.

Manually cherry-picked from commit: 45cdda6

Original commit message:


ICU-12973 CLDR Japanese Era data and tentative Japanese new era support (unicode-org#111)

* Updated era data format in supplementalData.

* Include tentative era names in data. Implemented Japanese era loaded from CLDR data in ICU4J.

* ICU4C implementation, ICU4C refactoring. WIP.

* VS project updates and some bug fixes

Also added API comments.

* Review feedback and bug fixes

- NULL to nullptr
- use of LocalUResourceBundlePointer
- TYPO "name" to "named"
- env var checking stricmp() == 0

* API comment correction based on feedback

* Duplicate the comment in ucal.h to calendar.h

* Fixed spelling errors in API comment
jefgen pushed a commit that referenced this pull request Mar 21, 2019
… the New Era.

Manually cherry-picked from commit: 45cdda6

Original commit message:


ICU-12973 CLDR Japanese Era data and tentative Japanese new era support (#111)

* Updated era data format in supplementalData.

* Include tentative era names in data. Implemented Japanese era loaded from CLDR data in ICU4J.

* ICU4C implementation, ICU4C refactoring. WIP.

* VS project updates and some bug fixes

Also added API comments.

* Review feedback and bug fixes

- NULL to nullptr
- use of LocalUResourceBundlePointer
- TYPO "name" to "named"
- env var checking stricmp() == 0

* API comment correction based on feedback

* Duplicate the comment in ucal.h to calendar.h

* Fixed spelling errors in API comment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants