public static String doFormat( String format, Calendar cal ) throws IllegalArgumentException {
            int fidx = 0;
            int flen = format.length();
            StringBuilder buf = new StringBuilder();

            while(fidx<flen) {
                char fch = format.charAt(fidx++);

                if(fch!='%') {  // not a meta character
                    buf.append(fch);
                    continue;
                }

                // seen meta character. we don't do error check against the format
                switch (format.charAt(fidx++)) {
                case 'Y' : // year
                    formatYear(cal, buf);
                    break;

                case 'M' : // month
                    formatMonth(cal, buf);
                    break;

                case 'D' : // days
                    formatDays(cal, buf);
                    break;

                case 'h' : // hours
                    formatHours(cal, buf);
                    break;

                case 'm' : // minutes
                    formatMinutes(cal, buf);
                    break;

                case 's' : // parse seconds.
                    formatSeconds(cal, buf);
                    break;

                case 'z' : // time zone
                    formatTimeZone(cal,buf);
                    break;

                default :
                    // illegal meta character. impossible.
                    throw new InternalError();
                }
            }

            return buf.toString();
        }