if (inSec >= -SECONDS_0000_TO_1970) {
// current era
long zeroSecs = inSec - SECONDS_PER_10000_YEARS + SECONDS_0000_TO_1970;
long hi = Jdk8Methods.floorDiv(zeroSecs, SECONDS_PER_10000_YEARS) + 1;
long lo = Jdk8Methods.floorMod(zeroSecs, SECONDS_PER_10000_YEARS);
LocalDateTime ldt = LocalDateTime.ofEpochSecond(lo - SECONDS_0000_TO_1970, 0, ZoneOffset.UTC);
if (hi > 0) {
buf.append('+').append(hi);
}
buf.append(ldt);
if (ldt.getSecond() == 0) {
buf.append(":00");
}
} else {
// before current era
long zeroSecs = inSec + SECONDS_0000_TO_1970;
long hi = zeroSecs / SECONDS_PER_10000_YEARS;
long lo = zeroSecs % SECONDS_PER_10000_YEARS;
LocalDateTime ldt = LocalDateTime.ofEpochSecond(lo - SECONDS_0000_TO_1970, 0, ZoneOffset.UTC);
int pos = buf.length();
buf.append(ldt);
if (ldt.getSecond() == 0) {
buf.append(":00");
}
if (hi < 0) {
if (ldt.getYear() == -10000) {
buf.replace(pos, pos + 2, Long.toString(hi - 1));
} else if (lo == 0) {
buf.insert(pos, hi);
} else {
buf.insert(pos + 1, Math.abs(hi));