public static String getWthYearDuration ( Map wthData ) { String yearDur = "" ; ArrayList < Map > wthRecords = ( ArrayList ) getObjectOr ( wthData , "dailyWeather" , new ArrayList ( ) ) ; if ( ! wthRecords . isEmpty ( ) ) { // Get the year of starting date and end date String startYear = getValueOr ( ( wthRecords . get ( 0 ) ) , "w_date" , " " ) . substring ( 2 , 4 ) . trim ( ) ; String endYear = getValueOr ( ( wthRecords . get ( wthRecords . size ( ) - 1 ) ) , "w_date" , " " ) . substring ( 2 , 4 ) . trim ( ) ; // If not available, do not show year and duration in the file name if ( ! startYear . equals ( "" ) && ! endYear . equals ( "" ) ) { yearDur += startYear ; try { int iStartYear = Integer . parseInt ( startYear ) ; int iEndYear = Integer . parseInt ( endYear ) ; iStartYear += iStartYear <= 15 ? 2000 : 1900 ; // P.S. 2015 is the cross year for the current version iEndYear += iEndYear <= 15 ? 2000 : 1900 ; // P.S. 2015 is the cross year for the current version int duration = iEndYear - iStartYear + 1 ; // P.S. Currently the system only support the maximum of 99 years for duration duration = duration > 99 ? 99 : duration ; yearDur += String . format ( "%02d" , duration ) ; } catch ( Exception e ) { yearDur += "01" ; // Default duration uses 01 (minimum value) } } } return yearDur ; }
Get the last 2 - bit year number and 2 - bit of the duration for weather file name