in src/main/java/com/epam/parso/date/SasTimeFormat.java [272:313]
public Function<Double, String> getInternalFormatFunction(int width, int precision) {
return (sasSeconds) -> {
if (sasSeconds < 0 || sasSeconds > SECONDS_IN_DAY) {
return nChars('*', width);
}
BigDecimal daySeconds = roundSeconds(sasSeconds, precision)
.remainder(BIG_SECONDS_IN_DAY);
BigDecimal[] parts = daySeconds.divideAndRemainder(BIG_SECONDS_IN_HOUR);
int adjustedPrecision = precision;
int firstTwoDigitsNumberAfterSingleDigit = 10;
if (parts[0].longValue() >= firstTwoDigitsNumberAfterSingleDigit
&& precision > 0 && width - precision == 8) {
adjustedPrecision = precision - 1;
daySeconds = roundSeconds(sasSeconds, adjustedPrecision)
.remainder(BIG_SECONDS_IN_DAY);
parts = daySeconds.divideAndRemainder(BIG_SECONDS_IN_HOUR);
}
String hh = String.valueOf(parts[0].longValue());
if (hh.length() == 1 && !(width == 4 || width == 7
|| (adjustedPrecision > 0 && width - 8 == adjustedPrecision))) {
hh = '0' + hh;
}
parts = parts[1].divideAndRemainder(BIG_SECONDS_IN_MINUTE);
String mm = String.valueOf(parts[0].longValue());
String hhmm = hh + (mm.length() == 1 ? ":0" : ":") + mm;
String ss = String.valueOf(parts[1].longValue());
String hhmmss = hhmm + (ss.length() == 1 ? ":0" : ":") + ss;
if (adjustedPrecision == 0 || hhmmss.length() > width - adjustedPrecision) {
return hhmmss;
} else {
adjustedPrecision = Math.min(adjustedPrecision, width - hhmmss.length());
String nanos = parts[1].remainder(BigDecimal.ONE).toString()
.substring(1, adjustedPrecision + 2);
return hhmmss + nanos;
}
};
}