public Function getInternalFormatFunction()

in src/main/java/com/epam/parso/date/SasTimeFormat.java [62:92]


        public Function<Double, String> getInternalFormatFunction(int width, int precision) {
            return (sasSeconds) -> {
                boolean negative = sasSeconds < 0;
                int minIntegralWidth = negative ? "-0:00:00".length() : "0:00:00".length();

                int actualPrecision = width > minIntegralWidth ? Math.min(width - minIntegralWidth, precision) : 0;

                BigDecimal[] parts = roundSeconds(sasSeconds, width, actualPrecision, minIntegralWidth);


                String hh = String.valueOf(parts[0].longValue());
                if (negative) {
                    hh = "-" + hh;
                }
                if (hh.length() > width) {
                    return nChars('*', width);
                } else if (hh.length() > width - 3) {
                    return hh;
                } else {
                    parts = parts[1].divideAndRemainder(BIG_MINUTES_IN_HOUR);
                    String mm = String.valueOf(parts[0].longValue());
                    String hhmm = hh + (mm.length() > 1 ? ":" : ":0") + mm;
                    if (hhmm.length() > width - 3) {
                        return hhmm;
                    } else {
                        String ss = parts[1].toString();
                        return hhmm + (ss.length() > 1 && ss.charAt(1) != '.' ? ":" : ":0") + ss;
                    }
                }
            };
        }