public static int unitsToCalendarType ( final String units ) { if ( units == null || units . isEmpty ( ) ) { throw new IllegalArgumentException ( "Units cannot be null or empty" ) ; } final String lc = units . toLowerCase ( ) ; if ( lc . equals ( "ms" ) ) { return Calendar . MILLISECOND ; } else if ( lc . equals ( "s" ) ) { return Calendar . SECOND ; } else if ( lc . equals ( "m" ) ) { return Calendar . MINUTE ; } else if ( lc . equals ( "h" ) ) { return Calendar . HOUR_OF_DAY ; } else if ( lc . equals ( "d" ) ) { return Calendar . DAY_OF_MONTH ; } else if ( lc . equals ( "w" ) ) { return Calendar . DAY_OF_WEEK ; } else if ( lc . equals ( "n" ) ) { return Calendar . MONTH ; } else if ( lc . equals ( "y" ) ) { return Calendar . YEAR ; } throw new IllegalArgumentException ( "Unrecognized unit type: " + units ) ; }
Return the proper Calendar time unit as an integer given the string