private static boolean getTimeFormatStringFor()

in util/src/main/java/com/epam/deltix/util/text/DateFormatDetector.java [171:273]


    private static boolean getTimeFormatStringFor(
            CharSequence  text,
            int           timeStartIdx,
            StringBuilder timeFormat   ) {

        String value = text.toString();
        boolean hasAmOrPmMarker = value.endsWith(DF_AM_MARKER) || value.endsWith(DF_PM_MARKER);
        if (hasAmOrPmMarker){
            text = text.subSequence(0, text.length() - DF_AM_MARKER.length());
        }

        int             limit = text.length ();
        boolean         success = false;
        TPS             state = TPS.BEFORE_HOURS;

        for (int ii = timeStartIdx; ii <= limit; ii++) {
            char        c;
            boolean     isdigit;
            
            if (ii < limit) {
                c = text.charAt (ii);            
                isdigit = Character.isDigit (c);
            }
            else {
                c = 0;
                isdigit = false;
            }
            
            switch (state) {
                case BEFORE_HOURS:  
                    if (isdigit) state = TPS.HOURS; 
                    break; 
                
                case HOURS:         
                    if (!isdigit) 
                        state = TPS.BEFORE_MINUTES; 
                    else if (StringUtils.endsWith (timeFormat, "HH"))
                        state = TPS.MINUTES;
                    break;                  
                    
                case BEFORE_MINUTES: 
                    if (isdigit) state = TPS.MINUTES; 
                    break;           
                    
                case MINUTES:       
                    if (!isdigit) 
                        state = TPS.BEFORE_SECONDS;
                    else if (StringUtils.endsWith (timeFormat, "mm"))
                        state = TPS.SECONDS;
                    break;
                    
                case BEFORE_SECONDS:
                    if (isdigit) state = TPS.SECONDS; 
                    break;                    
                    
                case SECONDS: 
                    if (!isdigit) 
                        state = TPS.BEFORE_MILLIS; 
                    else if (StringUtils.endsWith (timeFormat, "ss"))
                        state = TPS.MILLIS;
                    break;                    
                    
                case BEFORE_MILLIS: 
                    if (isdigit) state = TPS.MILLIS; 
                    break;                    
                    
                case MILLIS: 
                    if (!isdigit)
                        if (StringUtils.endsWith (timeFormat, "SSS")) 
                            state = TPS.STOP;
                        else
                            return (false); // Prohibit partial millis to avoid false matches with year!
                    else if (StringUtils.endsWith (timeFormat, "SSS")) 
                        state = TPS.STOP; 
                    break;                                                                
            }
            
            if (c == 0)
                break;
            
            if (isdigit)
                switch (state) {
                    case HOURS:     
                        timeFormat.append ('H'); 
                        success = true;
                        break;         
                        
                    case MINUTES:   timeFormat.append ('m'); break;               
                    case SECONDS:   timeFormat.append ('s'); break;   
                    case MILLIS:    timeFormat.append ('S'); break;
                    case STOP:      
                        return (false);
                }
            else
                appendToFormat (c, timeFormat);
        }

        if (hasAmOrPmMarker){
            timeFormat.append("a");
        }
        
        return (success);
    }