We're updating the issue view to help you get more done. 

ucal_add()ing backwards through Japanese eras does not behave correctly

Description

Japanese eras are not all the same length; consequently, the behavior I'd expect from the following snippet is not what actually occurs.

(Current date: Jul 23, 20 Heisei)

1 2 3 UErrorCode status = U_ZERO_ERROR; UCalendar *cal = ucal_open(NULL, -1, "en@calendar=japanese", UCAL_TRADITIONAL, &status); ucal_add(cal, UCAL_ERA, -2, &status);

Expected date: Jul 23, 15 Taishō

Actual result date: Jul 23, 6 Shōwa

In other words, the year is interpreted as "20 Taishō", which doesn't exist, and it rolls over to 6 Shōwa. (Japanese eras are one-based, but don't necessarily start on January 1st.) The behavior of ucal_roll is the same.

This is inconsistent with the behavior for handling months and days of months; going back a month from March 30 gives February 28, not March 2.

As a note, adding a "pinField(UCAL_YEAR, status);" to Calendar::add does not fix the problem, since the date's components are updated using the GregorianCalendar implementation before the maximum year is retrieved.

A separate problem is how the month and day components are pinned. Are they pinned ''with'' the year:

1 2 Jul 23, 20 Taishō >> Dec 24, 15 Taishō Dec 30, 20 Taishō >> Dec 24, 15 Taishō

or ''after'' the year has been pinned:

1 2 Jul 23, 20 Taishō >> Jul 23, 15 Taishō Dec 30, 20 Taishō >> Dec 24, 15 Taishō

or even affecting the year itself to preserve the month/day:

1 2 Jul 23, 20 Taishō >> Jul 23, 15 Taishō Dec 30, 20 Taishō >> Dec 30, 14 Taishō

? (This is probably a resolution order problem.)

Environment

Status

Assignee

Peter Edberg

Reporter

TracBot

tracCc

pedberg,yoshito

tracCreated

Jul 24, 2008, 1:12 AM

tracOwner

pedberg

tracProject

ICU4C

tracReporter

jordan_rose@de24b5571deaea7c

tracStatus

accepted

Components

Fix versions

Priority

medium