in src/main/java/com/epam/parso/date/SasDateTimeFormat.java [365:407]
public Function<Double, String> getInternalFormatFunction(int width, int precision) {
return (sasSeconds) -> {
BigDecimal daySeconds = daySeconds(sasSeconds, precision);
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 = daySeconds(sasSeconds, adjustedPrecision);
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;
}
if (hh.length() > width - 3) {
return hh;
} else {
parts = parts[1].divideAndRemainder(BIG_SECONDS_IN_MINUTE);
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 = 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;
}
}
}
};
}