in src/main/java/com/aliyun/dts/subscribe/clients/record/value/DateTime.java [295:419]
private String toJdbcString(int segments, boolean trimTrailingZero) {
StringBuffer datatimeBuf = new StringBuffer(32);
if (isSet(segments, SEG_YEAR)) {
int yearV = this.year > 0 ? this.year : -this.year;
String yearZeros = "0000";
String yearString = Integer.toString(yearV);
if (yearV < 1000) {
yearString = yearZeros.substring(0, (4 - yearString.length())) + yearString;
}
datatimeBuf.append(yearString);
}
if (isSet(segments, SEG_MONTH)) {
datatimeBuf.append("-");
int monthV = this.month > 0 ? this.month : -this.month;
if (monthV < 10) {
datatimeBuf.append("0").append(monthV);
} else {
datatimeBuf.append(monthV);
}
}
if (isSet(segments, SEG_DAY)) {
if (datatimeBuf.length() > 0) {
datatimeBuf.append("-");
}
int dayV = this.day > 0 ? this.day : -this.day;
if (dayV < 10) {
datatimeBuf.append("0").append(dayV);
} else {
datatimeBuf.append(dayV);
}
}
if (isSet(segments, SEG_HOUR)) {
if (datatimeBuf.length() > 0) {
datatimeBuf.append(" ");
}
int hourV = this.hour > 0 ? this.hour : -this.hour;
if (hourV < 10) {
datatimeBuf.append("0").append(hourV);
} else {
datatimeBuf.append(hourV);
}
}
if (isSet(segments, SEG_MINITE)) {
datatimeBuf.append(":");
int minuteV = this.minute > 0 ? this.minute : -this.minute;
if (minuteV < 10) {
datatimeBuf.append("0").append(minuteV);
} else {
datatimeBuf.append(minuteV);
}
}
if (isSet(segments, SEG_SECOND)) {
datatimeBuf.append(":");
int secondV = this.second > 0 ? this.second : -this.second;
if (secondV < 10) {
datatimeBuf.append("0").append(secondV);
} else {
datatimeBuf.append(secondV);
}
}
if (isSet(segments, SEG_NAONS)) {
int naonsV = this.naons > 0 ? this.naons : -this.naons;
int trailZeroCount = 0;
int remainingNumberCount = 0;
if (0 == naonsV) {
trailZeroCount = 8;
remainingNumberCount = 1;
} else {
while (0 == (naonsV % 10)) {
trailZeroCount++;
naonsV /= 10;
}
int tmp = naonsV;
while (tmp > 0) {
remainingNumberCount++;
tmp /= 10;
}
}
if (!trimTrailingZero) {
datatimeBuf.append(".");
int prefixPadZeroNumber = 9 - trailZeroCount - remainingNumberCount;
while (prefixPadZeroNumber > 0) {
datatimeBuf.append("0");
prefixPadZeroNumber--;
}
datatimeBuf.append(naonsV);
while (trailZeroCount > 0) {
datatimeBuf.append('0');
trailZeroCount--;
}
} else {
if (0 != naonsV) {
datatimeBuf.append(".");
int prefixPadZeroNumber = 9 - trailZeroCount - remainingNumberCount;
while (prefixPadZeroNumber > 0) {
datatimeBuf.append("0");
prefixPadZeroNumber--;
}
datatimeBuf.append(naonsV);
}
}
}
if (isSet(segments, SEG_TIMEZONE) && timeOffset != null) {
datatimeBuf.append(" ").append(timeOffset);
}
if (isSet(segments, SEG_COMMON_ERA) && null != commonEra) {
datatimeBuf.append(" ").append(commonEra);
}
if (isSet(segments, SEG_NEGATIVE)) {
return "-" + datatimeBuf.toString();
}
return datatimeBuf.toString();
}