@@ -3120,19 +3120,34 @@ private void handleEras(XPathParts parts, String value, List<String> examples) {
31203120 if (eraData == null ) {
31213121 return ; // no era data
31223122 }
3123- GregorianCalendar startCal = forDateString ( eraData .getStart () );
3124- GregorianCalendar endCal = forDateString ( eraData .getEnd () );
3123+ GregorianCalendar startCal = eraData .getStartCalendar ( );
3124+ GregorianCalendar endCal = eraData .getEndCalendar ( );
31253125
3126- final SupplementalCalendarData .EraData prevEra = calendarData .get (typeIndex - 1 );
3127- final SupplementalCalendarData .EraData nextEra = calendarData .get (typeIndex + 1 );
3126+ final SupplementalCalendarData .EraData eminusone = calendarData .get (typeIndex - 1 );
3127+ final SupplementalCalendarData .EraData eplusone = calendarData .get (typeIndex + 1 );
3128+
3129+ SupplementalCalendarData .EraData prevEra = null ;
3130+ SupplementalCalendarData .EraData nextEra = null ;
3131+
3132+ // see if we can find the 'prev' and 'next' era by date
3133+ if (eminusone != null && eminusone .compareTo (eraData ) < 0 ) {
3134+ prevEra = eminusone ;
3135+ } else if (eplusone != null && eplusone .compareTo (eraData ) < 0 ) {
3136+ prevEra = eplusone ;
3137+ }
3138+ if (eminusone != null && eminusone .compareTo (eraData ) > 0 ) {
3139+ nextEra = eminusone ;
3140+ } else if (eplusone != null && eplusone .compareTo (eraData ) > 0 ) {
3141+ nextEra = eplusone ;
3142+ }
31283143
31293144 if (startCal == null && prevEra != null && prevEra .getEnd () != null ) {
3130- startCal = forDateString ( prevEra .getEnd () );
3145+ startCal = prevEra .getEndCalendar ( );
31313146 // shift forward so we are in the next era
31323147 startCal .setTimeInMillis (startCal .getTimeInMillis () + (DateConstants .MILLIS_PER_DAY ));
31333148 }
31343149 if (endCal == null && nextEra != null && nextEra .getStart () != null ) {
3135- endCal = forDateString ( nextEra .getStart () );
3150+ endCal = nextEra .getStartCalendar ( );
31363151 // shift backward so we are in the prev era
31373152 endCal .setTimeInMillis (endCal .getTimeInMillis () - (DateConstants .MILLIS_PER_DAY ));
31383153 }
@@ -3150,7 +3165,7 @@ private void handleEras(XPathParts parts, String value, List<String> examples) {
31503165 sampleDate .setTimeInMillis (
31513166 sampleDate .getTimeInMillis () - (DateConstants .MILLIS_PER_DAY ));
31523167 } else if (startCal != null && endCal == null ) {
3153- sampleDate = forDateString ( " 2002-07-15" ); // CLDR repo root commit
3168+ sampleDate = new GregorianCalendar ( 2002 , 6 , 15 ); // CLDR repo root commit
31543169 if (sampleDate .before (startCal )) {
31553170 sampleDate = startCal ;
31563171 sampleDate .setTimeInMillis (
@@ -3183,24 +3198,6 @@ private void handleEras(XPathParts parts, String value, List<String> examples) {
31833198 examples .add (sdf .format (sample ));
31843199 }
31853200
3186- private GregorianCalendar forDateString (String ymd ) {
3187- if (ymd == null ) return null ;
3188- int multiplier = 1 ;
3189- if (ymd .startsWith ("-" )) {
3190- multiplier = -1 ;
3191- ymd = ymd .substring (1 );
3192- }
3193- final String [] parts = ymd .split ("-" );
3194- try {
3195- return new GregorianCalendar (
3196- multiplier * Integer .parseInt (parts [0 ]),
3197- Integer .parseInt (parts [1 ]) - 1 ,
3198- Integer .parseInt (parts [2 ]));
3199- } catch (NumberFormatException nfe ) {
3200- throw new IllegalArgumentException ("While parsing date string " + ymd , nfe );
3201- }
3202- }
3203-
32043201 /**
32053202 * Add examples for quarters for the gregorian calendar, matching each quarter type (1, 2, 3, 4)
32063203 * to a corresponding sample month and formatting an example with that date
0 commit comments